zoukankan      html  css  js  c++  java
  • [Roy&October之取石子]

    P4018 4860

    [Roy&October之取石子]

    题目大意:在题目条件下,有没有先手必胜的策略

    做法:从小到大找到第一个先手第一次取不完石子且为合数的数(h),如果(n)(h)的倍数,则先手必败,则先手必胜。

    证明:

    1:考虑若(n<h)则先手可以一次取完

    2:若(n=h),则先手一次取不完,则后手必胜

    3:若(n>h)且同时(n=k×h),那么先手取多少个,后手就可以给他凑够(h)的某个倍数,则最后面临的就是(2)中的情况,先手必败

    4:若(n>h)且同时(n≠k×h),那么先手可以考虑取某个数,使得剩下的数是(h)的倍数,则面临(3)中的情况。

    所以结论得证。

    Roy&October之取石子1

    #include <cstdio>
    #include <iostream>
    using namespace std;
    int n;
    int main()
    {
    	scanf("%d",&n);
    	for(int i=1;i<=n;i++)
    	{
    		int x;
    		scanf("%d",&x);
    		if(x % 6 == 0)//因为$p^{k}$,$k$为自然数,所以第一个先手不能一次取完的合数为6
    			printf("Roy wins!
    ");
    		else
    			printf("October wins!
    ");
    	}
    	return 0;
    }
    

    Roy&October之取石子2

    #include <cstdio>
    #include <iostream>
    using namespace std;
    int n;
    int main()
    {
    	scanf("%d",&n);
    	for(int i=1;i<=n;i++)
    	{
    		int x;
    		scanf("%d",&x);
    		if(x % 4 == 0)//因为$p^{k}$,$k$只能为$0/1$,所以第一个先手不能一次取完的合数为4
    			printf("Roy wins!
    ");
    		else
    			printf("October wins!
    ");
    	}
    	return 0;
    }
    
  • 相关阅读:
    更多的bash shell命令
    Docker(一)Docker概述
    SpringCloud(一)版本选择
    Scala 技术笔记之 可变长参数
    嵌入式 ThriftServer in Spark
    Spark 代码走读之 Cache
    Scala 技术笔记之 Option Some None
    Spark作业执行
    Shuffle
    Jetty初探
  • 原文地址:https://www.cnblogs.com/-Wind-/p/11851628.html
Copyright © 2011-2022 走看看