Codeforces ZeptoLab Code Rush 2015

2023-11-12

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");
    else
        printf("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");
}

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Codeforces ZeptoLab Code Rush 2015 的相关文章

  • Codeforces Round #368 (Div. 2) A C

    大清早发现自己的rating涨了72分还是很高兴的 xff0c 毕竟之前都是在掉分 xff0c 还差9分才能到宝蓝啊 xff0c 果然还是小菜鸡 A Brain 39 s Photos 大水题 xff0c 要不是这个codeforces是外
  • Codeforces Round #210 (Div. 2)

    本不想写 xff0c 毕竟就打了一个小时 xff08 训练题变成个人赛了T T xff09 xff0c 但是第一次水题4分钟搞定 xff0c 手速一点没涨 xff0c 纯粹就是脑子快 A Levko and Table 题意 xff1a 输
  • Codeforces游玩攻略

    Codeforces游玩攻略 1 简介2 网址3 使用1 主界面2 社区3 比赛名字颜色比赛种类比赛流程关于Codeforces赛制 xff1a 如何读懂排行榜Rating 4 题解 最后鸣谢 1 简介 Codeforces是全球最著名的在
  • Codeforces Round #853 (Div. 2) C题

    CF1789C Serval and Toxel 39 s Arrays 学弟的思路 思路清晰 xff0c 代码简洁明了 xff0c 吊打目前80 以上题解 分析 记录每个数字在多少个数组中出现过 xff0c 即记录每个数字出现的次数 然后
  • C. Good String Codeforces Round #560 (Div. 3)

    C Good String time limit per test 1 second memory limit per test 256 megabytes input standard input output standard outp
  • Codeforces 1419B. Stairs 递归

    Codeforces 1419B Stairs 递归 原题链接https codeforces com problemset problem 1419 B 样例 输入 5 2 1 49 5 20 50 6 20 50 5 3 8 9 13
  • Codeforces Round #513 by Barcelona Bootcamp (rated, Div. 1 + Div. 2) (A B C)

    链接 xff1a http codeforces com contest 1060 Codeforces Round 513 A Phone Numbers xff08 水题 xff09 B Maximum Sum of Digits xf
  • Codeforces Contest #1553 A : Digit Sum 题解

    题目链接 Digit Sum 题面 将上面一大坨翻译一下 xff0c 就是 xff1a 定义函数的数字和 给出 求有多少个满足且 若模余 xff0c 则成立 一开始想是输出的下取整 xff0c 最后的结果 xff1a 没有考虑到的情况 xf
  • codeforces 1326 E.Bombs

    codeforces 1326 E Bombs 题意 xff1a 给定 1 n 1 n 1 n 的排列p q xff0c 将
  • Codeforces Round 870 (Div. 2)【A、B、C、D】

    文章目录 A Trust Nobody 暴力 B Lunatic Never Content 数学 C Dreaming of Freedom 数学 暴力 D Running Miles 前缀 后缀 传送门 A Trust Nobody 暴
  • Codeforces Round #588 (Div. 1)

    Contest Page 因为一些特殊的原因所以更得不是很及时 A sol 不难发现当某个人diss其他所有人的时候就一定要被删掉 维护一下每个人会diss多少个人 xff0c 当diss的人数等于剩余人数 1 的时候放队列里 xff0c
  • 1603A - Di-visible Confusion

    1603A Di visible Confusion 题目 一个长度为N的数组从a1 a2 an 如果在存在不能被整除则可以删除 剩下的数变为a1 a2 an 1 求是否能使得数组为空 题解 每个数都会因为前一个数被删除而前移 所以遍历所有
  • 1500*C. Tenzing and Balls (线性DP)

    解析 每次选择两个相同的数 删去他们以及他们之间的所有数 问最多可以删除多少 DP 对于某个位置 i 其前面有多个 j 使得 a i a j 所以使用 f i 来记录前 i 个数能够删除的最大值 include
  • Codeforces Round 744 (Div. 3)

    A Casimir s String Solitaire 一个A需要一个B一个C需要一个B 所以只要A和C的个数之和等于B即可 AC代码 include
  • codeforces Gym 101341 K Competitions

    Problem codeforces com gym 101341 problem K vjudge net contest 162325 problem K Meaning 有 n 场比赛 每一场有 开始时间 a 结束时间 b 价值 c
  • Daniel and Spring Cleaning【数位DP】【Codeforces 1245 F】

    Codeforces Round 597 Div 2 F 这道题化简一下就是让我们求有上下限的2进制数中有几对满足每一位的相 值不为1的对数 那么 首先看到这个1e9就会让人想到数位DP 然后接着就是如何去求的这样一个问题 我们不如将上下限
  • Codeforces Round #367 (Div. 2)【贪心、差分、DP、字典树、二维链表】

    Codeforces Round 367 Div 2 A Beru taxi 就是问 我们知道一个点 从其他点到它的最少花费的时间是多少 include
  • 1400*C. No Prime Differences(找规律&数学)

    解析 由于 1 不是质数 所以我们令每一行的数都相差 1 对于行间 分为 n m之中有存在偶数和都为奇数两种情况 如果n m存在偶数 假设m为偶数 如果都为奇数 则 include
  • 1600*B. Jumping Jack(数学&&找规律)

    解析 一直往右条 直到第一次超过 x 如果当前和目标点 p x为偶数 则 p x 2 的那一步向左跳 这样会少跳 p x 正好补在多跳的这一段 如果为奇数 则不能除2 则继续跳 直到距离为偶数即可 x和x答案一样 include
  • Codeforces Round #697 (Div. 3) C. Ball in Berland(1400)

    Codeforces 1475 C Ball in Berland 题目分析 这个题其实就是给你一堆坐标 让你找到合适的有多少对 思路分析 坐标的话 首先想到用 pair

