Codeforces ZeptoLab Code Rush 2015

2024-03-20 14:18

本文主要是介绍Codeforces ZeptoLab Code Rush 2015,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

Codeforces ZeptoLab Code Rush 2015


比赛链接:http://codeforces.com/contest/526/


A. King of Thieves
time limit per test:1 second
memory limit per test:256 megabytes

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 numberi1, he can make a sequence of jumps through the platformsi1 < i2 < ... < ik, ifi2 - 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 sequencei1, i2, ..., i5, consisting offive 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 ofn 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 platforms2, 5, 8, 11, 14.


题目大意:给个字符串,问能不能找到连续5个下标成等差数列的位置上字符都为' * '的情况


题目分析:数字小,暴力枚举公差,然后模拟


#include <cstdio>
#include <cstring>
char s[105];
int a[105];int main()
{int len;bool flag = false;scanf("%d %s", &len, s);int d = 1;while(d <= len / 4){for(int i = 0; i < len; i++){if(s[i] == '*' && s[i + d] == '*' && s[i + 2 * d] == '*' && s[i + 3 * d] == '*' && s[i + 4 * d] == '*'){flag = true;break;}}d ++;if(flag)break;}if(flag)printf("yes\n");elseprintf("no\n");
}   


B. Om Nom and Dark Park
time limit per test:1 second
memory limit per test:256 megabytes

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 depthn. More formally, the entrance to the park is located at the square1. The exits out of the park are located at squares2n, 2n + 1, ..., 2n + 1 - 1 and these exits lead straight to the Om Nom friends' houses. From each squarei (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 exactlyn 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 numbersa2, a3, ...a2n + 1 - 1 — the initial numbers of street lights on each road of the park. Hereai is the number of street lights on the road between squaresi and . All numbersai are positive integers, not exceeding100.

Output

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

Sample test(s)
Input
2
1 2 3 4 5 6
Output
5
Note

Picture for the sample test. Green color denotes the additional street lights.




题目大意:一颗满二叉树,每条路上有一个权值表示灯的个数,现在要从根到所有叶子的路径上灯个数总和相同,问至少需要添加多少灯


题目分析:若要相等,显然兄弟到父亲路径上的灯数要一样,因此直接从叶子向上模拟即可,将灯数不断累加给父亲一直到根,每次兄弟到父亲路径上的差值的和就是最少需要补充的灯数


#include <cstdio>
#include <algorithm>
using namespace std;
int n, a[5000];int main()
{int ans = 0;scanf("%d", &n);for(int i = 2; i <= (1 << (n + 1)) - 1; i++)scanf("%d", &a[i]);for(int i = (1 << (n + 1)) - 1; i >= 2; i -= 2){ans += abs(a[i] - a[i - 1]);a[i / 2] += max(a[i], a[i - 1]);}printf("%d\n", ans);
}




C. Om Nom and Candies
time limit per test:1 second
memory limit per test:256 megabytes

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 weighsWr grams and each blue candy weighsWb grams. Eating a single red candy gives Om NomHr joy units and eating a single blue candy gives Om NomHb 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 thanC grams 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.

Input

The single line contains five integers C, Hr, Hb, Wr, Wb (1 ≤ C, Hr, Hb, Wr, Wb ≤ 109).

Output

Print a single integer — the maximum number of joy units that Om Nom can get.

Sample test(s)
Input
10 3 5 2 3
Output
16
Note

In the sample test Om Nom can eat two candies of each type and thus get 16 joy units.


题目大意:红糖有wr克,每克能得到hr的幸福值,蓝糖有wb克,每克能得到hb的幸福值,现在问最多吃c克能得到的最大幸福值


题目分析:这样的数据量显然不能用背包做,采用部分贪心策略,及另lcm为wr和wb的最小公倍数,如果c % lcm == 0且c / lcm >= 2,则对于容量为w1 = c / lcm - 1(这里减1是因为保证结果尽可能的大,如果直接取c/lcm的话不能除尽的部分可能会有很多空余位置)的部分我们可以直接贪心,结果记为sum,sum =w1 * max(lcm / wb * hb,lcm / wr * hr),剩下的部分直接枚举,枚举的时候取min(c / wr,c / wb)作为上界,这样可以防止超时。不妨假设wr比wb大,若wr数值很大,则枚举的时候c / wr就很小,若wr很小,则c = c % lcm后c就很小,则此时c / wr还是很小,由此可得本题部分贪心+部分暴力的方法是可行的


