codeforces GOOD BYE 2013
来源:互联网 发布:电力组态软件 编辑:程序博客网 时间:2024/06/02 10:13
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.
The single line contains two integers, a and b (1 ≤ a ≤ 1000; 2 ≤ b ≤ 1000).
Print a single integer — the number of hours Vasily can light up the room for.
4 2
7
6 3
8
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;}
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.
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.
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.
21 2
PRPLRP
40 2 0 2
RPRRPLLPLRRRP
思路:模拟,塞过只要往旁边走一下在走回来就可以了
#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;}
思路:贪心,按要礼物数排序,维护一个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;}
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.
The first line contains four integers k, x, n, m (3 ≤ k ≤ 50; 0 ≤ x ≤ 109; 1 ≤ n, m ≤ 100).
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.
3 2 2 2
ACAC
3 3 2 2
Happy new year!
3 0 2 2
AAAA
4 3 2 1
Happy new year!
4 2 2 1
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;}
- CodeForces Good Bye 2013
- codeforces GOOD BYE 2013
- Codeforces Good Bye 2013
- Codeforces Good Bye 2013
- Codeforces Good Bye 2013 ABCDE
- Codeforces Good Bye 2014
- codeforces good bye 2014
- codeforces Good Bye 2014
- Codeforces Good Bye 2014
- Codeforces Good Bye 2015
- CodeForces Good Bye 2016
- Codeforces------Good Bye 2016
- codeforces Good Bye 2016
- codeforces Good Bye 2016
- Good Bye 2014(codeforces)
- [CODEFORCES]Good Bye 2014题解
- Codeforces Good Bye 2015 ABCDE
- codeforces Good Bye 2015 B
- ubuntu服务器源配置
- 《Effective C++》学习笔记条款31:将文件间的编译依存关系降至最低
- mono touch中自定义事件
- mysql sql语句大全
- android开发必备的 42 个链接地址
- codeforces GOOD BYE 2013
- SpringAOP模型图解笔记
- StaticLinkList 静态链表
- oracle 临时表空间的增删改查
- 十大必备学习网站
- java中enum字段需要持久化时的处理
- Hibernate优势
- android ndk 崩溃捕获(cocos2d-x 之android崩溃捕获)
- c#中如何跨线程调用windows窗体控件?