标签:clock write cas nes this || another ken alter
InputThe first line is a number T(1<=T<=100), represents the number of case. The next T blocks follow each indicates a case.
Each case contains two integers N(3<=N<=10 9,1<=K<=10).OutputFor each case, output the number of case and the winner "first" or "second".(as shown in the sample output)Sample Input
2
3 1
3 2
Sample Output
Case 1: first
Case 2: second
题意:给你n个硬币排成一圈,编号1-n,只能翻转连续的1~k个的硬币。翻最后一枚硬币者赢。
题解:如果k=1,那么n为奇数,先手必胜,n为偶数,后手必胜。
如果k!=1{
如果k >= n 即先手可以一次性取完,先手必胜;
如果k<n,那么后手必胜 因为先手取完第一次后,后手可以在取完剩下的或者将剩下的截成相同的两段,之后先手怎么取,后手怎么取,所以必胜。
}
1 #include <iostream>
2 #include <cstdio>
3 #include <cstring>
4 using namespace std;
5 int casen;
6 int cas;
7 int main()
8 {
9 int n,k;
10 scanf("%d",&casen);
11 while(casen--)
12 {
13
14 scanf("%d%d",&n,&k);
15 printf("Case %d: ",++cas);
16 if(n<=k)
17 printf("first\n");
18 else if(k==1)
19 {
20 if(n%2)
21 printf("first\n");
22 else
23 printf("second\n");
24 }
25 else
26 {
27 printf("second\n");
28 }
29 }
30 return 0;
31 }
同理:
Input
Output
Sample Input
1
2
3
0
Sample Output
Alice
Alice
Bob
题目的意思就是两个人轮流拿硬币,Alice先拿,Alice拿的时候可以选择拿走一个或者拿走相邻的两个,谁拿完最后的石子胜利。
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int main()
{
int n;
while(~scanf("%d",&n)&&n)
{
if(n==1||n==2)
{
puts("Alice");
continue;
}
else
{
puts("Bob");
}
}
}
标签:clock write cas nes this || another ken alter
原文地址:https://www.cnblogs.com/1013star/p/9719625.html