拖了好久的题解,想想还是补一下吧。

A. King of Thieves

直接枚举起点和5个点之间的间距,进行判断即可。

 #include <bits/stdc++.h>
using namespace std; char s[]; int main()
{
//freopen("in.txt", "r", stdin); int n;
bool ans = false;
scanf("%d%s", &n, s);
for(int q = ; q < n && !ans; q++) if(s[q] == '*')
for(int l = ; q + *l < n; l++)
{
int i;
for(i = ; i <= ; i++) if(s[q + i*l] == '.') break;
if(i > ) { ans = true; break; }
} printf("%s\n", ans ? "yes" : "no"); return ;
}

代码君

B. Om Nom and Dark Park (DFS)

给一个完全二叉树,增加若干条边的权值,使得从根到每个叶节点的权值之和相同。

直接从下往上维护这颗树,累加所增加的权值。

 #include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn = ( << ) + ;
LL a[maxn], num[maxn], ans, sum[maxn]; int n; void dfs(int o, int d)
{
if(d > n) return;
int lc = o*, rc = o*+;
dfs(lc, d+); dfs(rc, d+);
int m = max(sum[lc] + a[lc], sum[rc] + a[rc]);
ans += m - (sum[lc] + a[lc]);
ans += m - (sum[rc] + a[rc]);
sum[o] = m;
} int main()
{
//freopen("in.txt", "r", stdin); scanf("%d", &n);
for(int i = ; i < (<<(n+)); i++) scanf("%I64d", &a[i]);
dfs(, );
printf("%I64d\n", ans); return ;
}

代码君

C. Om Nom and Candies (部分贪心)

关于部分贪心可以看高逸涵的09年国家队论文。

这道题可以分成两种情况,用不同的办法来解决。

  • 有一种糖果的质量大于等于1000,那么我们枚举这种糖果的数量来求最大值。根据题目数据范围,循环的次数不会超过109 / 103 = 106.
  • 两种糖果的质量都小于1000,然后选一个性价比比较高的糖果。不妨设,那么我们说蓝色糖果的数量一定小于Wr。这样贪心的理由就是,如果有Wr个蓝色糖果,我们完全可以换成Wb个红色糖果。因为这种方案的糖果质量是一样的,但是总价值是HbWr < HrWb。所以我们可以枚举蓝色糖果的数量,来求最优解,并且循环的次数不超过1000.
 #include <bits/stdc++.h>
using namespace std;
typedef long long LL; int main()
{
LL c, hr, hb, wr, wb, ans = ;
scanf("%I64d%I64d%I64d%I64d%I64d", &c, &hr, &hb, &wr, &wb);
const int M = ;
if(wb > wr) { swap(hr, hb); swap(wr, wb); }
if(wr > M)
{
for(LL i = ; i * wr <= c; i++)
{
LL j = (c - i * wr) / wb;
ans = max(ans, (LL)i*hr + j*hb);
}
cout << ans << endl;
return ;
} if(hb*wr > hr*wb) { swap(hr, hb); swap(wr, wb); }
for(LL i = ; i <= wr && i * wb <= c; i++)
{
LL j = (c - i * wb) / wr;
ans = max(ans, i*hb+j*hr);
}
cout << ans << endl; return ;
}

代码君

D. Om Nom and Necklace (KMP)

题解转自:http://cyberzhg.github.io/blog/Online-Judge/CF526ABCDE/

这道题最终还是并没有看明白 r mod k是怎么来的,(⊙﹏⊙)b

 #include <cstdio>

 const int maxn =  + ;
char s[maxn];
int f[maxn], m, k; void getFail()
{
f[] = , f[] = ;
for(int i = ; i < m; i++)
{
int j = f[i];
while(j && s[i] != s[j]) j = f[j];
f[i+] = s[i] == s[j] ? j+ : ;
}
} int main()
{
//freopen("in.txt", "r", stdin);
scanf("%d%d%s", &m, &k, s);
getFail(); for(int i = ; i <= m; i++)
{
int l = i - f[i];
int R = i / l;
if(i % l == )
printf("%c", R / k >= R % k ? '' : '');
else
printf("%c", R / k > R % k ? '' : '');
}
printf("\n"); return ;
}

代码君

E. Transmitting Levels

在CF上发现了一种非常神的解法。首先预处理一下前缀和,然后用一个链表head[i]记录以第i个节点为结尾的,每段上的数之和不超过b的第一个数的下标。当这个跨度大于等于n的时候就说明找到答案了。

len就是记录分成了多少段。

我说的可能不太清楚,但是代码十分好懂,而且十分简练。感觉比官方题解要好很多。

但是我不太能证明它的正确性,为什么一旦找到i - head[i] >= n就输出答案了呢,也就是为什么后面不可能有最优解了呢?

 #include <cstdio>

 typedef long long LL;
