D. Tokitsukaze, CSL and Stone Game

time limit per test1 second

memory limit per test256 megabytes

inputstandard input

outputstandard output

Tokitsukaze and CSL are playing a little game of stones.

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?

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.

Supposing that both players always take their best moves and never make mistakes, who will win the game?

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.

Input

The first line contains a single integer n (1≤n≤105) — the number of piles.

The second line contains n integers a1,a2,…,an (0≤a1,a2,…,an≤109), which mean the i-th pile has ai stones.

Output

Print "sjfnb" (without quotes) if Tokitsukaze will win, or "cslnb" (without quotes) if CSL will win. Note the output characters are case-sensitive.

Examples

inputCopy

1

0

outputCopy

cslnb

inputCopy

2

1 0

outputCopy

cslnb

inputCopy

2

2 2

outputCopy

sjfnb

inputCopy

3

2 3 1

outputCopy

sjfnb

Note

In the first example, Tokitsukaze cannot take any stone, so CSL will win.

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.

In the third example, Tokitsukaze will win. Here is one of the optimal ways:

Firstly, Tokitsukaze can choose the first pile and take a stone from that pile.

Then, CSL can only choose the first pile, because if he chooses the second pile, he will lose immediately.

Finally, Tokitsukaze can choose the second pile, and then CSL will have no choice but to lose.

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.

题意:

给n堆石子,每一堆有a[i] 个 石头,现在二人玩游戏,每一人每一次选择一个非空的石头堆,从中拿出一个石头。如果当一个人操作之后,这n堆石头中有两堆中的石头数量是相同的,那么这个人就输掉。假设二人决定聪明,请判断是先手赢还是后手赢。

思路:

先根据初始情况判断先手是否必输:

通过思考我们可以知道初始情况是以下情况先手必输

1、 空堆的数量 >=2

2、有三个堆中石头数量相等。

3、 有这种情况, x x y y 即 有相同数量堆的情况>=2

4、 有这种情况, x x x-1

如果先手不必输,那么二人的最优操作之后,石子堆一定会到达这个状态 (无顺序) 0,1,2,3,,,n-1

我们只需要求a[i] 的sum和然后减去 等差数列的前列项和后判断奇偶即可。

细节见代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <vector>
#include <iomanip>
#define ALL(x) (x).begin(), (x).end()
#define rt return
#define dll(x) scanf("%I64d",&x)
#define xll(x) printf("%I64d\n",x)
#define sz(a) int(a.size())
#define all(a) a.begin(), a.end()
#define rep(i,x,n) for(int i=x;i<n;i++)
#define repd(i,x,n) for(int i=x;i<=n;i++)
#define pii pair<int,int>
#define pll pair<long long ,long long>
#define gbtb ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define MS0(X) memset((X), 0, sizeof((X)))
#define MSC0(X) memset((X), '\0', sizeof((X)))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define eps 1e-6
#define gg(x) getInt(&x)
#define chu(x) cout<<"["<<#x<<" "<<(x)<<"]"<<endl
using namespace std;
typedef long long ll;
ll gcd(ll a, ll b) {return b ? gcd(b, a % b) : a;}
ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}
ll powmod(ll a, ll b, ll MOD) {ll ans = 1; while (b) {if (b % 2)ans = ans * a % MOD; a = a * a % MOD; b /= 2;} return ans;}
inline void getInt(int* p);
const int maxn = 1000010;
const int inf = 0x3f3f3f3f;
/*** TEMPLATE CODE * * STARTS HERE ***/ int num[maxn], a[maxn]; map<int, int> m1; int main()
{
int n;
scanf("%d", &n);
int flag3 = 0;
int flag2 = 0;
int x;
int id;
for (int i = 1; i <= n; i++)
{
scanf("%d", &num[i]);
a[i] = num[i];
m1[a[i]]++;
if (!flag3 && m1[a[i]] >= 3)
{
flag3 = 1;
} else if (m1[a[i]] >= 2)
{
id = i;
x = a[i];
flag2++;
}
}
int flag1 = 0;
if (n == 1)
{
if (a[1] & 1)
{
cout << "sjfnb" << endl;
} else
{
cout << "cslnb" << endl;
}
return 0;
}
if (flag3)
{
cout << "cslnb" << endl;
return 0;
} else if (flag2)
{
if (flag2 > 1)
{
cout << "cslnb" << endl;
return 0;
} else
{
if (m1[x - 1] || x == 0)
{
cout << "cslnb" << endl;
return 0;
}
}
}
ll ans = 0ll;
repd(i, 1, n)
{
ans += a[i];
}
if (flag1)
{
ans++;
}
ans -= 1ll * n * (n - 1ll) / 2;// 注意爆ll
if (ans & 1)
cout << "sjfnb" << endl;
else
cout << "cslnb" << endl; return 0;
}

