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

A

#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <utility>
#include <bitset>

using namespace std;
#define LL long long
#define pb push_back
#define mk make_pair
#define fi first
#define se second
#define pill pair<int, int>
#define mst(a, b)	memset(a, b, sizeof a)
#define REP(i, x, n)	for(int i = x; i <= n; ++i)
const int MOD = 1e9 + 7;
const int qq = 1e5 + 10;
const LL INF = 1e9 + 10;
int tail[30], head[30];
char st[3];

int main(){
	scanf("%s", st);
	int n;	scanf("%d", &n);
	bool f = false;
	for(int i = 0; i < n; ++i) {
		char s[3];	scanf("%s", s);
		if(strcmp(s, st) == 0) {
			f = true;
		} else if(s[0] == st[1] && s[1] == st[0]) {
			f = true;
		}
		if(s[0] == st[1]) {
			if(tail[st[0] - 'a'])	f = true;
		}
		if(s[1] == st[0]) {
			if(head[st[1] - 'a'])	f = true;
		}
		head[s[0] - 'a']++, tail[s[1] - 'a']++;
	}
	if(f)	puts("YES");
	else	puts("NO");
	return 0;
}

B

题意:给出一个时间的时、分、秒,然后再给你两个整数点,问在时钟上这两个点是不是再同一侧

思路:直接求个时、分、秒的角度然后排序判断一下就行拉

#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <utility>
#include <bitset>

using namespace std;
#define LL long long
#define pb push_back
#define mk make_pair
#define fi first
#define se second
#define pill pair<int, int>
#define mst(a, b)	memset(a, b, sizeof a)
#define REP(i, x, n)	for(int i = x; i <= n; ++i)
const int MOD = 1e9 + 7;
const int qq = 1e5 + 10;
const LL INF = 1e9 + 10;

int main(){
	int h, m, s, t1, t2;
	cin >> h >> m >> s >> t1 >> t2;
	if(h == 12)	h = 0;
	double deg[3];
	deg[2] = s * 1.0 / 60 * 360.0;
	deg[1] = m * 1.0 / 60 * 360.0 + (6.0 * (s * 1.0 / 60));
	deg[0] = h * 1.0 / 12 * 360.0 + (30.0 * (m * 1.0 / 60)) + (s * 1.0 / (12 * 60 * 60));
	sort(deg, deg + 3);
	double d1 = t1 * 1.0 / 12 * 360.0;
	double d2 = t2 * 1.0 / 12 * 360.0;
	bool f = false;
/*	printf("%lf %lf %lf\n", deg[0], deg[1], deg[2]);
	printf("%lf %lf\n", d1, d2);*/
	for(int i = 1; i < 3; ++i) {
		if(deg[i - 1] <= d1 && d1 <= deg[i]) {
			if(deg[i - 1] <= d2 && d2 <= deg[i])
				f = true;
		}
	}
	if(d1 >= deg[2] || d1 <= deg[0]) {
		if(d2 >= deg[2] || d2 <= deg[0]) {
			f = true;
		}
	}
	if(f)	puts("YES");
	else	puts("NO");
	return 0;
}

C

题意:让你从n行中选出几行,要求每一列的和不超过所选出行数的一半

思路:如果选两行不可以那么选三行一定不可以,所以我们只需要判断存不存在选两行的情况就行

#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <utility>
#include <bitset>

using namespace std;
#define LL long long
#define pb push_back
#define mk make_pair
#define fi first
#define se second
#define pill pair<int, int>
#define mst(a, b)	memset(a, b, sizeof a)
#define REP(i, x, n)	for(int i = x; i <= n; ++i)
const int MOD = 1e9 + 7;
const int qq = 1e5 + 10;
const LL INF = 1e9 + 10;
int dp[105];

int main(){
	int n, k;	scanf("%d%d", &n, &k);
	for(int i = 0; i < n; ++i) {
		int m = 0;
		for(int x, j = k - 1; j >= 0; --j) {
			scanf("%d", &x);
			if(x)	m += (1 << j);
		}
//		printf("%d\n", m);
		dp[m]++;
	}
	if(dp[0]) {
		puts("YES");
		return 0;
	}
	if(k == 1) {
		puts("NO");
	} else {
		bool f = false;
		for(int i = 0; i < (1 << k); ++i) {
			for(int j = 0; j < (1 << k); ++j) {
				if((i & j) == 0 && i != j) {
	//				printf("%d %d\n", i, j);
					if(dp[i] && dp[j])	f = true;
				}
			}
		}
		if(f)	puts("YES");
		else	puts("NO");
	} 
	return 0;
}


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值