In this problem you will meet the simplified model of game King of Thieves.
In a new ZeptoLab game called "King of Thieves" your aim is to reach a chest with gold by controlling your character, avoiding traps and obstacles on your way.
An interesting feature of the game is that you can design your own levels that will be available to other players. Let's consider the following simple design of a level.
A dungeon consists of n segments located at a same vertical level, each segment is either a platform that character can stand on, or a pit with a trap that makes player lose if he falls into it. All segments have the same length, platforms on the scheme of the level are represented as '*' and pits are represented as '.'.
One of things that affects speedrun characteristics of the level is a possibility to perform a series of consecutive jumps of the same length. More formally, when the character is on the platform number i1, he can make a sequence of jumps through the platforms i1 < i2 < ... < ik, if i2 - i1 = i3 - i2 = ... = ik - ik - 1. Of course, all segments i1, i2, ... ik should be exactly the platforms, not pits.
Let's call a level to be good if you can perform a sequence of four jumps of the same length or in the other words there must be a sequence i1, i2, ..., i5, consisting of five platforms so that the intervals between consecutive platforms are of the same length. Given the scheme of the level, check if it is good.
The first line contains integer n (1 ≤ n ≤ 100) — the number of segments on the level.
Next line contains the scheme of the level represented as a string of n characters '*' and '.'.
If the level is good, print the word "yes" (without the quotes), otherwise print the word "no" (without the quotes).
16 .**.*..*.***.**.
yes
11 .*.*...*.*.
no
In the first sample test you may perform a sequence of jumps through platforms 2, 5, 8, 11, 14.
很简单的模拟题,不过昨晚超级脑残,一直被hack,状态不好的时候坚决不写题啦
AC代码:
#include <cstdio> #include <cstring> #include <algorithm> using namespace std; char s[1000005]; int main() { int n; while(scanf("%d", &n) != EOF) { scanf("%s", s); int ok = 0; for(int i = 0; i < n && !ok; i++) { for(int j = 1; j < n && !ok; j++) { int k; for(k = 0; k < 5; k++) { int pos = i + j * k; if(pos >= n || s[pos] != '*') break; } if(k == 5) ok = 1; } } if(ok == 1) puts("yes"); else puts("no"); } return 0; }
Om Nom is the main character of a game "Cut the Rope". He is a bright little monster who likes visiting friends living at the other side of the park. However the dark old parks can scare even somebody as fearless as Om Nom, so he asks you to help him.
The park consists of 2n + 1 - 1 squares connected by roads so that the scheme of the park is a full binary tree of depth n. More formally, the entrance to the park is located at the square 1. The exits out of the park are located at squares 2n, 2n + 1, ..., 2n + 1 - 1 and these exits lead straight to the Om Nom friends' houses. From each square i (2 ≤ i < 2n + 1) there is a road to the square . Thus, it is possible to go from the park entrance to each of the exits by walking along exactly n roads.
To light the path roads in the evening, the park keeper installed street lights along each road. The road that leads from square i to square has ai lights.Om Nom loves counting lights on the way to his friend. Om Nom is afraid of spiders who live in the park, so he doesn't like to walk along roads that are not enough lit. What he wants is that the way to any of his friends should have in total the same number of lights. That will make him feel safe.
He asked you to help him install additional lights. Determine what minimum number of lights it is needed to additionally place on the park roads so that a path from the entrance to any exit of the park contains the same number of street lights. You may add an arbitrary number of street lights to each of the roads.
The first line contains integer n (1 ≤ n ≤ 10) — the number of roads on the path from the entrance to any exit.
The next line contains 2n + 1 - 2 numbers a2, a3, ... a2n + 1 - 1 — the initial numbers of street lights on each road of the park. Here ai is the number of street lights on the road between squares i and . All numbers ai are positive integers, not exceeding 100.
Print the minimum number of street lights that we should add to the roads of the park to make Om Nom feel safe.
2 1 2 3 4 5 6
5
思路:我的想法是先从最下面一层开始压缩,逐层往上
AC代码:
#include <cstdio> #include <cstring> #include <algorithm> #include <cmath> #define LL long long using namespace std; int n; int a[10005]; int asum[10005]; int tmp[10005]; int ret; int main() { while(scanf("%d", &n) != EOF) { int len = (1 << (n + 1)) - 1; int sum = 0; memset(asum, 0, sizeof(asum)); for(int i = 2; i <= len; i++) { scanf("%d", &a[i]); for(int j = i; j > 1 ; j /= 2) { asum[i] += a[j]; } sum += a[i]; } //for(int i = 2; i <= len; i++) printf("%d ", a[i]); ret = -1; for(int i = 2; i <= len; i++) { ret = max(ret, asum[i]); } //printf("%d\n", ret); memset(tmp, 0, sizeof(tmp)); for(int i = 1 << n; i <= len; i++) { tmp[i] = ret - asum[i]; } int ans = 0; for(int i = n; i >= 1; i--) { for(int j = 1 << i; j <= (1 << i + 1) - 1; j += 2) { ans += abs(tmp[j] - tmp[j + 1]); tmp[j / 2] = min(tmp[j], tmp[j + 1]); } } ans += tmp[1]; printf("%d\n", ans); } return 0; }
A sweet little monster Om Nom loves candies very much. One day he found himself in a rather tricky situation that required him to think a bit in order to enjoy candies the most. Would you succeed with the same task if you were on his place?
One day, when he came to his friend Evan, Om Nom didn't find him at home but he found two bags with candies. The first was full of blue candies and the second bag was full of red candies. Om Nom knows that each red candy weighs Wr grams and each blue candy weighsWb grams. Eating a single red candy gives Om Nom Hr joy units and eating a single blue candy gives Om Nom Hb joy units.
Candies are the most important thing in the world, but on the other hand overeating is not good. Om Nom knows if he eats more than Cgrams of candies, he will get sick. Om Nom thinks that it isn't proper to leave candy leftovers, so he can only eat a whole candy. Om Nom is a great mathematician and he quickly determined how many candies of what type he should eat in order to get the maximum number of joy units. Can you repeat his achievement? You can assume that each bag contains more candies that Om Nom can eat.
The single line contains five integers C, Hr, Hb, Wr, Wb (1 ≤ C, Hr, Hb, Wr, Wb ≤ 109).
Print a single integer — the maximum number of joy units that Om Nom can get.
10 3 5 2 3
16
In the sample test Om Nom can eat two candies of each type and thus get 16 joy units.
很简单的贪心题,暴力都可以过,不过没注意会爆int,一直错,半夜真的不适合做题
AC代码:
#include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #include <cmath> #define LL long long using namespace std; const int maxn = 500000; int n, m; LL c, hr, hb, wr, wb; int main() { cin >> c >> hr >> hb >> wr >> wb; LL ans = 0; for(int k = 0; k < 2; k ++) { LL tmp = c / wr; for(int i = 0; i <= tmp && i <= maxn; i++) { ans = max(ans, (tmp - i) * hr + ((c - (tmp - i) * wr) / wb) * hb); } swap(hr, hb); swap(wr, wb); } cout << ans << endl; return 0; }