其他分享
首页 > 其他分享> > codeforces 1191 D-----轻松题解 --- Tokitsukaze, CSL and Stone Game #573 (Div. 2)

codeforces 1191 D-----轻松题解 --- Tokitsukaze, CSL and Stone Game #573 (Div. 2)

作者:互联网

D. Tokitsukaze, CSL and Stone Game 题目链接:http://codeforces.com/contest/1191/problem/D
 1 D. Tokitsukaze, CSL and Stone Game
 2 
 3 time limit per test1 second
 4 
 5 memory limit per test256 megabytes
 6 
 7 inputstandard input
 8 
 9 outputstandard output
10 
11 Tokitsukaze and CSL are playing a little game of stones.
12 
13 In the beginning, there are n piles of stones, the i-th pile of which has ai stones. The two players take turns making moves. Tokitsukaze moves first. On each turn the player chooses a nonempty pile and removes exactly one stone from the pile. A player loses if all of the piles are empty before his turn, or if after removing the stone, two piles (possibly empty) contain the same number of stones. Supposing that both players play optimally, who will win the game?
14 
15 Consider an example: n=3 and sizes of piles are a1=2, a2=3, a3=0. It is impossible to choose the empty pile, so Tokitsukaze has two choices: the first and the second piles. If she chooses the first pile then the state will be [1,3,0] and it is a good move. But if she chooses the second pile then the state will be [2,2,0] and she immediately loses. So the only good move for her is to choose the first pile.
16 
17 Supposing that both players always take their best moves and never make mistakes, who will win the game?
18 
19 Note that even if there are two piles with the same number of stones at the beginning, Tokitsukaze may still be able to make a valid first move. It is only necessary that there are no two piles with the same number of stones after she moves.
20 
21 Input
22 The first line contains a single integer n (1≤n≤105) — the number of piles.
23 
24 The second line contains n integers a1,a2,…,an (0≤a1,a2,…,an≤109), which mean the i-th pile has ai stones.
25 
26 Output
27 Print "sjfnb" (without quotes) if Tokitsukaze will win, or "cslnb" (without quotes) if CSL will win. Note the output characters are case-sensitive.
28 
29 Examples
30 inputCopy
31 1
32 0
33 outputCopy
34 cslnb
35 inputCopy
36 2
37 1 0
38 outputCopy
39 cslnb
40 inputCopy
41 2
42 2 2
43 outputCopy
44 sjfnb
45 inputCopy
46 3
47 2 3 1
48 outputCopy
49 sjfnb
50 Note
51 In the first example, Tokitsukaze cannot take any stone, so CSL will win.
52 
53 In the second example, Tokitsukaze can only take a stone from the first pile, and then, even though they have no stone, these two piles will have the same number of stones, which implies CSL will win.
54 
55 In the third example, Tokitsukaze will win. Here is one of the optimal ways:
56 
57 Firstly, Tokitsukaze can choose the first pile and take a stone from that pile.
58 Then, CSL can only choose the first pile, because if he chooses the second pile, he will lose immediately.
59 Finally, Tokitsukaze can choose the second pile, and then CSL will have no choice but to lose.
60 In the fourth example, they only have one good choice at any time, so Tokitsukaze can make the game lasting as long as possible and finally win.

 

题目如上,题目就是说有两个小朋友去捡石头,如果轮到谁没石头捡了,谁就输了。

但是,如果捡完石头后,石头堆里有一样数目的石头,也算输。其中包括两个石头堆里都是0的情况。

叫你判断,两个人在不失误的情况下,谁会赢。

 

那么为了方便,咱sort一下(排序函数),把石头排一下序~

举个栗子

比如4个石头堆的数量是 3 4 5 8

如果让你一个人来拿石头,且不出现失误,那么肯定是从最小的石头开始拿起(从最大的石头开始拿可能会出现两个石头堆一样数量),并且,第一个石头堆可以拿到数量为0。

再拿第二个石头堆,因为不可以的数量一样,那么必须还剩下一个石头不能拿

第三个以此类推。。。。。。。。

最后把石头堆拿成这样就合格了

 

理解了这个,就可以算这个石头堆里,有多少个石头可以拿,比如刚刚的栗子,在不失误的情况下可以拿3-0+4-1+5-2+8-3=14个石头

那么,14个石头是偶数,谁先拿谁就输,谁后拿谁就赢。(然而题目告诉我们Tokitsukaze小朋友一定先拿。。。。先拿的人真吃亏)

 

根据这些就可以开始撸代码了。。。。哈哈哈哈

好吧,其实还有几种特殊情况要注意一下。

也就是几种根本赢不了的石头阵容(先拿的人真吃亏。。。。)

比如有三个石头堆是 4 5 5,或者是5 5 5,再或者是0 0 5,这该怎么拿???怎么拿都输丫

此时Tokitsukaze小朋友是内心是崩溃的

好了,AC代码,代码萌新,有啥写不好的见谅

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<algorithm> 
 4 using namespace std;
 5 const int maxn = 1e6 + 5;
 6 long long int arr[maxn];
 7 int main()
 8 {
 9     int N;
10     long long int sum1 = 0;
11     int x1 , x2;
12     while(scanf("%d" , &N) != EOF){
13         sum1 = 0;
14         for(x1 = 1 ; x1 <= N ; x1++)
15         {
16             scanf("%I64d" , &arr[x1]);
17         }
18         sort(arr + 1, arr + N + 1);
19         int flag = 0;
20         for(x1 = 1 ; x1 < N ; x1++)
21         {
22             if(arr[x1] == arr[x1 + 1])
23             {
24                 flag++;
25                 if(arr[x1] == arr[x1 - 1] + 1 && x1 > 1)
26                 {
27                     flag++;
28                 }
29             }
30             sum1 += arr[x1] - x1 + 1;
31         }
32         sum1 += arr[x1] - x1 + 1;
33         if(flag > 1)
34         {
35             printf("cslnb\n");
36         }
37         else if(arr[1] == 0 && arr[2] == 0 )
38         {
39             printf("cslnb\n");
40         }
41         else
42         {
43             
44             if(sum1 % 2 == 0)
45             {
46                 printf("cslnb\n");
47             }
48             else
49             {
50                 printf("sjfnb\n");
51             }
52         }
53     }
54     return 0;
55 }

 

 

标签:CSL,Stone,题解,石头堆,will,Tokitsukaze,pile,first
来源: https://www.cnblogs.com/bb13-acm/p/11180897.html