用表情包的方式打開codeforces 1191 D --- Tokitsukaze, CSL and Stone Game #573 (Div. 2)


D. Tokitsukaze, CSL and Stone Game
 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 }

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM