zoukankan      html  css  js  c++  java
  • 【JZOJ4637】大鱼海棠【博弈论】

    题目大意:

    题目链接:https://jzoj.net/senior/#main/show/4637
    给出一棵树,双方轮流选择节点,使得这个点到根节点不能再选。不能选择的人获胜。问先手能否赢得游戏。


    思路:

    这是一道很显然的chompchomp游戏啊。
    chompchomp游戏就是指一个n×mn imes m的矩形,双方轮流选择点(x,y)(x,y),使得(1,1,x,y)(1,1,x,y)这个矩形中的所有点都不可以再次选择。谁选择点(n,m)(n,m)谁就输。
    如果这道题先手必败,那么无论先手走任意点(x,y)(x,y)后手都是有必胜策略的。
    但是如果先手第一次选择点(1,1)(1,1),那么后手就必须选择一个点(x1,y1)(x_1,y_1),但是对于任意一个点(x,y)(x,y),选择后对方都是有方法必胜的。所以此时先手就处于必胜状态。与假设矛盾。
    所以在除了n=m=1n=m=1的情况下,先手是必胜的。


    这道题同理,先手第一次选择根节点,那么就相当于把第一手让给了后手。所以如果这棵树的节点数量大于1,先手就是必胜的。


    代码:

    #include <cstdio>
    #include <string>
    using namespace std;
    
    int T,n,x;
    
    int read()
    {
    	int d=0;
    	char ch=getchar();
    	while (!isdigit(ch)) ch=getchar();
    	while (isdigit(ch))
    		d=(d<<3)+(d<<1)+ch-48,ch=getchar();
    	return d;
    } 
    
    int main()
    {
    	T=read();
    	while (T--)
    	{
    		n=read();
    		for (register int i=1;i<n;i++) x=read();  //树的形状不影响结果
    		if (n==1) printf("NO
    ");
    			else printf("YES
    ");
    	}
    	return 0;
    }
    
  • 相关阅读:
    Leetcode Binary Tree Paths
    Leetcode Lowest Common Ancestor of a Binary Tree
    Leetcode Lowest Common Ancestor of a Binary Search Tree
    Leetcode Path Sum
    Leetcode Symmetric Tree
    Leetcode Invert Binary Tree
    Leetcode Same Tree
    Leetcode Maximum Depth of Binary Tree
    Python Json&Pickle&模块
    Python Shelve模块
  • 原文地址:https://www.cnblogs.com/hello-tomorrow/p/11998208.html
Copyright © 2011-2022 走看看