Codeforces Round #438 by Sberbank and Barcelona Bootcamp (Div. 1 + Div. 2 combined)

纪念一下自己第一场Cf

A. Bark to Unlock
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

As technologies develop, manufacturers are making the process of unlocking a phone as user-friendly as possible. To unlock its new phone, Arkady's pet dog Mu-mu has to bark the password once. The phone represents a password as a string of two lowercase English letters.

Mu-mu's enemy Kashtanka wants to unlock Mu-mu's phone to steal some sensible information, but it can only bark n distinct words, each of which can be represented as a string of two lowercase English letters. Kashtanka wants to bark several words (not necessarily distinct) one after another to pronounce a string containing the password as a substring. Tell if it's possible to unlock the phone in this way, or not.

Input

The first line contains two lowercase English letters — the password on the phone.

The second line contains single integer n (1 ≤ n ≤ 100) — the number of words Kashtanka knows.

The next n lines contain two lowercase English letters each, representing the words Kashtanka knows. The words are guaranteed to be distinct.

Output

Print "YES" if Kashtanka can bark several words in a line forming a string containing the password, and "NO" otherwise.

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

Examples
input
ya
4
ah
oy
to
ha
output
YES
input
hp
2
ht
tp
output
NO
input
ah
1
ha
output
YES
Note

In the first example the password is "ya", and Kashtanka can bark "oy" and then "ah", and then "ha" to form the string "oyahha" which contains the password. So, the answer is "YES".

In the second example Kashtanka can't produce a string containing password as a substring. Note that it can bark "ht" and then "tp" producing "http", but it doesn't contain the password "hp" as a substring.

In the third example the string "hahahaha" contains "ah" as a substring.


分析:就是给你一个长度为2的字符串,然后给你n个字符串看看能拼接成给的这个不,刚开始英文捉鸡,没翻译出来就2位,卡了,后来翻出来直接模拟。

#include<stdio.h>
#include<iostream> 
#include <algorithm>
#include<string.h>
#include<vector>
#include<math.h>
#include<queue>
#include<set>
#define LL long long
#define INf 0x3f3f3f3f
int dir[5][2]={0,1,0,-1,1,0,-1,0};
using namespace std;
int KGCD(int a,int b){if(a==0)return b;if(b==0)return a;if(~a&1){ if(b&1) return KGCD(a>>1,b);else return KGCD(a>>1,b>>1) <<1; } if(~b & 1)  return KGCD(a, b>>1);  if(a > b) return KGCD((a-b)>>1, b);return KGCD((b-a)>>1, a);}  
int LCM(int a,int b){ return a/KGCD(a,b)*b; } 
int main()
{
	char a[10];
	char b[105][10];
	int n,flag,flag1;
	while(scanf("%s",a)!=EOF)
	{
		scanf("%d",&n);
		for(int i=0;i<n;i++)
			scanf("%s",b[i]);
		flag=0;
		for(int i=0;i<n;i++)
		{
			for(int j=0;j<n;j++)
			{
				if((b[i][0]==a[0]&&b[i][1]==a[1])||(b[i][1]==a[0]&&b[j][0]==a[1])||(b[i][0]==a[1]&&b[j][1]==a[0]))
				{
					printf("YES\n");
					flag=1;
					break;
				}
			}
			if(flag)
				break;
		}
		if(!flag)
			printf("NO\n");
	}
} 


B. Race Against Time
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Have you ever tried to explain to the coordinator, why it is eight hours to the contest and not a single problem has been prepared yet? Misha had. And this time he has a really strong excuse: he faced a space-time paradox! Space and time replaced each other.

The entire universe turned into an enormous clock face with three hands — hour, minute, and second. Time froze, and clocks now show the time h hours, m minutes, s seconds.

Last time Misha talked with the coordinator at t1 o'clock, so now he stands on the number t1 on the clock face. The contest should be ready by t2 o'clock. In the terms of paradox it means that Misha has to go to number t2 somehow. Note that he doesn't have to move forward only: in these circumstances time has no direction.

Clock hands are very long, and Misha cannot get round them. He also cannot step over as it leads to the collapse of space-time. That is, if hour clock points 12 and Misha stands at 11 then he cannot move to 1 along the top arc. He has to follow all the way round the clock center (of course, if there are no other hands on his way).

Given the hands' positions, t1, and t2, find if Misha can prepare the contest on time (or should we say on space?). That is, find if he can move from t1 to t2 by the clock face.

Input

Five integers hmst1t2 (1 ≤ h ≤ 120 ≤ m, s ≤ 591 ≤ t1, t2 ≤ 12t1 ≠ t2).

Misha's position and the target time do not coincide with the position of any hand.

Output

Print "YES" (quotes for clarity), if Misha can prepare the contest on time, and "NO" otherwise.

You can print each character either upper- or lowercase ("YeS" and "yes" are valid when the answer is "YES").

Examples
input
12 30 45 3 11
output
NO
input
12 0 1 12 1
output
YES
input
3 47 0 4 9
output
YES
Note

The three examples are shown on the pictures below from left to right. The starting position of Misha is shown with green, the ending position is shown with pink. Note that the positions of the hands on the pictures are not exact, but are close to the exact and the answer is the same.


