Codeforces Round #236 (Div. 2)
来源:互联网 发布:淘宝模特去哪里找 编辑:程序博客网 时间:2024/05/01 02:46
You have a nuts and lots of boxes. The boxes have a wonderful feature: if you put x (x ≥ 0) divisors (the spacial bars that can divide a box) to it, you get a box, divided into x + 1 sections.
You are minimalist. Therefore, on the one hand, you are against dividing some box into more than k sections. On the other hand, you are against putting more than v nuts into some section of the box. What is the minimum number of boxes you have to use if you want to put all the nuts in boxes, and you have b divisors?
Please note that you need to minimize the number of used boxes, not sections. You do not have to minimize the number of used divisors.
The first line contains four space-separated integers k, a, b, v (2 ≤ k ≤ 1000; 1 ≤ a, b, v ≤ 1000) — the maximum number of sections in the box, the number of nuts, the number of divisors and the capacity of each section of the box.
Print a single integer — the answer to the problem.
3 10 3 3
2
3 10 1 3
3
100 100 1 1000
1
In the first sample you can act like this:
- Put two divisors to the first box. Now the first box has three sections and we can put three nuts into each section. Overall, the first box will have nine nuts.
- Do not put any divisors into the second box. Thus, the second box has one section for the last nut.
In the end we've put all the ten nuts into boxes.
The second sample is different as we have exactly one divisor and we put it to the first box. The next two boxes will have one section each.
#include<stdio.h>int main(){ int k,a,b,v; while(scanf("%d%d%d%d",&k,&a,&b,&v)!=EOF) { int ans=0,box=0,kk=k-1; while(ans<a) { if(b>=kk) { ans+=v*k; b-=kk; box++; } else if(b>0) { ans+=(b+1)*v; b=0; box++; } else if(b==0) { ans+=v; box++; } } printf("%d\n",box); } return 0;}
Sereja is a coder and he likes to take part in Codesorfes rounds. However, Uzhland doesn't have good internet connection, so Sereja sometimes skips rounds.
Codesorfes has rounds of two types: Div1 (for advanced coders) and Div2 (for beginner coders). Two rounds, Div1 and Div2, can go simultaneously, (Div1 round cannot be held without Div2) in all other cases the rounds don't overlap in time. Each round has a unique identifier — a positive integer. The rounds are sequentially (without gaps) numbered with identifiers by the starting time of the round. The identifiers of rounds that are run simultaneously are different by one, also the identifier of the Div1 round is always greater.
Sereja is a beginner coder, so he can take part only in rounds of Div2 type. At the moment he is taking part in a Div2 round, its identifier equals to x. Sereja remembers very well that he has taken part in exactly k rounds before this round. Also, he remembers all identifiers of the rounds he has taken part in and all identifiers of the rounds that went simultaneously with them. Sereja doesn't remember anything about the rounds he missed.
Sereja is wondering: what minimum and what maximum number of Div2 rounds could he have missed? Help him find these two numbers.
The first line contains two integers: x (1 ≤ x ≤ 4000) — the round Sereja is taking part in today, and k (0 ≤ k < 4000) — the number of rounds he took part in.
Next k lines contain the descriptions of the rounds that Sereja took part in before. If Sereja took part in one of two simultaneous rounds, the corresponding line looks like: "1 num2 num1" (where num2 is the identifier of this Div2 round, num1 is the identifier of the Div1 round). It is guaranteed that num1 - num2 = 1. If Sereja took part in a usual Div2 round, then the corresponding line looks like: "2 num" (where num is the identifier of this Div2 round). It is guaranteed that the identifiers of all given rounds are less than x.
Print in a single line two integers — the minimum and the maximum number of rounds that Sereja could have missed.
3 22 12 2
0 0
9 31 2 32 81 4 5
2 3
10 0
5 9
In the second sample we have unused identifiers of rounds 1, 6, 7. The minimum number of rounds Sereja could have missed equals to 2. In this case, the round with the identifier 1 will be a usual Div2 round and the round with identifier 6 will be synchronous with the Div1 round.
The maximum number of rounds equals 3. In this case all unused identifiers belong to usual Div2 rounds.
#include<stdio.h>#include<string.h>#include<algorithm>#define M 1007using namespace std;char s[M];int a[M],b[M],c[M];struct sa{ char s; int a,b;}q[M];int cmp(sa a,sa b){ return a.a<b.a;}int main(){ int n,k; while(scanf("%d%d",&n,&k)!=EOF) { int count=0,minn=99999; for(int i=1;i<=n;i++) scanf("%d",&c[i]); for(int i=1;i<=n;i++) { count=0; for(int j=i-1,kk=1;j>=1;j--,kk++) { int ans=c[i]-k*kk; if(ans==c[j])continue; int cha=ans-c[j]; if(cha>0) { s[count]='-'; a[count]=j; b[count++]=cha; } else if(cha<0) { s[count]='+'; a[count]=j; b[count++]=-cha; } if(count>minn)break; } for(int j=i+1,kk=1;j<=n;j++,kk++) { if(count>minn)break; int ans=c[i]+kk*k; if(ans==c[j])continue; int cha=c[j]-ans; if(cha>0) { s[count]='-'; a[count]=j; b[count++]=cha; } else if(cha<0) { s[count]='+'; a[count]=j; b[count++]=-cha; } if(count>minn)break; } if(count<minn) { minn=count; for(int j=0;j<minn;j++) { q[j].s=s[j]; q[j].a=a[j]; q[j].b=b[j]; } } } sort(q,q+minn,cmp); printf("%d\n",minn); for(int i=0;i<minn;i++) printf("%c %d %d\n",q[i].s,q[i].a,q[i].b); } return 0;}
Let's call an undirected graph of n vertices p-interesting, if the following conditions fulfill:
- the graph contains exactly 2n + p edges;
- the graph doesn't contain self-loops and multiple edges;
- for any integer k (1 ≤ k ≤ n), any subgraph consisting of k vertices contains at most 2k + p edges.
A subgraph of a graph is some set of the graph vertices and some set of the graph edges. At that, the set of edges must meet the condition: both ends of each edge from the set must belong to the chosen set of vertices.
Your task is to find a p-interesting graph consisting of n vertices.
The first line contains a single integer t (1 ≤ t ≤ 5) — the number of tests in the input. Next t lines each contains two space-separated integers: n,p (5 ≤ n ≤ 24; p ≥ 0; ) — the number of vertices in the graph and the interest value for the appropriate test.
It is guaranteed that the required graph exists.
For each of the t tests print 2n + p lines containing the description of the edges of a p-interesting graph: the i-th line must contain two space-separated integers ai, bi (1 ≤ ai, bi ≤ n; ai ≠ bi) — two vertices, connected by an edge in the resulting graph. Consider the graph vertices numbered with integers from 1 to n.
Print the answers to the tests in the order the tests occur in the input. If there are multiple solutions, you can print any of them.
16 0
1 21 31 41 51 62 32 42 52 63 43 53 6
#include<stdio.h>int x[1007],y[1007];int main(){ int t; scanf("%d",&t); while(t--) { int n,p,k=0; scanf("%d%d",&n,&p); for(int i=1;i<=n;i++) for(int j=i+1;j<=n;j++) { x[k]=i; y[k++]=j; } for(int i=0;i<2*n+p;i++) printf("%d %d\n",x[i],y[i]); } return 0;}
- Codeforces Round #236 (Div. 2)
- Codeforces Round #236 (Div. 2)
- Codeforces Round #236 (Div. 2)
- Codeforces Round #236 (Div. 2) A. Nuts
- Codeforces Round #236 (Div. 2)B
- Codeforces Round #236 (Div. 2)A
- Codeforces round #236Div.2--A;B
- Codeforces Round #236 (Div. 2)__Upgrading Array
- Codeforces Round #236 (Div. 2) (全)
- Codeforces Round #236 (Div. 2) A. Nuts
- Codeforces Round #236 (Div. 2)------A,B
- Codeforces Round #236 (Div. 2)(强联通)
- codeforces round #236 div.2 A
- codeforces round #236 div.2 B
- codeforces round #236 div.2 C
- codeforces Round #236(DIV 2)A. Nuts
- Codeforces Round #236 (Div. 1)
- Codeforces Round #102 (Div. 2)
- 两种实现多线程的方法有什么区别
- 字符过滤
- 马航事件12天,在东北大西洋找到了?
- linux 下载的两个命令ftp和scp
- 安卓中COLOR的值分析
- Codeforces Round #236 (Div. 2)
- 水禅心的庭院,在暖暖的朝阳里,教清风识字,在意兴阑珊的
- gh0st_util
- Android平台https嗅探劫持漏洞
- 强大的GUAVA之Strings
- 【js与jquery】jquery中$.ajax()方法的使用
- ssh常见错误一(result 'null' not found)小结
- Adding Reversed Numbers
- 人生三句话