随机推荐

  • 合并两个有序数组(go实现

    合并两个有序数组 go实现 题目描述 解题思路 代码示例 执行结果 更多 题目描述 给你两个按 非递减顺序 排列的整数数组 nums1 和 nums2 另有两个整数 m 和 n 分别表示 nums1 和 nums2 中的元素数目 请你 合并
  • 机器学习python实现,自我总结

    机器学习代码及套用 网上很多机器学习的资料 我看了很多 最后发现用的时候其实没有那么复杂 也不需要了解很多的数学知识 也庆幸自己没有在上机器学习的课时放弃 写篇文章来总结总结吧 本文使用python来套 导入机器学习模块 自己随便百度一下机
  • centos网页/phpmyadmin 打不开_苹果手机Safari打不开网页?按下一个键,马上就能用...

    Safari 苹果手机自带的一个浏览器 很多人都认为是个垃圾 甚至把它卸载 但其实 Safari是当时乔布斯最看重的一个苹果武器 如果真要好好利用起来 这个自带软件远远比你想象的厉害
  • 下载LAMBDA Group的代码

    LAMBDA Group 的文章在其主页有公布代码和数据集 具体在其 主页 gt 数据与代码 下面的 代码 栏列了文章 比如点开第一篇 AcMR 里面有个下载代码的链接 code 但点开会发现 无法链接到服务器 根据杨嘉祺的邮件回复 在网址
  • Google前工程经理王忻:如何准备软件工程师的面试

    2010 10 20 10 48 4639次阅读 来源 伯乐在线 职场博客 已有0条评论 发表评论 关键词 Google 软件工程师 面试 作者 人力资源 收藏这篇资讯 导读 原文作者王忻 Google前工程经理 2003年月加入Googl
  • 【华为OD机试真题2023B卷 JAVA&JS】人气最高的店铺

    华为OD2023 B卷 机试题库全覆盖 刷题指南点这里 人气最高的店铺 知识点贪心排序 时间限制 1s 空间限制 32MB 限定语言 不限 题目描述 某购物城有m个商铺 现决定举办一场活动选出人气最高店铺 活动共有n位市民参与 每位市民只能
  • 微信小程序Token登录验证

    上图是微信开发文档提供的图 最近开发一款小程序 看了许久的微信文档 这里来记录一下其中的登录与授权过程 总体流程 前端执行wx login 获取code传给后端 后端通过微信官方的登录凭证校验接口获取到session key与openid
  • 使用PHP语言实现ETH 及 token转账

    以太坊转账 废话不多说直接上代码 代码下载地址 https download csdn net download u012841825 11021920 github代码 用你们可爱的小手 点一下星星 https github com zc
  • Angular 模态框 入坑记

    今天用到了ui bootstrap中的modal 觉得用起来还不错 也比较简单 博主以前用个ngDialog做的模态框 虽然不知道对不对 但这个插件也还可以 这貌似是我目前为止用过最简单的功能了 所以博客内容也很简单 大家一看就能懂 因为博
  • Qt中布局管理使用总结

    目录 1 五大布局 1 1 QVBoxLayout垂直布局 1 2 QHBoxLayout水平布局 1 3 QGridLayout网格布局 1 4 QFormLayout表单布局 1 5 QStackedLayout分组布局 1 6 五大布
  • linux下多线程:经典生产者和消费者示例

    生产者和消费者典型案例 include
  • 使用db doctor批量更新库

    之前旧版本的封装库 在更新candence软件后 需要使用db doctor对其进行更新 但是一个一个更新太慢 搜了半天 没有找到如何批处理更新 直接硬钢 于是将放置封装库文件目录下任意类型文件全部设置 将原来选中的文件名和后缀替换为 点击
  • Mac远程Win桌面官方工具——Microsoft Remote Desktop for mac

    微软官方专门为Mac用户提供了一款类Windows mstsc的远程桌面工具 Microsoft Remote Desktop for mac 专门用于远程控制Windows桌面 但是 苹果Appstore中国区无法搜索到该软件 不知道什么
  • 简单几步升级Spring security4.x升级到5.x

    本次升级源自一次安全漏洞提醒 Spring Security 身份认证绕过漏洞 CVE 2022 22978 现将漏洞相关详情下发 如系统使用了受影响版本软件 请参照处置建议及时完成处理 风险名称 Spring Security 身份认证绕
  • oracle自动生成uuid的实现方法

    oracle自动生成uuid方法 1 创建一个表 1 create table t user id varchar2 200 name varchar2 200 2 生成uuid的语句 1 2 alter table t user modi
  • Android Studio出现ERROR: AdbHostServer.cpp:102: Unable to connect to adb daemon on port: 5037问题

    打开android studio自带模拟机出现问题 原因是adb exe因为被阻止不能启动 具体错误代码如下 Emulator emulator ERROR AdbHostServer cpp 102 Unable to connect t
  • 性能不输 x265!国产开源 AVS2 高清实时编码器 xAVS2

    2018 年 1 月 31 日 北京大学数字视频编解码技术国家工程实验室视频编码算法研究室 PKU VCL 开源了 AVS2 高清实时编码器 xAVS2 V1 0 AVS2 是我国新一代视频编码国家标准 和第一代 AVS 视频编码标准相比
  • jenkins添加网页链接方法

    代码 li 外网页测试链接 a href http www baidu com 百度 a li li 本地网页测试链接 a href http 192 168 0 236 8080 seed package index html 我的本地h
  • 高德地图实现点聚合功能的详细步骤加截取地图图片 (附源码)

    目录 介绍 准备工作 1 注册并登录高德地图开放平台 申请密钥 2 在Vue项目中安装高德地图的相关库 插件 一 点聚合 1 引入高德地图API font color purple initializeMap font color purp
  • 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 m