Codeforces Round #236 (Div. 2)

来源:互联网 发布:淘宝模特去哪里找 编辑:程序博客网 时间:2024/05/01 02:46
点击打开链接
A. Nuts
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

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.

Input

The first line contains four space-separated integers kabv (2 ≤ k ≤ 10001 ≤ 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.

Output

Print a single integer — the answer to the problem.

Sample test(s)
input
3 10 3 3
output
2
input
3 10 1 3
output
3
input
100 100 1 1000
output
1
Note

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.

给你a个nuts以及b个隔板和一些盒子,每个盒子都可以用一些隔板分成k部分,每一部分都能乘最多v个nuts,让你求最少需要几个盒子,就可以将所有的nuts全部乘下。
#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;}


点击打开链接
B. Sereja and Contests
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

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.

Input

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.

Output

Print in a single line two integers — the minimum and the maximum number of rounds that Sereja could have missed.

Sample test(s)
input
3 22 12 2
output
0 0
input
9 31 2 32 81 4 5
output
2 3
input
10 0
output
5 9
Note

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.


有n棵树排成一排,每棵树都有一定都高度,现在要求这n棵树满足这种情况ai + 1 - ai = k,你可以对每棵树的高度进行增加或减少,让你求最少需要对多少棵树进行修改就可以满足条件。
枚举每一棵树,找出最少操作。
#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;}


点击打开链接
C. Searching for Graph
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

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.

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.

Input

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 ≤ 24p ≥ 0) — the number of vertices in the graph and the interest value for the appropriate test.

It is guaranteed that the required graph exists.

Output

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 ≤ nai ≠ 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.

Sample test(s)
input
16 0
output
1 21 31 41 51 62 32 42 52 63 43 53 6
让你构造一个图,图中有n个顶点,2*n+p条边,而且它的任何一个有k个顶点的子图都要满足要求最多有2*k+p条边。
模拟样例过的,为什么这么做不是很明白。
#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;}


0 0
原创粉丝点击