Codeforces Round #430 (Div. 2) A B C D
来源:互联网 发布:dt大数据 编辑:程序博客网 时间:2024/05/16 09:18
Kirill plays a new computer game. He came to the potion store where he can buy any potion. Each potion is characterized by two integers — amount of experience and cost. The efficiency of a potion is the ratio of the amount of experience to the cost. Efficiency may be a non-integer number.
For each two integer numbers a and b such that l ≤ a ≤ r and x ≤ b ≤ y there is a potion with experience a and cost b in the store (that is, there are (r - l + 1)·(y - x + 1) potions).
Kirill wants to buy a potion which has efficiency k. Will he be able to do this?
First string contains five integer numbers l, r, x, y, k (1 ≤ l ≤ r ≤ 107, 1 ≤ x ≤ y ≤ 107, 1 ≤ k ≤ 107).
Print "YES" without quotes if a potion with efficiency exactly k can be bought in the store and "NO" without quotes otherwise.
You can output each of the letters in any register.
1 10 1 10 1
YES
1 5 6 10 1
NO
A题,比赛的时候挂了。
不能直接根据数据的区间关系判断,因为整数是不连续的。
#include <cstdio>#include <iostream>#include <string.h>#include <string> #include <map>#include <queue>#include <vector>#include <set>#include <algorithm>#include <math.h>#include <cmath>#include <stack>#define mem0(a) memset(a,0,sizeof(a))#define meminf(a) memset(a,0x3f,sizeof(a))using namespace std;typedef long long ll;typedef long double ld;const int maxn=100005,inf=0x3f3f3f3f; const ll llinf=0x3f3f3f3f3f3f3f3f; const ld pi=acos(-1.0L); int main() {ll l,r,x,y,k,i;cin >> l >> r >> x >> y >> k;for (i=x;i<=y;i++) {if (i*k>=l&&i*k<=r) {cout << "YES";return 0;}}cout << "NO";return 0;}
Gleb ordered pizza home. When the courier delivered the pizza, he was very upset, because several pieces of sausage lay on the crust, and he does not really like the crust.
The pizza is a circle of radius r and center at the origin. Pizza consists of the main part — circle of radius r - d with center at the origin, and crust around the main part of the width d. Pieces of sausage are also circles. The radius of the i -th piece of the sausage is ri, and the center is given as a pair (xi, yi).
Gleb asks you to help determine the number of pieces of sausage caught on the crust. A piece of sausage got on the crust, if it completely lies on the crust.
First string contains two integer numbers r and d (0 ≤ d < r ≤ 500) — the radius of pizza and the width of crust.
Next line contains one integer number n — the number of pieces of sausage (1 ≤ n ≤ 105).
Each of next n lines contains three integer numbers xi, yi and ri ( - 500 ≤ xi, yi ≤ 500, 0 ≤ ri ≤ 500), where xi and yi are coordinates of the center of i-th peace of sausage, ri — radius of i-th peace of sausage.
Output the number of pieces of sausage that lay on the crust.
8 477 8 1-7 3 20 2 10 -2 2-3 -3 10 6 25 3 1
2
10 840 0 90 0 101 0 11 0 2
0
Below is a picture explaining the first example. Circles of green color denote pieces of sausage lying on the crust.
水。
#include <cstdio>#include <iostream>#include <string.h>#include <string> #include <map>#include <queue>#include <vector>#include <set>#include <algorithm>#include <math.h>#include <cmath>#include <stack>#define mem0(a) memset(a,0,sizeof(a))#define meminf(a) memset(a,0x3f,sizeof(a))using namespace std;typedef long long ll;typedef long double ld;const int maxn=105,inf=0x3f3f3f3f; const ll llinf=0x3f3f3f3f3f3f3f3f; const ld pi=acos(-1.0L); int sqr(int x) {return x*x;}int main() {int d,R,n,x,y,r,i,ans=0;cin >> R >> d >> n;int p=d;d=R;R=R-p;for (i=1;i<=n;i++) {scanf("%d%d%d",&x,&y,&r);if (sqr(x)+sqr(y)>=sqr(R+r)&&sqr(x)+sqr(y)<=sqr(d-r)) ans++;}printf("%d\n",ans);return 0;}
一棵树,每个点有一个点权。设1号点为根,问对于每一个点,从树上单独删去一个点的点权或者不删,从根到该点的gcd最大是多少。
观察发现,一共只有两种情况:
1.把根删去,每个点的答案就是从根到该点路径上除去根所有点的gcd,可以dfs得到。不删的结果肯定没有删根更优。
2.删除根之外另一个点。
由于求所有点的gcd必须经过根,所有答案只可能是根的一个因子。这时只要再次dfs,看根到每个点的路径上,这些因子是否至少出现了树的深度减1这么多次,如果这样,说明删掉路径上一个点之后这个因子可能是答案。
#include <cstdio>#include <iostream>#include <string.h>#include <string> #include <map>#include <queue>#include <vector>#include <set>#include <algorithm>#include <math.h>#include <cmath>#include <stack>#define mem0(a) memset(a,0,sizeof(a))#define meminf(a) memset(a,0x3f,sizeof(a))using namespace std;typedef long long ll;typedef long double ld;const int maxn=200005,inf=0x3f3f3f3f; const ll llinf=0x3f3f3f3f3f3f3f3f; const ld pi=acos(-1.0L); int num;int head[maxn],ans[maxn],a[maxn],b[maxn],t[maxn];bool visit[maxn];struct Edge {int from,to,pre;};Edge edge[maxn*2];void addedge(int from,int to) {edge[num]=(Edge){from,to,head[from]};head[from]=num++;edge[num]=(Edge){to,from,head[to]};head[to]=num++;}int gcd(int x,int y) {int z;if (x<y) swap(x,y);while (y) {z=y;y=x%y;x=z;}return x;}void dfs(int now,int fa) {visit[now]=1;if (fa==1||fa==0) ans[now]=a[now]; else if (now!=1) ans[now]=gcd(ans[fa],a[now]);for (int i=head[now];i!=-1;i=edge[i].pre) {int to=edge[i].to;if (!visit[to]) dfs(to,now);}}void dfs2(int now,int depth) {visit[now]=1;for (int i=1;i<=num;i++) {if (a[now]%b[i]==0) t[i]++;if (t[i]>=depth) ans[now]=max(ans[now],b[i]);}for (int i=head[now];i!=-1;i=edge[i].pre) {int to=edge[i].to;if (!visit[to]) dfs2(to,depth+1);}for (int i=1;i<=num;i++) {if (a[now]%b[i]==0) t[i]--;}}int main() {int n,i,x,y;num=0;memset(head,-1,sizeof(head));scanf("%d",&n);for (i=1;i<=n;i++) {scanf("%d",&a[i]);}for (i=1;i<n;i++) {scanf("%d%d",&x,&y);addedge(x,y);}mem0(visit);dfs(1,0);num=0;for (i=1;i<=sqrt(a[1]);i++) {if (a[1]%i==0) {b[++num]=i;if ((a[1]/i)*(a[1]/i)!=a[1]) b[++num]=a[1]/i;}}sort(b+1,b+num+1);mem0(visit);visit[1]=1;mem0(t);for (i=head[1];i!=-1;i=edge[i].pre) {if (!visit[edge[i].to]) {dfs2(edge[i].to,0);}}for (i=1;i<=n;i++) printf("%d ",ans[i]);return 0;}
Today at the lesson Vitya learned a very interesting function — mex. Mex of a sequence of numbers is the minimum non-negative number that is not present in the sequence as element. For example, mex([4, 33, 0, 1, 1, 5]) = 2 and mex([1, 2, 3]) = 0.
Vitya quickly understood all tasks of the teacher, but can you do the same?
You are given an array consisting of n non-negative integers, and m queries. Each query is characterized by one number x and consists of the following consecutive steps:
- Perform the bitwise addition operation modulo 2 (xor) of each array element with the number x.
- Find mex of the resulting array.
Note that after each query the array changes.
First line contains two integer numbers n and m (1 ≤ n, m ≤ 3·105) — number of elements in array and number of queries.
Next line contains n integer numbers ai (0 ≤ ai ≤ 3·105) — elements of then array.
Each of next m lines contains query — one integer number x (0 ≤ x ≤ 3·105).
For each query print the answer on a separate line.
2 21 313
10
4 30 1 5 6124
200
5 40 1 5 6 71145
2202
一个序列,每次把所有数异或一个数,保留结果,求最小的非负的序列中没有出现的数字。
这题需要利用异或的一个性质:(a^b)^c=a^(b^c)。
这样,每次查询我们可以认为是原序列异或上之后所有数字的异或和。
题目需要求最小的没有出现的数字,有点不好求。不过,这题中每个数字的范围并不是很大,不超过2^20=524288.
既然是没有出现,每次的序列固定,我们可以反其道而行之,把所有没有出现的数字统计出来,然后只需要求这些数中选择一个和当前要异或的数字异或运算的最小值。
求这个值,是字典树的典型应用。详见:POJ 3764 The Xor-longest length
建树的时候需要注意,虽然数字最大只有300000,但是需要把2^20以下的数字全部考虑进去,因为字典树是按照深度建立的,只有这样才能使得所有二进制为20位的未出现数字全部考虑完全。
#include <cstdio>#include <iostream>#include <string.h>#include <string> #include <map>#include <queue>#include <vector>#include <set>#include <algorithm>#include <math.h>#include <cmath>#include <stack>#define mem0(a) memset(a,0,sizeof(a))#define meminf(a) memset(a,0x3f,sizeof(a))using namespace std;typedef long long ll;typedef long double ld;const int maxn=300005,inf=0x3f3f3f3f; const ll llinf=0x3f3f3f3f3f3f3f3f; const ld pi=acos(-1.0L); bool f[524288];int num;struct Tree{int l,r;};Tree tree[maxn*20];void insert(int now,int val,int depth) {if (depth==21) return;if ((val>>(20-depth))%2==1) {if (tree[now].l==-1) {tree[now].l=++num;tree[num].l=tree[num].r=-1;}insert(tree[now].l,val,depth+1);} else {if (tree[now].r==-1) {tree[now].r=++num;tree[num].l=tree[num].r=-1;}insert(tree[now].r,val,depth+1);}}int findxor(int now,int val,int depth) {if (depth==21) return 0;if ((val>>(20-depth))%2==0) {if (tree[now].r!=-1) return findxor(tree[now].r,val,depth+1);else return findxor(tree[now].l,val,depth+1)+(1<<(20-depth));} else {if (tree[now].l!=-1) return findxor(tree[now].l,val,depth+1);else return findxor(tree[now].r,val,depth+1)+(1<<(20-depth));}}int main() {int n,m,i,t=0,x,ans;scanf("%d%d",&n,&m);num=0;tree[0].l=tree[0].r=-1;mem0(f);for (i=1;i<=n;i++) {scanf("%d",&x);f[x]=1;}for (i=0;i<=524288;i++) {if (!f[i]) insert(0,i,0);}for (i=1;i<=m;i++) {scanf("%d",&x);t=t^x;ans=findxor(0,t,0);printf("%d\n",ans);}return 0;}
- Codeforces Round #430 (Div. 2) A B C D
- Codeforces Round #179 (Div. 2)A、B、C、D
- Codeforces Round #186 (Div. 2)A、B、C、D、E
- Codeforces Round #202 (Div. 2) (A、B、C、D)
- Codeforces Round #211 (Div. 2)(A,B,C,D)
- Codeforces Round #220 (Div. 2)(A,B,C,D)
- Codeforces Round #231 (Div. 2)A, B, C, D
- Codeforces Round #258 (Div. 2)-(A,B,C,D,E)
- Codeforces Round #246 (Div. 2) A,B,C,D
- Codeforces Round #261 (Div. 2) A,B,C,D,E
- Codeforces Round #259 (Div. 2) A/B/C/D
- Codeforces Round #257 (Div. 2) A/B/C/D
- Codeforces Round #256 (Div. 2) A/B/C/D
- Codeforces Round #262 (Div. 2)-A,B,C,D
- Codeforces Round #263 (Div. 2) A,B,C,D,E
- Codeforces Round #264 (Div. 2) A,B,C,D,E
- Codeforces Round #276 (Div. 2) A B C D
- Codeforces Round #277 (Div. 2) A,B,C,D,E
- 年终总结
- wingIDE右侧文件列表移动到左侧
- 排序:插入排序
- 移动端图片上传裁切(版权归秒为所有,仅为搬运)
- hdu6105(想法题)
- Codeforces Round #430 (Div. 2) A B C D
- 算法导论——关于快速排序的实现(c语言实现)
- 如何给变量取个简短且无歧义的名字
- python简介
- 存储过程调试信息的输出
- bzoj 2733: [HNOI2012]永无乡(线段树启发式合并)
- 洛谷P1282 多米诺骨牌
- 改试卷
- 海量IP地址排序统计出现次数最多的K个地址