OUC_Summer Training_ DIV2_#13 723afternoon

A - Shaass and Oskols
Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u

Description

Shaass has decided to hunt some birds. There are n horizontal electricity wires aligned parallel to each other. Wires are numbered 1 to nfrom top to bottom. On each wire there are some oskols sitting next to each other. Oskol is the name of a delicious kind of birds in Shaass's territory. Supposed there are ai oskols sitting on the i-th wire.

 

 

Sometimes Shaass shots one of the birds and the bird dies (suppose that this bird sat at the i-th wire). Consequently all the birds on the i-th wire to the left of the dead bird get scared and jump up on the wire number i - 1, if there exists no upper wire they fly away. Also all the birds to the right of the dead bird jump down on wire number i + 1, if there exists no such wire they fly away.

Shaass has shot m birds. You're given the initial number of birds on each wire, tell him how many birds are sitting on each wire after the shots.

Input

The first line of the input contains an integer n(1 ≤ n ≤ 100). The next line contains a list of space-separated integers a1, a2, ..., an,(0 ≤ ai ≤ 100).

The third line contains an integer m(0 ≤ m ≤ 100). Each of the next m lines contains two integers xi and yi. The integers mean that for the i-th time Shaass shoot the yi-th (from left) bird on the xi-th wire, (1 ≤ xi ≤ n, 1 ≤ yi). It's guaranteed there will be at least yibirds on the xi-th wire at that moment.

Output

On the i-th line of the output print the number of birds on the i-th wire.

Sample Input

Input
5
10 10 10 10 10
5
2 5
3 13
2 12
1 13
4 6
Output
0
12
5
0
16
Input
3
2 4 1
1
2 2
Output
3
0
3
这个题就没有什么好说的啦,从头到尾模拟一下就好了。题意也特别好理解哦。
#include<stdio.h>
int main()
{
    int a[120];
    int n,i,j,x,y;
    scanf("%d",&n);
    for(i = 0;i < n;i++)
    {
        scanf("%d",&a[i]);
    }
    int t;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d%d",&x,&y);
        x = x -1 ;
        if(x > 0 && x < n-1)
        {
            a[x - 1] += y - 1;
            a[x + 1] += a[x] - y;
            a[x] = 0;
        }
        else if(x == 0)
        {
            a[1] += a[0] - y;
            a[0] = 0;
        }
        else if(x == n - 1)
        {
            a[n - 2] += y - 1;
            a[n - 1] = 0;
        }
    }
    for(i = 0;i < n;i++)
    {
        printf("%d\n",a[i]);
    }
    return 0;

}
View Code

B - Shaass and Bookshelf
Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u

Description

Shaass has n books. He wants to make a bookshelf for all his books. He wants the bookshelf's dimensions to be as small as possible. The thickness of the i-th book is ti and its pages' width is equal to wi. The thickness of each book is either 1 or 2. All books have the same page heights.

 

 

Shaass puts the books on the bookshelf in the following way. First he selects some of the books and put them vertically. Then he puts the rest of the books horizontally above the vertical books. The sum of the widths of the horizontal books must be no more than the total thickness of the vertical books. A sample arrangement of the books is depicted in the figure.

 

 

Help Shaass to find the minimum total thickness of the vertical books that we can achieve.

Input

The first line of the input contains an integer n(1 ≤ n ≤ 100). Each of the next n lines contains two integers ti and wi denoting the thickness and width of the i-th book correspondingly, (1 ≤ ti ≤ 2, 1 ≤ wi ≤ 100).

Output

On the only line of the output print the minimum total thickness of the vertical books that we can achieve.

Sample Input

Input
5
1 12
1 3
2 15
2 5
2 1
Output
5
Input
3
1 10
2 1
2 4
Output
3

这个题是用背包,但是我看不懂也不能完全理解。囧~
#include<stdio.h>
int main()
{
    int a[120];
    int n,i,j,x,y;
    scanf("%d",&n);
    for(i = 0;i < n;i++)
    {
        scanf("%d",&a[i]);
    }
    int t;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d%d",&x,&y);
        x = x -1 ;
        if(x > 0 && x < n-1)
        {
            a[x - 1] += y - 1;
            a[x + 1] += a[x] - y;
            a[x] = 0;
        }
        else if(x == 0)
        {
            a[1] += a[0] - y;
            a[0] = 0;
        }
        else if(x == n - 1)
        {
            a[n - 2] += y - 1;
            a[n - 1] = 0;
        }
    }
    for(i = 0;i < n;i++)
    {
        printf("%d\n",a[i]);
    }
    return 0;

}
View Code

 

 
posted @ 2013-07-26 09:17  lwy_kitty  阅读(273)  评论(0编辑  收藏  举报