【codeforces ZeptoLab Code Rush 2015】ABCD题解

A. King of Thieves

time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard output 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.

Input 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 ‘.’.

Output If the level is good, print the word “yes” (without the quotes), otherwise print the word “no” (without the quotes).

Sample test(s) input 16 ……*. output yes input 11 ..….. output no Note In the first sample test you may perform a sequence of jumps through platforms 2,5,8,11,14.

暴力枚举首相和公差,注意是五个点,跳四步。

;char s[1005];int a[1005];int main(){int n;cin>>n;scanf(“%s”,s);for (int i=0;i<n;i++)if (s[i]==’*’) a[i+1]=1;else a[i+1]=0;int f=0;for (int i=1;i+4<=n;i++){for (int j=1;i+4*j<=n;j++){int ok=1;for (int k=i;k<=i+4*j;k+=j)if (!a[k]) ok=0;if (ok) f=1;}if (f) break;}if (f) cout<<“yes”<<endl;else cout<<“no”<<endl;return 0;}

B. Om Nom and Dark Park time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard output 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.

Input 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.

Output Print the minimum number of street lights that we should add to the roads of the park to make Om Nom feel safe.

记忆像是倒在手心里的水,不论是摊平还是握紧,

【codeforces ZeptoLab Code Rush 2015】ABCD题解

相关文章:

你感兴趣的文章:

标签云: