Good Bye 2013 总结

A. New Year Candles
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Vasily the Programmer loves romance, so this year he decided to illuminate his room with candles.

Vasily has a candles.When Vasily lights up a new candle, it first burns for an hour and then it goes out. Vasily is smart, so he can make bwent out candles into a new candle. As a result, this new candle can be used like any other new candle.

Now Vasily wonders: for how many hours can his candles light up the room if he acts optimally well? Help him find this number.

Input

The single line contains two integers, a and b (1 ≤ a ≤ 1000; 2 ≤ b ≤ 1000).

Output

Print a single integer — the number of hours Vasily can light up the room for.

Sample test(s)
input
4 2
output
7
input
6 3
output
8
Note

Consider the first sample. For the first four hours Vasily lights up new candles, then he uses four burned out candles to make two new ones and lights them up. When these candles go out (stop burning), Vasily can make another candle. Overall, Vasily can light up the room for 7 hours.

题意:a根蜡烛,b根烧剩的蜡烛能变成一根新蜡烛,一根烧一小时,问能烧几小时。水过;

<span style="font-size:14px;">#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
const int maxm=1e5+10;
int main()
{
    int a,b;
    while(scanf("%d%d",&a,&b)!=EOF)
    {
        int sum=a;
        int cnt=a;
        while(cnt>=b)
        {
            int x=cnt;
            sum+=(cnt/b);
            cnt=x%b+cnt/b;
        }
        printf("%d\n",sum);
    }
    return 0;
}</span>

B. New Year Present
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

The New Year is coming! That's why many people today are busy preparing New Year presents. Vasily the Programmer is no exception.

Vasily knows that the best present is (no, it's not a contest) money. He's put n empty wallets from left to right in a row and decided how much money to put in what wallet. Vasily decided to put ai coins to the i-th wallet from the left.

Vasily is a very busy man, so the money are sorted into the bags by his robot. Initially, the robot stands by the leftmost wallet in the row. The robot can follow instructions of three types: go to the wallet that is to the left of the current one (if such wallet exists), go to the wallet that is to the right of the current one (if such wallet exists), put a coin to the current wallet. Due to some technical malfunctions the robot cannot follow two "put a coin" instructions in a row.

Vasily doesn't want to wait for long, so he wants to write a program for the robot that contains at most 106 operations (not necessarily minimum in length) the robot can use to put coins into the wallets. Help him.

Input

The first line contains integer n (2 ≤ n ≤ 300) — the number of wallets. The next line contains n integers a1, a2, ..., an (0 ≤ ai ≤ 300).

It is guaranteed that at least one ai is positive.

Output

Print the sequence that consists of k (1 ≤ k ≤ 106) characters, each of them equals: "L", "R" or "P". Each character of the sequence is an instruction to the robot. Character "L" orders to move to the left, character "R" orders to move to the right, character "P" orders the robot to put a coin in the wallet. The robot is not allowed to go beyond the wallet line. In other words, you cannot give instructions "L" if the robot is at wallet 1, or "R" at wallet n.

As a result of the performed operations, the i-th wallet from the left must contain exactly ai coins. If there are multiple answers, you can print any of them.

Sample test(s)
input
2
1 2
output
PRPLRP
input
4
0 2 0 2
output
RPRRPLLPLRRRP
题意:B题:一个机器人要塞钱进钱袋,n个钱袋每个要塞ai个。不能连续塞两次,问怎么做,不要求最短。
<span style="font-size:14px;">#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
const int maxm=1e5+10;
int a[maxm];
int main()
{
    int n;
    while(scanf("%d",&n)!=EOF)
    {
        int ok=-1;
        for(int i=1; i<=n; i++)
        {
            scanf("%d",&a[i]);
            if(a[i])
            {
                ok=i;
            }
        }
        if(!ok)
        {
            printf("\n");
            continue;
        }
        else
        {
            for(int i=1; i<=n; i++)
            {
                if(!a[i])
                {
                        printf("R");
                }
                else
                {
                    while(a[i]--)
                    {
                        if(a[i]==0)
                        {
                            if(ok!=i)
                                printf("PR");
                            else
                                printf("P");
                        }
                        else
                        {
                            if(i==1)
                                printf("PRL");
                            else
                                printf("PLR");
                        }
                    }
                }
            }
            printf("\n");
        }
    }
    return 0;
}</span>

C. New Year Ratings Change
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

One very well-known internet resource site (let's call it X) has come up with a New Year adventure. Specifically, they decided to give ratings to all visitors.

There are n users on the site, for each user we know the rating value he wants to get as a New Year Present. We know that user iwants to get at least ai rating units as a present.

The X site is administered by very creative and thrifty people. On the one hand, they want to give distinct ratings and on the other hand, the total sum of the ratings in the present must be as small as possible.

Help site X cope with the challenging task of rating distribution. Find the optimal distribution.

Input

The first line contains integer n (1 ≤ n ≤ 3·105) — the number of users on the site. The next line contains integer sequencea1, a2, ..., an (1 ≤ ai ≤ 109).

Output

Print a sequence of integers b1, b2, ..., bn. Number bi means that user i gets bi of rating as a present. The printed sequence must meet the problem conditions.

If there are multiple optimal solutions, print any of them.

Sample test(s)
input
3
5 1 1
output
5 1 2
input
1
1000000000
output
1000000000

题意:n个人,每个人最少要ai个礼物,要求每个人给礼物不重复,问怎么分配。

解:贪心,按要礼物数排序,维护一个Min值代表当前最小的,每个人的礼物等于 max(Min, a[i]); 然后Min++表示不重复。

<span style="font-size:14px;">#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
const int maxm=1e6+10;
int ans[maxm];
struct node
{
    int id,a;
}t[maxm];
int cmp(node p,node q)
{
    return p.a<q.a;
}
int main()
{
    int n;
    while(scanf("%d",&n)!=EOF)
    {
        for(int i=0;i<n;i++)
        {
            scanf("%d",&t[i].a);
            t[i].id=i;
        }
        sort(t,t+n,cmp);
        int MIN=t[0].a;
        for(int i=0;i<n;i++)
        {
            if(MIN>=t[i].a)
            {
                ans[t[i].id]=MIN++;
            }
            else
            {
                MIN=t[i].a;
                ans[t[i].id]=MIN++;
            }
        }
        for(int i=0;i<n;i++)
        {
            if(i==0)
                printf("%d",ans[i]);
            else
                printf(" %d",ans[i]);
        }
        printf("\n");
    }
    return 0;
}</span>



你可能感兴趣的:(Good Bye 2013 总结)