纪念一下自己第一场Cf
#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");
}
}
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.
Five integers h, m, s, t1, t2 (1 ≤ h ≤ 12, 0 ≤ m, s ≤ 59, 1 ≤ t1, t2 ≤ 12, t1 ≠ t2).
Misha's position and the target time do not coincide with the position of any hand.
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").
12 30 45 3 11
NO
12 0 1 12 1
YES
3 47 0 4 9
YES
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;
}
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!
The first line contains two integers n, k (1 ≤ n ≤ 105, 1 ≤ 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.
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").
5 3 1 0 1 1 1 0 1 0 0 1 0 0 1 0 0
NO
3 2 1 0 1 1 0 1
YES
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;
}