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 ...
随机推荐
- poj 2017 Speed Limit
Speed Limit Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 17704 Accepted: 12435 Des ...
- Mybatis缓存(一)
1.什么是缓存 Mybatis提供缓存,用于减轻数据压力,提高数据库性能. 2.Mybatis缓存分类 Mybatis的缓存分为一级缓存和二级缓存. Mybatis的一级缓存 1.一级缓存的范围 1 ...
- Maven 配置Tomcat
1.Tomcat conf 下的tomcat-users.xml 增加 <role rolename="manager"/> <role rolename=&qu ...
- 网站SEO优化
网站的优化应该迎合搜索引擎,这样才能得到事半功倍的效果! 一.站内优化 1.做好HTML头标签 标题(title):标题是网页优化中相当有分量,一般网页title主要包含一些关键词.网站名称等.关键词 ...
- HttpContext.Current.Request.RawUrl是什么意思?
原始 URL 定义为 URL 中域信息之后的部分.在 URL 字符串 http://www.contoso.com/articles/recent.aspx 中,原始 URL 为/articles/r ...
- Hnoi2004 金属包裹
传送门 三维凸包模板题……只是听了听计算几何的课之后心血来潮想写的…… 我的做法很无脑是吧……暴力枚举三个点组成的三角形,然后枚举剩下的点,判断其余点是否都在这个三角形的同一侧,是的话则说明这个三角形 ...
- css手风琴
<style> .box{ width: 1000px; height: 450px; margin:0 auto; overflow: hidden;} .box div{ width: ...
- Android 快速切换到主线程更新UI的几种方法
此最近看了网上,在子线程更新UI的方法,说法很多,但都不是很全面.在此我争取做到总结的全面一些,希望以后对自己,对大家都有一些帮助. 方法一: view.post(Runnable action) 假 ...
- 常见的浏览器兼容性问题与解决方案——CSS篇
1.不同的浏览器的标签默认的外补丁和内补丁不同 问题症状:随便写几个标签,不加样式控制的情况下,各自的margin和padding差异较大. 碰到频率:100% 解决方案:初始化CSS的默认样式,*{ ...
- C++中long是什么类型
long long本质上还是整型,只不过是一种超长的整型. int型:32位整型,取值范围为-2^31 ~ (2^31 - 1) .long:在32位系统是32位整型,取值范围为-2^31 ~ (2^ ...