zoukankan      html  css  js  c++  java
  • Whu 1604——Play Apple——————【博弈】

    Problem 1604 - Play Apple
    Time Limit: 1000MS   Memory Limit: 65536KB   
    Total Submit: 442  Accepted: 177  Special Judge: No
    Description

    There are N apples. Two people take turns to either: 
    1. Divide the apple into two piles with different numbers.
    2. The other people selects a pile of apples as the beginning of the next turn.
    If someone can not meet the requirements, he is lost. Will the first one win the game if both use the best strategy?

    Input
    There are multiple test cases.
    The first line of each case contains a integer N. ( 1 <= N <= 1000000000 )
    Output
    If the first person will win, output “Yes”. Otherwise, output “No”.
    Sample Input
    2
    3
    4
    Sample Output
    No
    Yes
    No
     
    题目大意:两个人分苹果。两种操作:(1)第一个人把苹果分成不相等的两堆 (2)第二个人挑一堆留下,下轮继续玩。 当某个人不能操作的时候,他就输了。 问你如果两个人都采用最优策略,第一个人是否会赢。
     
    #include<stdio.h>
    #include<algorithm>
    #include<string.h>
    using namespace std;
    typedef long long LL;
    int main(){
        int n;
        while(scanf("%d",&n)!=EOF){
            if(n == 1 || n == 2){
                puts("No");
            }else if(n == 3){
                puts("Yes");
            }else{
                if((n-3) % 3 == 1){
                    puts("No");
                }else{
                    puts("Yes");
                }
            }
        }
        return 0;
    }
    

      

     
  • 相关阅读:
    2019前端面试系列——CSS面试题
    面试题——数组转树结构
    前端安全
    webpack入门——构建简易版vue-cli
    [] == ![],走进==隐式转换的世界
    Vue图片懒加载插件
    JS常用时间处理方法
    Vue中实现token验证
    VSCode基本配置
    打乱数组——shuffle
  • 原文地址:https://www.cnblogs.com/chengsheng/p/5380289.html
Copyright © 2011-2022 走看看