Codeforces Round #426(div2)

本文介绍了一个有趣的编程问题:通过玩具的起始位置和旋转时间来判断其旋转方向。此外,还探讨了如何确保聚会入口的安全性和验证游戏得分的正确性。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

A. The Useless Toy
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays – caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.

Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):

After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.

Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.

Input

There are two characters in the first string – the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.

In the second strings, a single number n is given (0 ≤ n ≤ 109) – the duration of the rotation.

It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.

Output

Output cw, if the direction is clockwise, ccw – if counter-clockwise, and undefined otherwise.

Examples
input
^ >
1
output
cw
input
< ^
3
output
ccw
input
^ v
6
output
undefined

#include <bits/stdc++.h>
#include <cstring>
using namespace std;
char rotc[5];
char rotcc[5];
int main()
{
//	freopen("data.in.txt","r",stdin);
	rotc[0]=118,rotc[1]=60,rotc[2]=94,rotc[3]=62;
	rotcc[0]=62,rotcc[1]=94,rotcc[2]=60,rotcc[3]=118;
	string in;
	getline(cin,in);
		char s=in[0],e=in[2];
		int pos_cs,pos_ccs;
		for(int i=0;i<=3;i++){
			if(s==rotc[i])
				pos_cs=i;
			if(s==rotcc[i])
				pos_ccs=i;
		}
		int n;
		cin>>n;
//		cout<<s<<" "<<e<<" "<<n<<endl;
		if(rotc[(pos_cs+n)%4]==e&&rotcc[(pos_ccs+n)%4]!=e)
			cout<<"cw"<<endl;
		else
		if(rotc[(pos_cs+n)%4]!=e&&rotcc[(pos_ccs+n)%4]==e)
			cout<<"ccw"<<endl;
		else
			cout<<"undefined"<<endl;
	return 0;
} 

B. The Festive Evening
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

It's the end of July – the time when a festive evening is held at Jelly Castle! Guests from all over the kingdom gather here to discuss new trends in the world of confectionery. Yet some of the things discussed here are not supposed to be disclosed to the general public: the information can cause discord in the kingdom of Sweetland in case it turns out to reach the wrong hands. So it's a necessity to not let any uninvited guests in.

There are 26 entrances in Jelly Castle, enumerated with uppercase English letters from A to Z. Because of security measures, each guest is known to be assigned an entrance he should enter the castle through. The door of each entrance is opened right before the first guest's arrival and closed right after the arrival of the last guest that should enter the castle through this entrance. No two guests can enter the castle simultaneously.

For an entrance to be protected from possible intrusion, a candy guard should be assigned to it. There are k such guards in the castle, so if there are more than k opened doors, one of them is going to be left unguarded! Notice that a guard can't leave his post until the door he is assigned to is closed.

Slastyona had a suspicion that there could be uninvited guests at the evening. She knows the order in which the invited guests entered the castle, and wants you to help her check whether there was a moment when more than k doors were opened.

Input

Two integers are given in the first string: the number of guests n and the number of guards k (1 ≤ n ≤ 1061 ≤ k ≤ 26).

In the second string, n uppercase English letters s1s2... sn are given, where si is the entrance used by the i-th guest.

Output

Output «YES» if at least one door was unguarded during some time, and «NO» otherwise.

You can output each letter in arbitrary case (upper or lower).

Examples
input
5 1
AABBB
output
NO
input
5 1
ABABB
output
YES
Note

In the first sample case, the door A is opened right before the first guest's arrival and closed when the second guest enters the castle. The door B is opened right before the arrival of the third guest, and closed after the fifth one arrives. One guard can handle both doors, as the first one is closed before the second one is opened.

In the second sample case, the door B is opened before the second guest's arrival, but the only guard can't leave the door A unattended, as there is still one more guest that should enter the castle through this door.


#include <bits/stdc++.h>
#include <cstring>
using namespace std;
const int maxn=30;
struct node
{
	int s=INT_MAX;
	int e=INT_MIN;
};
int main()
{
//	freopen("data.in.txt","r",stdin);
	int n,k;
	while(cin>>n>>k){
		node inf[maxn];
		char temp;
		for(int i=0;i<n;i++){
			cin>>temp;
			if(inf[temp-'A'].s==INT_MAX)
				inf[temp-'A'].s=i;
			inf[temp-'A'].e=i;
		}
		bool flag=0;
		for(int i=0;i<n;i++){
			int sum=0;
			for(int j=0;j<26;j++)
				if(i>=inf[j].s&&i<=inf[j].e)
					sum++;
			if(sum>k){
				flag=1;
				cout<<"YES"<<endl;
				break;
			}
		}
		if(flag==0)
			cout<<"NO"<<endl;
	}
	return 0;
} 



C. The Meaningless Game
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Slastyona and her loyal dog Pushok are playing a meaningless game that is indeed very interesting.

The game consists of multiple rounds. Its rules are very simple: in each round, a natural number k is chosen. Then, the one who says (or barks) it faster than the other wins the round. After that, the winner's score is multiplied by k2, and the loser's score is multiplied by k. In the beginning of the game, both Slastyona and Pushok have scores equal to one.

Unfortunately, Slastyona had lost her notepad where the history of all n games was recorded. She managed to recall the final results for each games, though, but all of her memories of them are vague. Help Slastyona verify their correctness, or, to put it another way, for each given pair of scores determine whether it was possible for a game to finish with such result or not.

Input

In the first string, the number of games n (1 ≤ n ≤ 350000) is given.

Each game is represented by a pair of scores ab (1 ≤ a, b ≤ 109) – the results of Slastyona and Pushok, correspondingly.

Output

For each pair of scores, answer "Yes" if it's possible for a game to finish with given score, and "No" otherwise.

You can output each letter in arbitrary case (upper or lower).

Example
input
6
2 4
75 45
8 8
16 16
247 994
1000000000 1000000
output
Yes
Yes
Yes
No
No
Yes
Note

First game might have been consisted of one round, in which the number 2 would have been chosen and Pushok would have won.

The second game needs exactly two rounds to finish with such result: in the first one, Slastyona would have said the number 5, and in the second one, Pushok would have barked the number 3.


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
//	freopen("data.in.txt","r",stdin);
	int n;
	scanf("%d",&n);
	while(n--){
		ll a,b;
		scanf("%lld%lld",&a,&b);
		ll sub_ab=cbrt(a*b);
//		cout<<sub_ab<<" ";
		ll sub_a=a/sub_ab,sub_b=b/sub_ab;
//			cout<<sub_ab<<" "<<sub_a<<"  "<<sub_b<<endl;
		if(sub_a*sub_a*sub_b==a&&sub_b*sub_b*sub_a==b)
			printf("Yes\n");
		else
			printf("No\n");
	} 
	return 0;
} 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

Jamence

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

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

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

打赏作者

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

抵扣说明:

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

余额充值