Codeforces Round #573 (Div. 2) D. Tokitsukaze, CSL and Stone Game (博弈,思维)的更多相关文章

  1. Codeforces Round #573 (Div. 2) E. Tokitsukaze and Duel (博弈)

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  2. Codeforces Round #573 (Div. 1) 差F

    Codeforces Round #573 (Div. 1) E 题意:二维平面上有 n 个点,你可以放至多 m 条直线使得 (0,0) 与每个点的连线至少与一条直线相交.求原点与所有直线的距离最小值 ...

  3. Codeforces Round #573 (Div. 2)

    A:Tokitsukaze and Enhancement 当时看错条件了..以为A>C>B>D.就胡写了判断条件. #include<bits/stdc++.h> us ...

  4. Codeforces Round #573 (Div. 1)

    Preface 军训终于结束了回来补一补之前的坑发现很多题目题意都忘记了 这场感觉难度适中,F由于智力不够所以弃了,E的话石乐志看了官方英文题解才发现自己已经胡了一大半就差实现了233 水平下降严重. ...

  5. Codeforces Round #573 (Div. 2) D题题解

    一.题目 ​ Tokitsukaze, CSL and Stone Game ​ Tokitsukaze和CSL正在玩一些石头游戏. ​ 一开始,有n堆的石头,第i堆石头数记为 \(a_i\),两人轮 ...

  6. Codeforces Round #539 (Div. 2) - D. Sasha and One More Name(思维)

    Problem   Codeforces Round #539 (Div. 2) - D. Sasha and One More Name Time Limit: 1000 mSec Problem ...

  7. Codeforces Round #573 (Div. 2) Tokitsukaze and Mahjong 水题

    B. Tokitsukaze and Mahjong time limit per test1 second memory limit per test256 megabytes Tokitsukaz ...

  8. Codeforces Round 573 (Div.1) 题解

    这场怎么说呢……有喜有悲吧. 开场先秒了 A.看到 B,感觉有点意思,WA 了 2 发后也过了. 此时还在 rk 前 200. 开 C,一看就不可做.跟榜,切 D 人数是 C 的两倍. 开 D.一眼感 ...

  9. Codeforces Round #523 (Div. 2) F. Katya and Segments Sets (交互题+思维)

    https://codeforces.com/contest/1061/problem/F 题意 假设存在一颗完全k叉树(n<=1e5),允许你进行最多(n*60)次询问,然后输出这棵树的根,每 ...

随机推荐

  1. Dubbo负载均衡:最少活跃数(LeastActive)

    官方文档定义 最少活跃调用数,相同活跃数的随机,活跃数指调用前后计数差. 使慢的提供者收到更少请求,因为越慢的提供者的调用前后计数差会越大. 关于活跃数 最少活跃数负载均衡,最关键的点在于活跃数.活跃 ...

  2. 基于RANSAC的点云面分割算法

    该算法在RANSAC和空间检索树的基础上实现的. 算法思路: 1.点云抽希.法线估计 2.出局点索引存储声明 3.平面检测 for (size_t i = 0; i < cloudTemp-&g ...

  3. Windows2008 r2“Web服务器HTTP头信息泄露”漏洞修复

    一.漏洞名称 漏洞名称 漏洞摘要 修复建议 Web服务器HTTP头信息泄露 远程Web服务器通过HTTP头公开信息. 修改Web服务器的HTTP头以不公开有关底层Web服务器的详细信息. 说明:在ii ...

  4. 什么是HOOK功能?

    HOOK API是一个永恒的话题,如果没有HOOK,许多技术将很难实现,也许根本不能实现.这里所说的API,是广义上的API,它包括DOS下的中断,WINDOWS里的API.中断服务.IFS和NDIS ...

  5. CSS-W3School:CSS table-layout 属性

    ylbtech-CSS-W3School:CSS table-layout 属性 1.返回顶部 1. CSS table-layout 属性 CSS 参考手册 实例 设置表格布局算法: table { ...

  6. leetcode 374. 猜数字大小(python)

    我们正在玩一个猜数字游戏. 游戏规则如下:我从 1 到 n 选择一个数字. 你需要猜我选择了哪个数字.每次你猜错了,我会告诉你这个数字是大了还是小了.你调用一个预先定义好的接口 guess(int n ...

  7. oauth2.0协议原理

    OAuth的授权不会使用第三方触及到用户的帐号信息(如用户密码),即第三方无需使用用户的用户名与密码就可以申请获得该用户资源的授权,因此OAuth是安全的. OAuth的作用:就是让“客户端”安全可控 ...

  8. list,string,tuple,dictionary之间的转换

    list,string,tuple,dictionary之间的转换 类型 String List tuple dictionary String - list(str), str.split() tu ...

  9. RESR API (二)之Responses

    Responses 与基本的HttpResponse对象不同,TemplateResponse对象保留 the details of the context that was provided by ...

  10. Scratch少儿编程系列:(八)演奏简单音乐

    一.程序说明 本程序,用来演奏简单音乐. 二.制作过程 1. 场景和角色的选择 场景选择“音乐和舞蹈”主题下的“party root”,角色沿用默认角色,如下图: 选择后效果如下图: 2. 切换到“脚 ...