zoukankan      html  css  js  c++  java
  • 邂逅明下 HDU

    Problem description:

      有三个数字n,p,q,表示一堆硬币一共有n枚,从这个硬币堆里取硬币,一次最少取p枚,最多q枚,如果剩下少于p枚就要一次取完。两人轮流取,直到堆里的硬币取完,最后一次取硬币的算输。对于每一行的三个数字,给出先取的人是否有必胜策略,如果有回答WIN,否则回答LOST。

    Input
    不超过100000行,每行三个正整数n,p,q。Output对应每行输入,按前面介绍的游戏规则,判断先取者是否有必胜策略。输出WIN或者LOST。
    Sample Input
    7 2 4
    6 2 4
    Sample Output
    LOST
    WIN

    思路:总是读题不准,原来是最后一个取的人会输,而且这个不能用动态规划做,会超时。
     这个其实是巴什博奕。
    #include<iostream>
    using namespace std;
    int main(){
        int n,p,q;
        while(cin>>n>>p>>q){
            int s=n%(p+q);
            if(s==0)
                cout<<"WIN"<<endl;
            else if(s<=p)
                cout<<"LOST"<<endl;
            else
                cout<<"WIN"<<endl;
        }
    }
  • 相关阅读:
    HDU 1060 Leftmost Digit
    HDU 1008 Elevator
    HDU 1042 N!
    HDU 1040 As Easy As A+B
    HDU 1007 Quoit Design
    欧拉函数
    HDU 4983 Goffi and GCD
    HDU 2588 GCD
    HDU 3501 Calculation 2
    HDU 4981 Goffi and Median
  • 原文地址:https://www.cnblogs.com/astonc/p/9981450.html
Copyright © 2011-2022 走看看