ac number theory game theory Bash game

Scenario 1: Whoever takes the light at the end wins

Anyone who has played one of the types of Bash games knows that n stones are given to you, and two people take turns to take it. It is stipulated that each person will take at least one at a time and at most m. win, and assume that both parties use the optimal strategy.

Analysis, if the last one left to the opponent is m+1, then the opponent will take at most m, and at least 1, then the last player must be himself, then if the opponent faces (m+1) before each take The multiple of , that is, no matter how much the opponent takes next, he can always make up so that the number of stones taken by two people only sums up to (m+1). Finally, the opponent will face the situation of m+1 stones, that is, he will definitely take the last stone. over

That is, if you are the first mover, then if n%(m+1)==0, that is, you are faced with a multiple of (m+1), and you will lose if both parties adopt the best strategy.

If n%(m+1)! =0, then you will take n%(m+1) of them, so that the opponent faces a multiple of (m+1), that is, the opponent will definitely lose in the end

Scenario 2: The one who takes the light at the end loses

If there is only one stone left when your opponent takes at the end, because at least one is taken, then your opponent must have taken all, then the opponent must lose, that is, whoever takes n-1 stones first will win, then Reference Scenario 1 If you move first, and (n-1)%(m+1)==0, then you will definitely lose, otherwise your opponent will definitely lose

Special case:

if m>=n

That is to say, it can be taken at one time. In case one, the first mover must win. If n=1 at this time, then in case two, the first mover must lose, otherwise the second mover must lose.

portal

Stone

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


Problem Description
Tang and Jiang are good friends. To decide whose treat it is for dinner, they are playing a game. Specifically, Tang and Jiang will alternatively write numbers (integers) on a white board. Tang writes first, then Jiang, then again Tang, etc... Moreover, assuming that the number written in the previous round is X, the next person who plays should write a number Y such that 1 <= Y - X <= k. The person who writes a number no smaller than N first will lose the game. Note that in the first round, Tang can write a number only within range [1, k] (both inclusive). You can assume that Tang and Jiang will always be playing optimally, as they are both very smart students.
 

Input
There are multiple test cases. For each test case, there will be one line of input having two integers N (0 < N <= 10^8) and k (0 < k <= 100). Input terminates when both N and k are zero.
 

Output
For each case, print the winner's name in a single line.
 

Sample Input
 
  
1 130 310 20 0
 

Sample Output
 
  
JiangTangJiang
 

#include<iostream>
using namespace std;
intmain()
{
    int n,m;
    while(cin>>n>>m&&n>0)

    {
        if((n-1)%(m+1)!=0)
            cout<<"Tang"<<endl;
        else
            cout<<"Jiang"<<endl;
    }
}

Public Sale

Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 10000    Accepted Submission(s): 5957


Problem Description
Although he didn't want to, but reality is always reality, Lele never escaped the fate of dropping out because he didn't get a scholarship. What awaits him now is a farm career like FarmJohn.

To farm, you need to have a field. Lele heard that a special auction is being held on the street. The auction item happens to be a 20-acre field. So, Lele took all his savings and rushed to the auction.

It was later discovered that the entire auction consisted of Lele and his nemesis Yueyue.

Through inquiries, Lele knows that the rules of this auction are as follows: at the beginning, the reserve price is 0, and two people take turns to increase the price, but the range of each increase should be between 1 and N. When the price is greater than or equal to the cost price M of the field , the organizer sold the field to the bidder.

Although Lele and Yueyue failed the exams, they were very proficient at auctions, and both of them wanted the land very much. So they choose the most favorable way to increase the price every time.

Since Lele's lexicographical order is higher than Yueyue's, Lele starts to increase the price every time. Excuse me, when the price is increased for the first time,
how much does Lele have to pay to ensure that he can buy this land?
 

Input
This question contains multiple sets of tests, please process until the end of file (EOF). One line for each set of tests.
Each set of tests contains two integers M and N (see the title description for the meaning, 0<N, M<1100)
 

Output
For each set of data, output the price that Lele can add for the first time in increasing order in a row. Separate the two data with a space.
If Lele can't buy the land on the first bid no matter what, output "none".
 

Sample Input
 
  
4 23 23 5
 

Sample Output
 
  
1none3 4 5

#include<iostream>
using namespace std;
int r[10000];
int ri=0;
int main()
{
    int n,m;
    while(cin>>n>>m)
    {
        ri=0;
        if(n%(m+1)!=0)
        {
            for(int i=1;i<=m;i++)
            {
                if((n-i)%(m+1)==0||n-i<=0)
                    r[ri++]=i;
            }
            for(int i=0;i<ri-1;i++)
                cout<<r[i]<<" ";
            cout<<r[ri-1];
            cout<<endl;
        }
        else
            cout<<"none"<<endl;
    }
}

Good Luck in CET-4 Everybody!

Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 12163    Accepted Submission(s): 7882


Problem Description
大学英语四级考试就要来临了,你是不是在紧张的复习?也许紧张得连短学期的ACM都没工夫练习了,反正我知道的Kiki和Cici都是如此。当然,作为在考场浸润了十几载的当代大学生,Kiki和Cici更懂得考前的放松,所谓“张弛有道”就是这个意思。这不,Kiki和Cici在每天晚上休息之前都要玩一会儿扑克牌以放松神经。
“升级”?“双扣”?“红五”?还是“斗地主”?
当然都不是!那多俗啊~
作为计算机学院的学生,Kiki和Cici打牌的时候可没忘记专业,她们打牌的规则是这样的:
1、  总共n张牌;
2、  双方轮流抓牌;
3、  每人每次抓牌的个数只能是2的幂次(即:1,2,4,8,16…)
4、  抓完牌,胜负结果也出来了:最后抓完牌的人为胜者;
假设Kiki和Cici都是足够聪明(其实不用假设,哪有不聪明的学生~),并且每次都是Kiki先抓牌,请问谁能赢呢?
当然,打牌无论谁赢都问题不大,重要的是马上到来的CET-4能有好的状态。

Good luck in CET-4 everybody!
 

Input
输入数据包含多个测试用例,每个测试用例占一行,包含一个整数n(1<=n<=1000)。
 

Output
如果Kiki能赢的话,请输出“Kiki”,否则请输出“Cici”,每个实例的输出占一行。
 

Sample Input
 
  
13
 

Sample Output
 
  
KikiCici

#include<iostream>
using namespace std;
int main()
{
    int n;
    while(cin>>n)
    {
        if(n%3==0)
            cout<<"Cici"<<endl;
        else
            cout<<"Kiki"<<endl;
    }
}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326483748&siteId=291194637