本文共 1440 字,大约阅读时间需要 4 分钟。
题意: 给你一颗有n个节点的无根树(我的理解就是一个无向连通图),现在每次可以删除一个以叶子节点为端点的所有边并删除这个节点,现在指定一个节点x,谁先删到这个节点,谁就获胜(Ayush 先手 Ashish后手)。思路:
1.首先我们先判断当现在指定删除的节点就已经是叶子节点的话,那么先手直接赢。2.如果先手不能第一次就拿到指定的节点,那么每个人肯定都不会让指定节点的度等于1(换句话来说,当拿到指定节点的度已经为2的时候,为了赢,没有人会去再拿连接这个节点的边,除非迫不得已只剩连接他的边了)。那么条件出来了,其实就像一个拿数的博弈论了,谁先拿到只剩俩个数(俩个节点)谁就赢了。
那么如果原先n为偶数,那么先手一定是拿图中还有偶数的时候,后手一定是拿图中还有奇数个节点的时候,那么这个时候先手一定赢,反之后手赢AC代码
#includeinline int read(){ char c = getchar();int x = 0,s = 1;while(c < '0' || c > '9') { if(c == '-') s = -1;c = getchar();}while(c >= '0' && c <= '9') { x = x*10 + c -'0';c = getchar();}return x*s;}using namespace std;#define NewNode (TreeNode *)malloc(sizeof(TreeNode))#define Mem(a,b) memset(a,b,sizeof(a))const int N = 1e5 + 5;const long long INFINF = 0x7f7f7f7f7f7f7f;const int INF = 0x3f3f3f3f;const double EPS = 1e-7;const unsigned long long mod = 998244353;const double II = acos(-1);const double PP = (II*1.0)/(180.00);typedef long long ll;typedef unsigned long long ull;typedef pair pii;typedef pair piil;int main(){ std::ios::sync_with_stdio(false); cin.tie(0),cout.tie(0); int t; cin >> t; while(t--) { int n,x,a,b; cin >> n >> x; int ru[1050] = { 0}; for(int i = 0;i < n-1;i++) { cin >> a >> b;ru[a]++,ru[b]++;} if(ru[x] <= 1) cout << "Ayush" << endl; else if(n % 2 == 0) cout << "Ayush" << endl; else cout << "Ashish" << endl; }}
转载地址:http://ynirz.baihongyu.com/