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 ...
随机推荐
- 基于URL权限拦截的实现
一.实现原理 1.实现原理 本示例采用SpringMVC的拦截器来实现一个基于URL的权限拦截. 2.权限管理流程 二.数据库搭建 1.用户表(sys_user) (1)表结构 (2)表字段说明 ...
- python-爬虫之urllib模块
urllib是python的一个获取url(Uniform Resource Locators,统一资源定址器)了,我们可以利用它来抓取远程的数据进行保存哦 1.基本方法 urllib.request ...
- 在centos linux上安装docker
前置条件 64-bit 系统 kernel 3.10+ 1.检查内核版本,返回的值大于3.10即可. $ uname -r 2.确保yum是最新的 $ yum update 3.安装 Docker y ...
- 2.Windows服务-->安装卸载服务
1.使用vs组件“VS2012开发人员命令提示” 工具,进行安装卸载服务(必须以“管理员身份运行") 安装和卸载的时候选择合适的安装程序工具地址,例如: 安装服务:C:\Windows\Mi ...
- 基于bootstrap的图片轮播功能
插入js及css支持: <link rel="stylesheet" href="css/bootstrap.min.css"/> <scri ...
- Tomcat服务器配置https认证(使用keytool生成证书)
一.证书生成 1.生成服务器证书 (1)打开打开命令控制台,进入jdk的bin目录 cd D:\Program Files\jdk1.6.0_45\bin (2)keytool为Tomcat生成证书( ...
- mysql 查询近几天的结果
//近两天的 不包括当天的数据 select * from order_info 今天的数据 select* fromorder_info where date(createtime)=curdate ...
- 模块—— 序列化模块、random模块、os模块 、 sys模块、hashlib模块、collections模块
今天我们来说说Python中的模块: 第三方模块 可以下载/安装/使用 第一步:将pip.exe 所在的目录添加到环境变量中第二步:输入pip第三步:pip install 要安装的模块名称 #pi ...
- Java设计模式—观察者模式
观察者模式(Observer Pattern)也叫做发布订阅模式(Publish/subscribe). 其定义如下: 定义对象间一种一对多的依赖关系,使得每当一个对象改变状态,则所有依赖于它的对象都 ...
- [小北De编程手记] : Lesson 05 - Selenium For C# 之 API 下
上一篇,我们介绍了一些Selenium WebDriver相关的API,下面我们就接着上一篇继续介绍Selenium常用的API,这一篇的内容主要涉及到以下话题: Selenium API:复杂事件处 ...