Codeforces Round #430 (Div. 2)

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>

using namespace std;
#define LL long long
#define pb push_back
#define mk make_pair
#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 = 2e5 + 10;
const int INF = 1e9 + 10;
LL l, r, x, y, k;

int main(){
	scanf("%lld%lld%lld%lld%lld", &l, &r, &x, &y, &k);
	bool f = false;
	while(x <= y) {
		LL mid = (x + y) >> 1;
		if(mid * k < l) x = mid + 1;
		else if(mid * k > r)	y = mid - 1;
		else {
			f = true;
			break;
		}
	}
	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>

using namespace std;
#define LL long long
#define pb push_back
#define mk make_pair
#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 = 2e5 + 10;
const int INF = 1e9 + 10;
const double eps = 1e-8;
LL r, d;

int main(){
	scanf("%lld%lld", &r, &d);
	int n;	scanf("%d", &n);
	int cnt = 0;
	for(int i = 0; i < n; ++i) {
		LL x, y, ri;
		scanf("%lld%lld%lld", &x, &y, &ri);
		LL dis = x * x + y * y;
		double res = sqrt(dis * 1.0);
		if(res + ri > r || res - ri < (r - d)) {
			continue;
		} else {
			cnt++;
		}
	}
	printf("%d\n", cnt);
	return 0;
}

C

题意:给你一个n个结点 n - 1条边的数,每个结点有一个权值,定义每个结点的美丽值为这个结点到根节点1结点之间所有结点的gcd,现在你可以将某个点的权值变成0,求每个点可能的美丽值的最大值

思路:dfs,求出u结点的父结点v能达到的所有状态,然后更新即可,用set保存结果,去重之后还是很少的

#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>

using namespace std;
#define LL long long
#define pb push_back
#define mk make_pair
#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 = 2e5 + 10;
const int INF = 1e9 + 10;
int a[qq], ans[qq], n;
vector<int> G[qq];
int Gcd(int a, int b) {
	return b == 0 ? a : Gcd(b, a % b);
}
void Dfs(int rt, int fa, int pre, set<int> & x) {
	for(int v : G[rt]) {
		if(v == fa)	continue;
		set<int> tmp;
		for(int p : x) {
			tmp.insert(Gcd(p, a[v]));
		}
		tmp.insert(Gcd(pre, a[rt]));
		Dfs(v, rt, Gcd(pre, a[rt]), tmp);
	}
	ans[rt] = *x.rbegin();
}

int main(){
	scanf("%d", &n);
	for(int i = 1; i <= n; ++i) {
		scanf("%d", a + i);
	}
	for(int i = 1; i < n; ++i) {
		int x, y;	scanf("%d%d", &x, &y);
		G[x].pb(y), G[y].pb(x);
	}
	set<int> x;
	x.insert(0);
	x.insert(a[1]);
	Dfs(1, 1, a[1], x);
	for(int i = 1; i <= n; ++i) {
		printf("%d ", ans[i]);
	}
	puts("");
	return 0;
}

D

参考:传送门


#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>

using namespace std;
#define LL long long
#define pb push_back
#define mk make_pair
#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 = 6e5 + 10;
const int INF = 1e9 + 10;
int n, m, node_cnt;
int ch[19 * qq][2];
int vis[qq];
void Init() {
	mst(ch[0], 0);
	node_cnt = 1;
}
void Insert(int x) {
	int cur = 0;
	for(int i = 19; i >= 0; --i) {
		int idx = (x >> i) & 1;
		if(!ch[cur][idx]) {
			mst(ch[node_cnt], 0);
			ch[cur][idx] = node_cnt++;
		}
		cur = ch[cur][idx];
	}
}
void Query(int x) {
	int cur = 0;
	int ans = 0;
	for(int i = 19; i >= 0; --i) {
		int idx = (x >> i) & 1;
		if(ch[cur][idx]) {
			cur = ch[cur][idx];
		} else {
			ans += (1 << i);
			cur = ch[cur][idx ^ 1];
		}
//		printf("%d\n", ans);
	}
	printf("%d\n", ans);
}

int main(){
	scanf("%d%d", &n, &m);
	Init();
	for(int x, i = 0; i < n; ++i) {
		scanf("%d", &x);
		vis[x] = 1;
	}
	for(int i = 0; i < qq; ++i) {
		if(!vis[i])	Insert(i);
	}
	int x = 0, tmp;
	for(int i = 0; i < m; ++i) {
		scanf("%d", &tmp);
		x ^= tmp;
		Query(x);
	}
	return 0;
}


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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值