const int maxn = + ;
LL a[maxn], sum[maxn], len[maxn], head[maxn]; int main()
{
//freopen("in.txt", "r", stdin); int n, q;
scanf("%d%d", &n, &q);
for(int i = ; i <= n; i++) { scanf("%I64d", &a[i]); a[i+n] = a[i]; }
for(int i = ; i <= n * ; i++) { sum[i] = sum[i-] + a[i]; head[i] = i; }
while(q--)
{
int b; scanf("%d", &b);
for(int i = n + , j = ; i <= n * ; i++)
{
while(sum[i] - sum[j] > b) j++;
head[i] = head[j];
len[i] = len[j] + ;
if(i - head[i] >= n) { printf("%I64d\n", len[i]); break; }
}
} return ;
}

代码君

CodeForces ZeptoLab Code Rush 2015的更多相关文章

  1. Codeforces - ZeptoLab Code Rush 2015 - D. Om Nom and Necklace:字符串

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

  2. Codeforces ZeptoLab Code Rush 2015 D.Om Nom and Necklace(kmp)

    题目描述: 有一天,欧姆诺姆发现了一串长度为n的宝石串,上面有五颜六色的宝石.他决定摘取前面若干个宝石来做成一个漂亮的项链. 他对漂亮的项链是这样定义的,现在有一条项链S,当S=A+B+A+B+A+. ...

  3. ZeptoLab Code Rush 2015 A. King of Thieves 暴力

    A. King of Thieves Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/526/pr ...

  4. ZeptoLab Code Rush 2015 C. Om Nom and Candies 暴力

    C. Om Nom and Candies Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/526 ...

  5. ZeptoLab Code Rush 2015 B. Om Nom and Dark Park DFS

    B. Om Nom and Dark Park Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/5 ...

  6. ZeptoLab Code Rush 2015

    A 题意:给出一串由.*组成的字符串,如果有等间距的五个及五个以上的*存在,则输出yes 直接枚举就可以了 看题一定要仔细啊,做的时候看成必须有五个等间距的".*"才可以跳跃= = ...

  7. ZeptoLab Code Rush 2015 C. Om Nom and Candies [ 数学 ]

    传送门 C. Om Nom and Candies time limit per test 1 second memory limit per test 256 megabytes input sta ...

  8. ZeptoLab Code Rush 2015 B. Om Nom and Dark Park

    Om Nom is the main character of a game "Cut the Rope". He is a bright little monster who l ...

  9. Codeforces Zepto Code Rush 2014 -C - Dungeons and Candies

    这题给的一个教训:Codeforces没有超时这个概念.本来以为1000*(1000+1)/2*10*10要超时的.结果我想多了. 这题由于k层都可能有关系,所以建一个图,每两个点之间连边,边权为n* ...

随机推荐

  1. hadoop开发环境-----eclipse

    1.eclipse下载 http://www.eclipse.org/downloads/packages/eclipse-ide-java-ee-developers/lunasr1 2.hadoo ...

  2. javascript和swf在网页中交互的一些总结

    Javascript和swf在网页中交互一般可有以下几种情况: 1.swf和这些调用的javascript在同域 2.swf和这些调用的javascript在不同域,比如加载远程的swf然后call别 ...

  3. HDU 1393 Weird Clock (英语,纪念题)

    这题简单,只要看懂题目就好,坑爹的是我的英语水平太差了,wa了n次,所以 仅此纪念 一下. //坑爹的英语题目,注意重点:move d times clockwise the current time ...

  4. 在运行jar时自动加载指定的jar包

    初学Java的人经常遇到的一个问题是:如果一个程序依赖某个文件夹下的一堆jar包,那么启动它的时候就需要在java -cp参数后面一个一个的加上jar包的名称,很不方便. 比如主程序类叫Main,在目 ...

  5. Mime Types

    Mime Types 1.http://www.freeformatter.com/mime-types-list.html 2.http://www.webmaster-toolkit.com/mi ...

  6. (转)白话经典算法系列之八 MoreWindows白话经典算法之七大排序总结篇

    在我的博客对冒泡排序,直接插入排序,直接选择排序,希尔排序,归并排序,快速排序和堆排序这七种常用的排序方法进行了详细的讲解,并做成了电子书以供大家下载.下载地址为:http://download.cs ...

  7. java控制反转与依赖注入

    1.简介 依赖注入和控制反转,目的是为了使类与类之间解耦合,提高系统的可扩展性和可维护性,下面通过一个例子来引入这一概念. 2.案例 1)一般情况下的类耦合 Main.java public clas ...

  8. Java集合框架(二)

    Set Set:无序,不可以重复元素. |--------HashSet:数据结构是哈希表. 线程是非同步的.保证元素唯一性的原理是:判断元素的hashCode值是否相同,如果相同,还会继续判断元素的 ...

  9. Tomcat SSL 设置

    1. 先用如下命令生成tomcat 证书 cls rem please set the env JAVA_HOME before run this bat file SET JAVA_HOME=C:\ ...

  10. ​浅谈Asp.net的sessionState

    见:http://my.oschina.net/kavensu/blog/330436