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 ...
随机推荐
- 想熟悉PostgreSQL?这篇就够了
欢迎大家前往腾讯云+社区,获取更多腾讯海量技术实践干货哦~ 本文由angel_郁 发表于云+社区专栏 什么是PostgreSQL? PostgreSQL是自由的对象-关系型数据库服务器,在灵活的BSD ...
- JavaEE 7 最全教程集锦(转)
转自 http://www.iteye.com/news/28009 甲骨文公司已经在6月份正式发布了JavaEE 7,该版本带来了诸多新的规范及特性,将企业级开发提升到了一个新的层次. Java E ...
- Splunk数据处理
0.提要 本篇主要从技术层面针对Splunk Enterprise中关于数据处理的概念.过程与部件进行了概要性总结. 1.数据管理基本概念 索引(index):Splunk用于存储事件的数据仓库: 索 ...
- java gc 随记
gc为garbage collection的缩写,中文翻译为垃圾回收.垃圾为不在使用的实例.变量,回收为释放垃圾所占用的内存空间. 学习过的C语言.C++语言,是没有垃圾回收机制的,因此需要软件工程师 ...
- 如何删除eclipse中已经保存的svn密码
一.打开eclipse--->点击Window--->点击Perference,打开eclipse配置,输入svn,然后点击svn,找到下方svn接口,查看下svn是什么类型的接口,如果是 ...
- 二、mysql存储引擎之InnoDB
一.存储引擎简介 mysql采用业务逻辑和数据存储分离的架构,底层的存储引擎为上层的SQL层提供了支持:mysql采用的是插件的方式将存储引擎直接加载到正在运行的MySQL中,这是mysql的一个重要 ...
- 流畅的python和cookbook学习笔记(五)
1.随机选择 python中生成随机数使用random模块. 1.从序列中随机挑选元素,使用random.choice() >>> import random >>> ...
- Java温故而知新(3)异常处理机制
异常处理是程序设计中一个非常重要的方面,也是程序设计的一大难点,从C开始,你也许已经知道如何用if...else...来控制异常了,也许是自发的,然而这种控制异常痛苦,同一个异常或者错误如果多个地方出 ...
- nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)解决方案
前提:已经配置好静态IP以防万一,先安装好iptables服务(不管你装没装,先执行,免得后面添乱)[root@localhost ~]# yum install iptables-services[ ...
- 【创客+】偷心锁屏创始人Jerry创业心得分享
偷心锁屏创始人Jerry创业心得分享 作者:Jerry权泉,偷心锁屏创始人 我创业的起因非常偶然.08年在东京早稻田大学读博士期间,每周六都去社区活动中心跟日本人志愿者日语对话练习日语.有一次练习结束 ...