第二个题目也是简单模拟,就给你小时,分钟,秒,然后分割成几块,问给你的2个点在不在同一块里面,直接求出来角度,判断即可,思维题。

#include<stdio.h>
#include<iostream> 
#include <algorithm>
#include<string.h>
#include<vector>
#include<math.h>
#include<queue>
#include<set>
#define LL long long
#define INf 0x3f3f3f3f
int dir[5][2]={0,1,0,-1,1,0,-1,0};
using namespace std;
int KGCD(int a,int b){if(a==0)return b;if(b==0)return a;if(~a&1){ if(b&1) return KGCD(a>>1,b);else return KGCD(a>>1,b>>1) <<1; } if(~b & 1)  return KGCD(a, b>>1);  if(a > b) return KGCD((a-b)>>1, b);return KGCD((b-a)>>1, a);}  
int LCM(int a,int b){ return a/KGCD(a,b)*b; } 
int main()
{
	double h,m,s,t1,t2;
	while(scanf("%lf%lf%lf%lf%lf",&h,&m,&s,&t1,&t2)!=EOF)
	{
		double a=s*6;//秒针的度数
		double b=(a/60+m*6);// 分针的度数
		while(b>=360.0)
			b=b-360;
		double c=(b/12+h*30);//小时的度数
		while(c>=360.0)
			c=c-360;
		t1=t1*30;
		t2=t2*30;
		if(t1==360)
			t1=0;
		if(t2==360)
			t2=0;
		double w[3];
		w[0]=a;
		w[1]=b;
		w[2]=c;
		sort(w,w+3);
		a=w[0];
		b=w[1];
		c=w[2];
		double t=max(t1,t2);
		t1=min(t1,t2);
		if((t1>=a && t<=b))//最小和第二小
			printf("YES\n");
		else if(t1>=b && t<=c)//最大和第二中间 
			printf("YES\n");
		else//判断最大和最小 
		{
			if(t>=c && t1<=a)//一个大 一个小 
				printf("YES\n");
			else if(t>=c && t1>=c)//都大 
				printf("YES\n");
			else if(t<=a && t1<=a)//都小 
				printf("YES\n");
			else 			//其他都是不行的 
				printf("NO\n");
		} 
	}
	return 0; 
} 

C. Qualification Rounds
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Snark and Philip are preparing the problemset for the upcoming pre-qualification round for semi-quarter-finals. They have a bank of nproblems, and they want to select any non-empty subset of it as a problemset.

k experienced teams are participating in the contest. Some of these teams already know some of the problems. To make the contest interesting for them, each of the teams should know at most half of the selected problems.

Determine if Snark and Philip can make an interesting problemset!

Input

The first line contains two integers nk (1 ≤ n ≤ 1051 ≤ k ≤ 4) — the number of problems and the number of experienced teams.

Each of the next n lines contains k integers, each equal to 0 or 1. The j-th number in the i-th line is 1 if j-th team knows i-th problem and 0otherwise.

Output

Print "YES" (quotes for clarity), if it is possible to make an interesting problemset, and "NO" otherwise.

You can print each character either upper- or lowercase ("YeS" and "yes" are valid when the answer is "YES").

Examples
input
5 3
1 0 1
1 1 0
1 0 0
1 0 0
1 0 0
output
NO
input
3 2
1 0
1 1
0 1
output
YES
Note

In the first example you can't make any interesting problemset, because the first team knows all problems.

In the second example you can choose the first and the third problems.


第三个题比较有意思,就是给你几个队伍几个题目,然后每个题不能超过一半以上的队伍做出来,k小于4最多也就16种情况,先扫描一边,看看有哪几种情况在一块,然后暴力枚举,如果可以构成a&b==0的形式说明存在符合题意的情况。

 a&b==0  a: 1001 b 0110 

#include<stdio.h>
#include<iostream> 
#include <algorithm>
#include<string.h>
#include<vector>
#include<math.h>
#include<queue>
#include<set>
#define LL long long
#define INf 0x3f3f3f3f
using namespace std;
int KGCD(int a,int b){if(a==0)return b;if(b==0)return a;if(~a&1){ if(b&1) return KGCD(a>>1,b);else return KGCD(a>>1,b>>1) <<1; } if(~b & 1)  return KGCD(a, b>>1);  if(a > b) return KGCD((a-b)>>1, b);return KGCD((b-a)>>1, a);}  
int LCM(int a,int b){ return a/KGCD(a,b)*b; } 
int mm[20];
int main()
{
	int n,m,x;
	while(scanf("%d%d",&n,&m)!=EOF)
	{
		memset(mm,0,sizeof(mm));
		for(int i=1;i<=n;i++)
		{
			int t=0;
			for(int j=1;j<=m;j++)
			{
				scanf("%d",&x);
				t=t*2+x;
			}
			mm[t]=1;
		}
		int tt=pow(2,m);
		int flag=0;
		for(int i=0;i<tt;i++)
		{
			for(int j=0;j<tt;j++)
			{
				if(mm[i] && mm[j] && (i&j)==0)
				{
					printf("YES\n");
					flag=1;
					break;
				}
			}
			if(flag)
					break;
		}
		if(!flag)
			printf("NO\n");
	}
	return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值