日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

TOJ 4393 Game

發布時間:2024/4/14 编程问答 40 豆豆
生活随笔 收集整理的這篇文章主要介紹了 TOJ 4393 Game 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

描述

Bob always plays game with Alice.Today,they are playing a game on a tree.Alice has m1 stones,Bob has m2 stones.At the beginning of the game,all the stones are placed on the nodes of a tree,except the root.Alice moves first and they turns moving the stones.On each turn,the player chooses exactly one of his stone,moves this stone from current node to his parent node.During the game,any number of stone can be put on the same node.
the player who first moves all of his stones to the root of the tree is the loser.Assurme that Bob and Alice are both clever enough.Given the initial position of the stones,write a program to find the winner.

輸入

Input contains multiple test case.
The first line of each test case cotains three integers n(1<n<=10),m1(1<=m1<=3) and m2(1<=m2<=3) ,n is the number of node.
Next n-1 line describe the tree.Each line contains two integers A and B in range [0,n) representing an edge of the tree and A is B's parent.Node 0 is root.
There are m1 integers and m2 integers on the next two lines,representing the initial position of Alice's and Bob's stones.

輸出

Output the winner of the game.

樣例輸入

3 1 1 0 1 0 2 1 2 3 2 1 0 1 1 2 2 2 2

樣例輸出

Bob Alice

?

看了半天沒看懂題目是什么意思,后來看了一個人的一篇博客才明白是大概是什么的意思。

應該是先把所有的stones移到根節點的人算輸,這樣子的話只要是把所有的stones所在層數相加和最小的人就輸了。

?

#include <stdio.h> #include <string.h> #include <iostream> #include <queue> #define MAXN 20 using namespace std;int n,m1,m2,cnt; int dist[MAXN]; int visited[MAXN]; int head[MAXN];struct Edge{int to,next; }edge[MAXN*2];void addedge(int u, int v){edge[cnt].to=v;edge[cnt].next=head[u];head[u]=cnt++; }void bfs(){queue<int> Q;Q.push(0);dist[0]=0;while(!Q.empty()){int t=Q.front();Q.pop();for(int i=head[t]; i!=-1; i=edge[i].next){int c=edge[i].to;if(!visited[c]){visited[c]=1;dist[c]=dist[t]+1;Q.push(c);}} } } int main(int argc, char *argv[]) {int u,v,p1,p2;while(scanf("%d %d %d",&n,&m1,&m2)!=EOF){cnt=0;memset(head,-1,sizeof(head));memset(visited,0,sizeof(visited));memset(dist,0,sizeof(dist));for(int i=1; i<n; i++){scanf("%d %d",&u,&v); addedge(u,v);addedge(v,u);}int sum1=0,sum2=0;dist[0]=0;bfs();for(int i=0; i<m1;i++){scanf("%d",&p1);sum1+=dist[p1];}for(int i=0; i<m2; i++){scanf("%d",&p2);sum2+=dist[p2];}if(sum1>sum2){puts("Alice");}else{puts("Bob");}}return 0; }

?

轉載于:https://www.cnblogs.com/chenjianxiang/p/3540892.html

總結

以上是生活随笔為你收集整理的TOJ 4393 Game的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。