#include <cstdio>
#include <cstring>
#include <algorithm>
#define ll long long
using namespace std; ll Gcd(ll a, ll b)
{return b ? Gcd(b, a % b) : a;  
}ll Lcm(ll a, ll b)
{return a * b / Gcd(a, b);
}
int main()
{ll c, h1, h2, w1, w2, ans = 0; //scanf("%lld %lld %lld %lld %lld", &c, &w1, &h1, &w2, &h2);scanf("%I64d %I64d %I64d %I64d %I64d", &c, &h1, &h2, &w1, &w2);ll lcm = Lcm(w1, w2);ll tmp = c / lcm;c = c % lcm;if(tmp){ tmp --; c += lcm; } ll sum = tmp * (max(lcm / w1 * h1, lcm / w2 * h2));if(w1 < w2){swap(w1, w2);swap(h1, h2);}for(int i = 0; i <= c / w1; i++)ans = max(ans, i * h1 + (c - i * w1) / w2 * h2);ans += sum;printf("%I64d\n", ans);//printf("%lld\n", ans);
}





D. Om Nom and Necklace
time limit per test
1 second
memory limit per test
256 megabytes

One day Om Nom found a thread with n beads of different colors. He decided to cut the first several beads from this thread to make a bead necklace and present it to his girlfriend Om Nelly.

Om Nom knows that his girlfriend loves beautiful patterns. That's why he wants the beads on the necklace to form aregular pattern. A sequence of beads S is regular if it can be represented asS = A + B + A + B + A + ... + A + B + A, whereA and B are some bead sequences, " + " is the concatenation of sequences, there are exactly2k + 1 summands in this sum, among which there arek + 1 "A" summands andk "B" summands that follow in alternating order. Om Nelly knows that her friend is an eager mathematician, so she doesn't mind ifA or B is an empty sequence.

Help Om Nom determine in which ways he can cut off the first several beads from the found thread (at least one; probably, all) so that they form aregular pattern. When Om Nom cuts off the beads, he doesn't change their order.

Input

The first line contains two integers n,k (1 ≤ n, k ≤ 1 000 000) — the number of beads on the thread that Om Nom found and numberk from the definition of the regular sequence above.

The second line contains the sequence of n lowercase Latin letters that represent the colors of the beads. Each color corresponds to a single letter.

Output

Print a string consisting of n zeroes and ones. Positioni (1 ≤ i ≤ n) must contain either number one if the firsti beads on the thread form a regular sequence, or a zero otherwise.

Sample test(s)
Input
7 2
bcabcab
Output
0000011
Input
21 2
ababaababaababaababaa
Output
000110000111111000011
Note

In the first sample test a regular sequence is both a sequence of the first 6 beads (we can takeA = "", B = "bca"), and a sequence of the first 7 beads (we can takeA = "b",B = "ca").

In the second sample test, for example, a sequence of the first 13 beads is regular, if we takeA = "aba",B = "ba".


题目大意:给一个长为n的字符串,对于其前缀子串,如果满足A+B+A+B+...+这样的形式,并且刚好有k+1个A和k个B,则对应位置值为1否则为0,注意A和B可能是空串


题目分析:非常纠结的一道题,首先想到的是枚举一个周期的串长,联想到kmp里的next数组的一个性质,即i - next[i]就表示长度为i的前缀串中的周期串的一个周期的串长,先求next数组,注意这里求的next数组和一般kmp里的next数组不太一样,因为这里对任意前缀串它的前后缀子串不能有重叠的部分,比如ababaa,如果在普通next数组里会是-1 0 0 1 2 3,而我们目标的next数组为-1 -1 0 1 2 0

s         a  b   a   b   a   a

i          0  1   2   3   4   5

next  -1  -1  0   1   2   0

len     1   2  2    2  2   5

next里第二个为-1是因为它对应的是当前位置,若是0的话则1-next[1] = 1显然周期串长为2(ab)

得到next数组后,我们要计算几个值,len表示周期串长,num表示周期,t表示周期不能被k整除的部分,可以发现若t==0,则肯定可以找到可行方案,因为整除的话,根据周期的可加性,例如k=2我们必然可以得到_A_A_这样的串,现在讨论t不等于0时,如果不是一个完整的周期串,t要加1,把周期去掉不能整除的部分再分成k份,若每份的个数小于t,则显然没有可行方案,反之存在可行方案



