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

2024-02-01 15:32
文章标签 codeforces round div abcd 573

本文主要是介绍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)/~

这篇关于Codeforces Round #573 (Div. 2)(ABCD)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/667673

相关文章

Codeforces Round #240 (Div. 2) E分治算法探究1

Codeforces Round #240 (Div. 2) E  http://codeforces.com/contest/415/problem/E 2^n个数,每次操作将其分成2^q份,对于每一份内部的数进行翻转(逆序),每次操作完后输出操作后新序列的逆序对数。 图一:  划分子问题。 图二: 分而治之,=>  合并 。 图三: 回溯:

Codeforces Round #261 (Div. 2)小记

A  XX注意最后输出满足条件,我也不知道为什么写的这么长。 #define X first#define Y secondvector<pair<int , int> > a ;int can(pair<int , int> c){return -1000 <= c.X && c.X <= 1000&& -1000 <= c.Y && c.Y <= 1000 ;}int m

Codeforces Beta Round #47 C凸包 (最终写法)

题意慢慢看。 typedef long long LL ;int cmp(double x){if(fabs(x) < 1e-8) return 0 ;return x > 0 ? 1 : -1 ;}struct point{double x , y ;point(){}point(double _x , double _y):x(_x) , y(_y){}point op

Codeforces Round #113 (Div. 2) B 判断多边形是否在凸包内

题目点击打开链接 凸多边形A, 多边形B, 判断B是否严格在A内。  注意AB有重点 。  将A,B上的点合在一起求凸包,如果凸包上的点是B的某个点,则B肯定不在A内。 或者说B上的某点在凸包的边上则也说明B不严格在A里面。 这个处理有个巧妙的方法,只需在求凸包的时候, <=  改成< 也就是说凸包一条边上的所有点都重复点都记录在凸包里面了。 另外不能去重点。 int

Codeforces 482B 线段树

求是否存在这样的n个数; m次操作,每次操作就是三个数 l ,r,val          a[l] & a[l+1] &......&a[r] = val 就是区间l---r上的与的值为val 。 也就是意味着区间[L , R] 每个数要执行 | val 操作  最后判断  a[l] & a[l+1] &......&a[r] 是否= val import ja

CSS实现DIV三角形

本文内容收集来自网络 #triangle-up {width: 0;height: 0;border-left: 50px solid transparent;border-right: 50px solid transparent;border-bottom: 100px solid red;} #triangle-down {width: 0;height: 0;bor

创建一个大的DIV,里面的包含两个DIV是可以自由移动

创建一个大的DIV,里面的包含两个DIV是可以自由移动 <body>         <div style="position: relative; background:#DDF8CF;line-height: 50px"> <div style="text-align: center; width: 100%;padding-top: 0px;"><h3>定&nbsp;位&nbsp;

Codeforces Round 971 (Div. 4) (A~G1)

A、B题太简单,不做解释 C 对于 x y 两个方向,每一个方向至少需要 x / k 向上取整的步数,取最大值。 由于 x 方向先移动,假如 x 方向需要的步数多于 y 方向的步数,那么最后 y 方向的那一步就不需要了,答案减 1 代码 #include <iostream>#include <algorithm>#include <vector>#include <string>

CF#271 (Div. 2) D.(dp)

D. Flowers time limit per test 1.5 seconds memory limit per test 256 megabytes input standard input output standard output 题目链接: http://codeforces.com/contest/474/problem/D We s

CF #278 (Div. 2) B.(暴力枚举+推导公式+数学构造)

B. Candy Boxes time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output 题目链接: http://codeforces.com/contest/488/problem/B There