zoukankan      html  css  js  c++  java
  • Couple doubi

    Couple doubi

    Couple doubi

    Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
    Total Submission(s): 238 Accepted Submission(s): 199

    Problem Description

    DouBiXp has a girlfriend named DouBiNan.One day they felt very boring and decided to play some games. The rule of this game is as following. There are k balls on the desk. Every ball has a value and the value of ith (i=1,2,...,k) ball is 1i+2i+...+(p-1)^i (mod p). Number p is a prime number that is chosen by DouBiXp and his girlfriend. And then they take balls in turn and DouBiNan first. After all the balls are token, they compare the sum of values with the other ,and the person who get larger sum will win the game. You should print “YES” if DouBiNan will win the game. Otherwise you should print “NO”.

    Input

    Multiply Test Cases.
    In the first line there are two Integers k and p(1<k,p<2^31).

    Output

    For each line, output an integer, as described above.

    Sample Input

    2 3
    20 3
    

    Sample Output

    YES
    NO
    

    分析:首先题目很好理解,有一点需要注意的就是先选的那个人并不是必须选一号球,这样轮流

    因为最后比sum的大小------简单博弈

    即,第一个人肯定选那个value大的

    做题时先列举几个,找一下规律

    20 3
    0 2 0 2 0 2 0 2 0 2 0 2 0 2 0 2 0 2 0 2
    20 5
    0 0 0 4 0 0 0 4 0 0 0 4 0 0 0 4 0 0 0 4

    仅仅有在p-1的倍数时有非0元素存在。

    所以只要分析非零的时候

    20 3 --------10 ---平局

    20 5 --------5 ---先手胜

    所以k/(p-1) 为奇数时先手胜,否则为平局

    #include<iostream>
    #include<algorithm>
    using namespace std;
    int main()
    {
    	int k,p;
    	while(cin>>k>>p)
    	{
    		if(k/(p-1)%2)
    		{
    			cout<<"YES"<<endl;
    		}
    		else
    		cout<<"NO"<<endl;
    	}
    	return 0;
    }
    
  • 相关阅读:
    USACO 玛丽卡(最短路+枚举)
    POJ 1161 Walls(最短路+枚举)
    Windows 上配置Docker Desktop 的k8s
    菜鸡学算法--70. 爬楼梯
    CLR 异步函数
    【.NET Core开发实战学习笔记】依赖注入框架:管理服务的依赖与生命周期
    【.NET Core 开发实战学习笔记】StartUp:理解程序的启动过程
    .ef core 多对对关系的关联方法
    HttpGet请求传递数组(集合)
    使用wkhtmltopdf工具生成pdf
  • 原文地址:https://www.cnblogs.com/serendipity-my/p/12601132.html
Copyright © 2011-2022 走看看