#include <cstdio>
#include <cstring>
int const MAX = 1e6 + 5;char s[MAX];  
int next[MAX];  
int n, k;void get_next()
{ int j = -1; next[0] = -1; for(int i = 1; i < n; i++){ while(j != -1 && s[j + 1] != s[i])j = next[j]; if(s[j + 1] == s[i] ) j++; next[i] = j; } 
}int main() 
{scanf("%d %d %s", &n, &k, s);get_next();for(int i = 0; i < n; i++) {int len = i - next[i];   int num = (i + 1) / len;   int t = num % k; if(t == 0)printf("1");else{if(len * num != i + 1) t ++;if((num - (num % k)) / k >= t) printf("1");else printf("0");}}printf("\n");
}

这篇关于Codeforces ZeptoLab Code Rush 2015的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/829728

相关文章

Codeforces Round #240 (Div. 2) E分治算法探究1

Codeforces Round #240 (Div. 2) E  http://codeforces.com/contest/415/problem/E 2^n个数,每次操作将其分成2^q份,对于每一份内部的数进行翻转(逆序),每次操作完后输出操作后新序列的逆序对数。 图一:  划分子问题。 图二: 分而治之,=>  合并 。 图三: 回溯:

Codeforces Round #261 (Div. 2)小记

A  XX注意最后输出满足条件,我也不知道为什么写的这么长。 #define X first#define Y secondvector<pair<int , int> > a ;int can(pair<int , int> c){return -1000 <= c.X && c.X <= 1000&& -1000 <= c.Y && c.Y <= 1000 ;}int m

Codeforces Beta Round #47 C凸包 (最终写法)

题意慢慢看。 typedef long long LL ;int cmp(double x){if(fabs(x) < 1e-8) return 0 ;return x > 0 ? 1 : -1 ;}struct point{double x , y ;point(){}point(double _x , double _y):x(_x) , y(_y){}point op

Codeforces Round #113 (Div. 2) B 判断多边形是否在凸包内

题目点击打开链接 凸多边形A, 多边形B, 判断B是否严格在A内。  注意AB有重点 。  将A,B上的点合在一起求凸包,如果凸包上的点是B的某个点,则B肯定不在A内。 或者说B上的某点在凸包的边上则也说明B不严格在A里面。 这个处理有个巧妙的方法,只需在求凸包的时候, <=  改成< 也就是说凸包一条边上的所有点都重复点都记录在凸包里面了。 另外不能去重点。 int

Codeforces 482B 线段树

求是否存在这样的n个数; m次操作,每次操作就是三个数 l ,r,val          a[l] & a[l+1] &......&a[r] = val 就是区间l---r上的与的值为val 。 也就是意味着区间[L , R] 每个数要执行 | val 操作  最后判断  a[l] & a[l+1] &......&a[r] 是否= val import ja

Debugging Lua Project created in Cocos Code IDE creates “Waiting for debugger to connect” in Win-7

转自 I Installed Cocos Code IDE and created a new Lua Project. When Debugging the Project(F11) the game window pops up and gives me the message waiting for debugger to connect and then freezes. Also a

LLVM入门2:如何基于自己的代码生成IR-LLVM IR code generation实例介绍

概述 本节将通过一个简单的例子来介绍如何生成llvm IR,以Kaleidoscope IR中的例子为例,我们基于LLVM接口构建一个简单的编译器,实现简单的语句解析并转化为LLVM IR,生成对应的LLVM IR部分,代码如下,文件名为toy.cpp,先给出代码,后面会详细介绍每一步分代码: #include "llvm/ADT/APFloat.h"#include "llvm/ADT/S

VS Code 调试go程序的相关配置说明

用 VS code 调试Go程序需要在.vscode/launch.json文件中增加如下配置:  // launch.json{// Use IntelliSense to learn about possible attributes.// Hover to view descriptions of existing attributes.// For more information,

Codeforces Round 971 (Div. 4) (A~G1)

A、B题太简单,不做解释 C 对于 x y 两个方向,每一个方向至少需要 x / k 向上取整的步数,取最大值。 由于 x 方向先移动,假如 x 方向需要的步数多于 y 方向的步数,那么最后 y 方向的那一步就不需要了,答案减 1 代码 #include <iostream>#include <algorithm>#include <vector>#include <string>

code: 400, msg: Required request body is missing 错误解决

引起这个错误的原因是,请求参数按照get方式给。 应该给json字符串才对 补充: 1. @RequestBody String resource 加@RequestBody必须给json字符串,否则会报错400,记如标题错误。 不加这个的进行请求的话,其实post和get就没有什么区别了。 2. List<String> indexCodes=(List<String>)json.