Codeforces Round #573 (Div. 2)(ABCD)

Tokitsukaze and Enhancement CodeForces - 1191A
Tokitsukaze is one of the characters in the game “Kantai Collection”. In this game, every character has a common attribute — health points, shortened to HP.

In general, different values of HP are grouped into 4 categories:

Category A if HP is in the form of (4n+1), that is, when divided by 4, the remainder is 1;
Category B if HP is in the form of (4n+3), that is, when divided by 4, the remainder is 3;
Category C if HP is in the form of (4n+2), that is, when divided by 4, the remainder is 2;
Category D if HP is in the form of 4n, that is, when divided by 4, the remainder is 0.
The above-mentioned n can be any integer.

These 4 categories ordered from highest to lowest as A>B>C>D, which means category A is the highest and category D is the lowest.

While playing the game, players can increase the HP of the character. Now, Tokitsukaze wants you to increase her HP by at most 2 (that is, either by 0, 1 or 2). How much should she increase her HP so that it has the highest possible category?

Input
The only line contains a single integer x (30≤x≤100) — the value Tokitsukaze’s HP currently.

Output
Print an integer a (0≤a≤2) and an uppercase letter b (b∈{A,B,C,D}), representing that the best way is to increase her HP by a, and then the category becomes b.

Note that the output characters are case-sensitive.

Examples
Input
33
Output
0 A
Input
98
Output
1 B
Note
For the first example, the category of Tokitsukaze’s HP is already A, so you don’t need to enhance her ability.

For the second example:

If you don’t increase her HP, its value is still 98, which equals to (4×24+2), and its category is C.
If you increase her HP by 1, its value becomes 99, which equals to (4×24+3), and its category becomes B.
If you increase her HP by 2, its value becomes 100, which equals to (4×25), and its category becomes D.
Therefore, the best way is to increase her HP by 1 so that the category of her HP becomes B.
水题,尽量往等级高的地方弄就行了。
代码如下:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#define ll long long
using namespace std;

int n;

int main()
{
	while(cin>>n)
	{
		if(n%4==1) cout<<"0 A"<<endl;
		if(n%4==2) cout<<"1 B"<<endl;
		if(n%4==3) cout<<"2 A"<<endl;
		if(n%4==0) cout<<"1 A"<<endl;
	}
}

Tokitsukaze and Mahjong CodeForces - 1191B
Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, …, 9m, 1p, 2p, …, 9p, 1s, 2s, …, 9s.

In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand.

Do you know the minimum number of extra suited tiles she needs to draw so that she can win?

Here are some useful definitions in this game:

A mentsu, also known as meld, is formed by a koutsu or a shuntsu;
A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu;
A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu.
Some examples:

[2m, 3p, 2s, 4m, 1s, 2s, 4s] — it contains no koutsu or shuntsu, so it includes no mentsu;
[4s, 3m, 3p, 4s, 5p, 4s, 5p] — it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu;
[5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] — it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu.
Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite.

Input
The only line contains three strings — the tiles in Tokitsukaze’s hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s.

Output
Print a single integer — the minimum number of extra suited tiles she needs to draw.

Examples
Input
1s 2s 3s
Output
0
Input
9m 9m 9m
Output
0
Input
3p 9m 2p
Output
1
Note
In the first example, Tokitsukaze already has a shuntsu.

In the second example, Tokitsukaze already has a koutsu.

In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile — 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p].
跟打麻将差不多吧。要把最后结果弄成同花顺,三个数相同,问应该操作多少步。
代码如下:

#include<bits/stdc++.h>
using namespace std;

const int maxx=1e2+10;
string s;
int a[maxx],b[maxx],c[maxx];

int main()
{
	memset(a,0,sizeof(a));
	memset(b,0,sizeof(b));
	memset(c,0,sizeof(c));
	for(int i=0;i<3;i++)
	{
		cin>>s;
		if(s[1]=='s') a[s[0]-'0']++;
		if(s[1]=='m') b[s[0]-'0']++;
		if(s[1]=='p') c[s[0]-'0']++;
	}
	int flag1=0;
	int flag2=0;
	for(int i=1;i<10;i++)
	{
		if(a[i]==3||b[i]==3||c[i]==3) flag1=1;
		if(a[i]==2||b[i]==2||c[i]==2) flag2=1;
	}
	for(int i=1;i<10;i++)
	{
		if(a[i]&&a[i+1]&&a[i+2]) flag1=1;
		if(b[i]&&b[i+1]&&b[i+2]) flag1=1;
		if(c[i]&&c[i+1]&&c[i+2]) flag1=1;
		if(a[i]&&a[i+1]) flag2=1;
		if(a[i]&&a[i+2]) flag2=1;
		if(b[i]&&b[i+1]) flag2=1;
		if(b[i]&&b[i+2]) flag2=1;
		if(c[i]&&c[i+1]) flag2=1;
		if(c[i]&&c[i+2]) flag2=1;
	}
	if(flag1) puts("0");
	else if(flag2) puts("1");
	else puts("2");
	return 0;
}

Tokitsukaze and Discard Items CodeForces - 1191C
Recently, Tokitsukaze found an interesting game. Tokitsukaze had n items at the beginning of this game. However, she thought there were too many items, so now she wants to discard m (1≤m≤n) special items of them.

These n items are marked with indices from 1 to n. In the beginning, the item with index i is placed on the i-th position. Items are divided into several pages orderly, such that each page contains exactly k positions and the last positions on the last page may be left empty.

Tokitsukaze would do the following operation: focus on the first special page that contains at least one special item, and at one time, Tokitsukaze would discard all special items on this page. After an item is discarded or moved, its old position would be empty, and then the item below it, if exists, would move up to this empty position. The movement may bring many items forward and even into previous pages, so Tokitsukaze would keep waiting until all the items stop moving, and then do the operation (i.e. check the special page and discard the special items) repeatedly until there is no item need to be discarded.
在这里插入图片描述
Consider the first example from the statement: n=10, m=4, k=5, p=[3,5,7,10]. The are two pages. Initially, the first page is special (since it is the first page containing a special item). So Tokitsukaze discards the special items with indices 3 and 5. After, the first page remains to be special. It contains [1,2,4,6,7], Tokitsukaze discards the special item with index 7. After, the second page is special (since it is the first page containing a special item). It contains [9,10], Tokitsukaze discards the special item with index 10.
Tokitsukaze wants to know the number of operations she would do in total.

Input
The first line contains three integers n, m and k (1≤n≤1018, 1≤m≤105, 1≤m,k≤n) — the number of items, the number of special items to be discarded and the number of positions in each page.

The second line contains m distinct integers p1,p2,…,pm (1≤p1<p2<…<pm≤n) — the indices of special items which should be discarded.

Output
Print a single integer — the number of operations that Tokitsukaze would do in total.

Examples
Input
10 4 5
3 5 7 10
Output
3
Input
13 4 5
7 8 9 10
Output
1
Note
For the first example:

In the first operation, Tokitsukaze would focus on the first page [1,2,3,4,5] and discard items with indices 3 and 5;
In the second operation, Tokitsukaze would focus on the first page [1,2,4,6,7] and discard item with index 7;
In the third operation, Tokitsukaze would focus on the second page [9,10] and discard item with index 10.
For the second example, Tokitsukaze would focus on the second page [6,7,8,9,10] and discard all special items at once.
一个序列,分成几页,每页都有k个数,现在要移除一些数。每一次移除处在相同页上的数字,问要操作几次。
一个模拟,没有什么技巧。记录移动的步数,处在相同页上的数字,除以k之后是相等的。
代码如下:

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<vector>
#include<map>
#define ll long long
using namespace std;

const int maxx=1e5+100;
ll a[maxx];
ll n,m,k;

int main()
{
	while(scanf("%lld%lld%lld",&n,&m,&k)!=EOF)
	{
		for(int i=1;i<=m;i++) cin>>a[i];
		ll ans=0;
		ll move=0;
		ll x=k;
		for(int i=1;i<=m;)
		{
			int j=i;
			while((a[j]-move-1)/k==(a[i]-move-1)/k) j++;
			ans++;
			move+=j-i;
			i=j;
		}
		printf("%lld\n",ans);
	}
}

Tokitsukaze, CSL and Stone Game CodeForces - 1191D
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
Input
1
0
Output
cslnb
Input
2
1 0
Output
cslnb
Input
2
2 2
Output
sjfnb
Input
3
2 3 1
Output
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堆石子,两个人每次拿一个,如果拿完之后出现两堆石子数相等或者没有石子可以拿了,就输了。问谁会赢。
先来分析先手必败的情况:
①有三堆或以上石子数目相同。
②有两堆或以上石子数目为零。
③有两堆石子数目相同,这样的有多个。例如 3 3 4 4 7。
④有两堆石子数目相同,而且还有一堆石子的数目比它少一。例如 4 5 5。
除去这些情况,就是俩个人公平竞争大的时候了。
先来分析一下必败态,就是0,1,2,3,,,,n-1。谁遇到这样的情况,谁肯定就输了。那么每个人拿一个石头,谁会遇到这种情况呢。分析(sum-n*(n-1)/2)的奇偶性就可以了。
代码如下:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#define ll long long
using namespace std;

const int maxx=1e5+100;
int a[maxx];
int n;

bool check()
{
	int cnt=0;
	if(n==1&&a[1]==0) return 1;
	for(int i=1;i<=n;i++)
	{
		if(a[i]==0) cnt++;
	}
	if(cnt>=2) return 1;
	for(int i=1;i<=n-2;i++)
	{
		if(a[i]==a[i+1]&&a[i+1]==a[i+2]) return 1;
	}
	cnt=0;a[0]=-1;
	for(int i=1;i<=n-1;i++)
	{
		if(a[i]==a[i+1]) 
		{
			cnt++;
			if(a[i]-a[i-1]==1) return 1;
		}
	}
	if(cnt>1) return 1;
	return 0;
}
int main()
{
	while(scanf("%d",&n)!=EOF)
	{
		for(int i=1;i<=n;i++) scanf("%d",&a[i]);
		sort(a+1,a+1+n);
		if(check())
		{
			puts("cslnb");
		}
		else
		{
			ll sum=0;
			for(int i=1;i<=n;i++) sum+=a[i];
			if((sum-n*(n-1)/2)&1) puts("sjfnb");
			else puts("cslnb");
		}
	}
	return 0;
}

后两道题没出来,嘤嘤嘤
努力加油a啊,(o)/~

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

starlet_kiss

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值