Codeforces Round #430 (Div. 2) 【A、B、C、D题】
【感谢牛老板对D题的指点OTZ】
codeforces 842 A. Kirill And The Game【暴力】
给定a的范围[l,r],b的范围[x,y],问是否存在a/b等于k。直接暴力判断即可。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long ll;
ll l, r, x, y, k;
int main() {
bool f;
while(~scanf("%lld%lld%lld%lld%lld", &l, &r, &x, &y, &k)) {
f = ;
for(ll i = x; i <= y; ++i) {
if(i * k >= l && i * k <= r) {
f = ; break;
}
}
if(f) puts("YES");
else puts("NO");
}
return ;
}
31ms
codeforces 842 B. Gleb And Pizza【几何水题】
已知大圆圆心在原点,半径为r,其中外壳厚度为d,给出n个小圆的位置和半径,问有多少个小圆包含在外壳上。水题。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long ll;
int r, d, x, y, rr, n;
int main() {
bool f;
while(~scanf("%d%d", &r, &d)) {
int cnt = ;
int s1 = (r-d), s2 = r;
scanf("%d", &n);
while(n--) {
scanf("%d%d%d", &x, &y, &rr);
double a = sqrt(x*x+y*y);
if(s1+rr <= a && a <= s2-rr)
cnt++;
}
printf("%d\n", cnt);
}
return ;
}
62ms
codeforces 842 C. Ilya And The Tree【DFS】
题意:给一棵树,根为1,每个节点有一个值,每个节点的美丽值为该节点到根的路径上所有节点的最大公约数,现在要求每个节点的美丽值。每个节点的求解,可以将任意一个节点的值改变为0或者不做任何改变。
题解:从根DFS,用set存储每个节点到根节点的gcd值,记录路径节点都不做改变的gcd值val,往下一个节点走时,若要将节点值置零,直接向set插入val即可,继续操作。最后答案即为每个节点的set的最后一个值(set默认升序排序的)。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
using namespace std;
typedef long long ll;
const int N = 2e5+;
int n;
int a[N];
vector<int>g[N];
set<int>s[N];
set<int>::iterator it;
int gcd(int a, int b) {return b?gcd(b, a%b):a;}
void dfs(int u, int fa, int val) {
for(it = s[fa].begin(); it != s[fa].end(); ++it) s[u].insert(gcd(*it, a[u]));
s[u].insert(val);
val = gcd(val, a[u]);
for(int i = ; i < g[u].size(); ++i) if(g[u][i] != fa) dfs(g[u][i], u, val);
}
int main() {
int i, j, x, y;
while(~scanf("%d", &n)) {
for(i = ; i <= n ;++i) {g[i].clear();s[i].clear();}
for(i = ; i <= n; ++i)scanf("%d", &a[i]);
for(i = ; i <= n-; ++i) {
scanf("%d%d", &x, &y);
g[x].push_back(y); g[y].push_back(x);
}
s[].insert();
dfs(, , );
for(i = ; i <= n; ++i)
printf("%d ", *s[i].rbegin());
puts("");
}
return ;
}
311ms
未完待续,,,
codeforces 842 D. Vitya and Strange Lesson【trie+贪心】
题意:mex为一个序列中没出现的非负最小值,现在序列有n个数,有m个询问,每个询问给一个数,将序列中每个数与x异或,然后查询序列的mex值。
题解:其实就是相当于求没出现的数与x异或的最小值。将序列没出现的数以二进制形式插入trie树中,树上跑x异或的最小值,贪心地让某位的值与x对应的位的值相同即可。
//yy:一开始字典树大小开小了,结果郁闷了很久。。。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#define CLR(a,b) memset((a),(b),sizeof((a)))
using namespace std;
typedef long long ll;
const int N = ;
const int M = 3e5+;
int n, m;
struct Trie {
int next[];
int v;
void init() {
v = ;
memset(next, -, sizeof(next));
}
}T[N*M*];
int le;
void inser(int x) {
int p = ;
for(int i = N-; i >= ; --i) {
int t = (x>>i) & ;
if(T[p].next[t] == -) {
T[le].init();
T[p].next[t] = le++;
}
p = T[p].next[t];
}
T[p].v = x;
}
void query(int x) {
int i = , p = ;
for(int i = N-; i >= ; --i) {
int t = (x>>i) & ;
if(T[p].next[t] == -) p = T[p].next[t^];
else p = T[p].next[t];
}
printf("%d\n", x ^ T[p].v);
}
bool a[<<N];
int main() {
int i, x, y;
while(~scanf("%d%d", &n, &m)) {
CLR(a, );
for(i = ; i <= n; ++i) {scanf("%d", &x); a[x] = ;}
le = ; T[].init();
for(i = ; i <= (<<N)-; ++i) if(!a[i]) inser(i);
y = ;
while(m--) {
scanf("%d", &x);
y ^= x;
query(y);
}
}
return ;
}
234ms
Codeforces Round #430 (Div. 2) 【A、B、C、D题】的更多相关文章
- Codeforces Round #367 (Div. 2) A. Beru-taxi (水题)
Beru-taxi 题目链接: http://codeforces.com/contest/706/problem/A Description Vasiliy lives at point (a, b ...
- Codeforces Round #575 (Div. 3) 昨天的div3 补题
Codeforces Round #575 (Div. 3) 这个div3打的太差了,心态都崩了. B. Odd Sum Segments B 题我就想了很久,这个题目我是找的奇数的个数,因为奇数想分 ...
- Codeforces Round #334 (Div. 2) A. Uncowed Forces 水题
A. Uncowed Forces Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/604/pro ...
- C - Ilya And The Tree Codeforces Round #430 (Div. 2)
http://codeforces.com/contest/842/problem/C 树 dp 一个数的质因数有限,用set存储,去重 #include <cstdio> #includ ...
- D. Vitya and Strange Lesson Codeforces Round #430 (Div. 2)
http://codeforces.com/contest/842/problem/D 树 二进制(路径,每个节点代表一位) #include <cstdio> #include < ...
- Codeforces Round #430 (Div. 2) C. Ilya And The Tree
地址:http://codeforces.com/contest/842/problem/C 题目: C. Ilya And The Tree time limit per test 2 second ...
- Codeforces Round #430 (Div. 2) - D
题目链接:http://codeforces.com/contest/842/problem/D 题意:定义Mex为一个序列中最小的未出现的正整数,给定一个长度为n的序列,然后有m个询问,每个询问给定 ...
- Codeforces Round #430 (Div. 2) - B
题目链接:http://codeforces.com/contest/842/problem/B 题意:给定一个圆心在原点(0,0)半径为r的大圆和一个圆内的圆环长度d,然后给你n个小圆,问你有多少个 ...
- Codeforces Round #430 (Div. 2) - A
题目链接:http://codeforces.com/contest/842/problem/A 题意:给定l,r,x,y,k.问是否存在a (l<=a<=r) 和b (x<=b&l ...
随机推荐
- linux系统下图片的路径
1. 图片跟网页或者程序在同一目录下 直接 src="abc.jpg" 如果不行 就加多一个斜杠 src="/abc.jpg"
- vue打包后运行在本地/非服务器端环境的访问路径
vue打包前的配置: 项目目录下--> config文件夹---> index.js: build: { assetsPublickPath: './', // 设置成相对路径 ...
- java POST 传值 加签 验证
话不多说,代码如下 package com.syl.test_key; import lombok.extern.slf4j.Slf4j; import org.apache.commons.code ...
- 初学zookeeper--自定义事件监听
zk有四种节点类型: 持久节点,持久顺序节点,临时节点,临时顺序节点. 自定义监听事件时,在节点的创建,修改,删除的方法第一行都需要加入是否监听的一个方法: //开启监听的方法.第二个参数表示是否开启 ...
- Spring系列之Alias标签的解析与使用
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.sp ...
- mysql数据库详解
001 数据库应用系统设计 1.规划 2.需求分析 3.概念模型设计 4.逻辑设计 5.物理设计 6.程序编制及调试 7.运行及维护. 002 创建数据库 CREATE DAT ...
- Java测试工具使用(1)--Junit
在进行测试之前需要导入junit的两个包,分别是 junit:4.12;hamcrest-core:1.1 1.基本测试标签 @Test.@Before.@After 2.组测试 有时候多个测试文件, ...
- 纯CSS实现立方体旋转
下面为通过CSS动画实现的立方体旋转,可以改变CSS代码中关键帧定义(@keyframes)来改变立方体的旋转方式 HTML部分: <body class="body"> ...
- Redis学习笔记(一) ---- Linux系统中部署Redis存储系统
Redis 一.Redis简介 1.Redis是一个key-value存储系统.和Memcached类似,它支持存储的value类型相对更多,包括string(字符串).list(链表).set(集合 ...
- html+css模仿的锤子官方首页
<div id="wrapper"> <header> <div class="container"> <h1> ...