codeforces GOOD BYE 2013

来源:互联网 发布:电力组态软件 编辑:程序博客网 时间:2024/06/02 10:13

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题:a根蜡烛,b根烧剩的蜡烛能变成一根新蜡烛,一根烧一小时,问能烧几小时。水过:

#include <stdio.h>#include <string.h>int a, b;int sum = 0, yu = 0;int main() {    scanf("%d%d", &a, &b);    while (a) {        sum += a;        yu += a;        a = yu / b;        yu %= b;    }    printf("%d\n", sum);    return 0;}

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
21 2
output
PRPLRP
input
40 2 0 2
output
RPRRPLLPLRRRP
B题:一个机器人要塞钱进钱袋,n个钱袋每个要塞ai个。不能连续塞两次,问怎么做,不要求最短。

思路:模拟,塞过只要往旁边走一下在走回来就可以了

#include <stdio.h>#include <string.h>const int N = 305;int n, a[N], v = -1;int main() {    scanf("%d", &n); int i;    for (i = 0; i < n; i ++) {        scanf("%d", &a[i]);        if (a[i] != 0)            v = i;    }    if (v == -1) {        printf("\n");        return 0;    }    for (i = 0; i <= v; i ++) {        if (a[i] == 0) {            if (i != v)                printf("R");        }        else {            while (a[i] --) {                if (a[i] == 0) {                    if (i != v)                        printf("PR");                    else                        printf("P");                }                else {                    if (i == 0) printf("PRL");                    else printf("PLR");                }            }        }    }    printf("\n");    return 0;}

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 i wants 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
35 1 1
output
5 1 2
input
11000000000
output
1000000000

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

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

代码:

#include <stdio.h>#include <string.h>#include <algorithm>using namespace std;const int N = 500005;int n, ans[N];struct P {int a, id;} p[N];int cmp(P a, P b) {return a.a < b.a;}int main() {scanf("%d", &n); int i, Min;for (i = 0; i < n; i++) {scanf("%d", &p[i].a);p[i].id = i;}sort(p, p + n, cmp);Min = p[0].a;for (i = 0; i < n; i++) {if (Min >= p[i].a) {ans[p[i].id] = Min++;}else {Min = p[i].a;ans[p[i].id] = Min++;}}for (i = 0; i < n - 1; i ++)printf("%d ", ans[i]);printf("%d\n", ans[n - 1]);return 0;}

D. New Year Letter
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Many countries have such a New Year or Christmas tradition as writing a letter to Santa including a wish list for presents. Vasya is an ordinary programmer boy. Like all ordinary boys, he is going to write the letter to Santa on the New Year Eve (we Russians actually expect Santa for the New Year, not for Christmas).

Vasya has come up with an algorithm he will follow while writing a letter. First he chooses two strings, s1 anf s2, consisting of uppercase English letters. Then the boy makes string sk, using a recurrent equation sn = sn - 2 + sn - 1, operation '+' means a concatenation (that is, the sequential record) of strings in the given order. Then Vasya writes down string sk on a piece of paper, puts it in the envelope and sends in to Santa.

Vasya is absolutely sure that Santa will bring him the best present if the resulting string sk has exactly x occurrences of substring AC (the short-cut reminds him оf accepted problems). Besides, Vasya decided that string s1 should have length n, and string s2 should have length m. Vasya hasn't decided anything else.

At the moment Vasya's got urgent New Year business, so he asks you to choose two strings for him, s1 and s2 in the required manner. Help Vasya.

Input

The first line contains four integers k, x, n, m (3 ≤ k ≤ 50; 0 ≤ x ≤ 109; 1 ≤ n, m ≤ 100).

Output

In the first line print string s1, consisting of n uppercase English letters. In the second line print string s2, consisting of m uppercase English letters. If there are multiple valid strings, print any of them.

If the required pair of strings doesn't exist, print "Happy new year!" without the quotes.

Sample test(s)
input
3 2 2 2
output
ACAC
input
3 3 2 2
output
Happy new year!
input
3 0 2 2
output
AAAA
input
4 3 2 1
output
Happy new year!
input
4 2 2 1
output
Happy new year!

D题:给定S1,长度n,S2长度M,求Sk能不能正好包含X个AC字串。

这题分类讨论,在暴力枚举,每种情况去进行斐波那契的递推。。。然后有漏洞,被Petr大神HACK掉了!! 后面过了再贴。。


总算是过了。。之前的想法还是too young了。。。

思路:暴力枚举,dp,枚举两个串的头尾字母和AC个数。每次判断进行dp递推。如果i - 2串为A且i - 1串头为C。dp[i]会多组成一个AC就+1。

代码:

#include <stdio.h>#include <string.h>const int N = 105;int k, x, n, m;__int64 f[N];char ans[N], s[N], e[N];void init() {scanf("%d%d%d%d", &k, &x, &n, &m);}void print(char s, char e, int len, int num) {memset(ans, 0, sizeof(ans));ans[0] = s; ans[len - 1] = e;int i, bo = (s == 'A' ? 0 : 1);for (i = 1; i < len - 1; i++)ans[i] = 'B';for (i = 0; i < num; i++) {ans[bo + 2 * i] = 'A';ans[bo + 2 * i + 1] = 'C';}printf("%s\n", ans);}bool ISOK(char s1, char e1, char s2, char e2, int xx, int yy) {s[1] = s1; e[1] = e1; s[2] = s2; e[2] = e2; f[1] = xx; f[2] = yy;for (int i = 3; i <= k; i ++) {s[i] = s[i - 2];e[i] = e[i - 1];f[i] = f[i - 1] + f[i - 2] + (e[i - 2] == 'A' && s[i - 1] == 'C');}if (f[k] == x)return true;return false;}bool judge() {for (char s1 = 'A'; s1 <= 'C'; s1++) {for (char e1 = 'A'; e1 <= 'C'; e1++) {if (n == 1 && s1 != e1) continue;for (char s2 = 'A'; s2 <= 'C'; s2++) {for (char e2 = 'A'; e2 <= 'C'; e2++) {if (m == 1 && s2 != e2) continue;int lx = n - (s1 != 'A') - (e1 != 'C');int ly = m - (s2 != 'A') - (e2 != 'C');lx /= 2; ly /= 2;for (int xx = 0; xx <= lx; xx++)for (int yy = 0; yy <= ly; yy++) {if (n == 2 && s1 == 'A' && e1 == 'C' && xx == 0) continue;if (m == 2 && s2 == 'A' && e2 == 'C' && yy == 0) continue;if (ISOK(s1, e1, s2, e2, xx, yy)) {print(s1, e1, n, xx);print(s2, e2, m, yy);return true;}}}}}}return false;}void solve() {if (!judge())printf("Happy new year!\n");}int main() {init();solve();return 0;}


1 0
原创粉丝点击