CodeForces ZeptoLab Code Rush 2015
拖了好久的题解,想想还是补一下吧。
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的更多相关文章
- 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 ...
- Codeforces ZeptoLab Code Rush 2015 D.Om Nom and Necklace(kmp)
题目描述: 有一天,欧姆诺姆发现了一串长度为n的宝石串,上面有五颜六色的宝石.他决定摘取前面若干个宝石来做成一个漂亮的项链. 他对漂亮的项链是这样定义的,现在有一条项链S,当S=A+B+A+B+A+. ...
- 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 ...
- 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 ...
- 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 ...
- ZeptoLab Code Rush 2015
A 题意:给出一串由.*组成的字符串,如果有等间距的五个及五个以上的*存在,则输出yes 直接枚举就可以了 看题一定要仔细啊,做的时候看成必须有五个等间距的".*"才可以跳跃= = ...
- 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 ...
- 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 ...
- Codeforces Zepto Code Rush 2014 -C - Dungeons and Candies
这题给的一个教训:Codeforces没有超时这个概念.本来以为1000*(1000+1)/2*10*10要超时的.结果我想多了. 这题由于k层都可能有关系,所以建一个图,每两个点之间连边,边权为n* ...
随机推荐
- HDU4782 Beautiful Soup
成都赛里的一道坑爹码力题,突然间脑抽想做一下弥补一下当时的遗憾.当时没做出这道题一是因为当时只剩大概45分钟,对于这样的具有各种条件的题无从下手,二则是因为当时估算着已经有银牌了,所以就不挣扎了.但是 ...
- HDU 1715 大菲波数(JAVA, 简单题,大数)
题目 //BigInteger 和 BigDecimal 是在java.math包中已有的类,前者表示整数,后者表示浮点数 import java.io.*; import java.util.*; ...
- POJ 2014
#include <iostream> using namespace std; int main() { //freopen("acm.acm","r&qu ...
- 在WCF中使用消息队列
在一些大型的解决方案中,假设我们的服务没有办法一直在线,或者因为这样那样的原因宕机了,有没有什么办法让客户端的影响最小化呢?答案是可以通过消息队列的方式,哪怕服务是没有在线的,客户端依然可以继续操作. ...
- poj 1733(带权并查集+离散化)
题目链接:http://poj.org/problem?id=1733 思路:这题一看就想到要用并查集做了,不过一看数据这么大,感觉有点棘手,其实,我们仔细一想可以发现,我们需要记录的是出现过的节点到 ...
- 初学Ajax(一)
以下文字根据李炎恢——jQuery教程整理而成. Ajax全称为:“Asynchronous JavaScript and XML”(异步JavaScript和XML),它并不是JavaScript的 ...
- Linux - wxWidgets安装和编译HelloWorld
安装参考http://codelite.org/LiteEditor/WxWidgets30Binaries#toc2 源 /etc/apt/source.list deb http://repos. ...
- 浏览器的CSS各种hack,大汇总
对着IE久了也有感觉了,在win10出新浏览器以及中国的IE6+用户没有普及新的浏览器前IE还是个坑,所以hack这东西还是要掌握一点的.不废话直接贴图 记得之前在项目里面针对IE6的hack是这样写 ...
- 矩阵快速幂 POJ 3070 Fibonacci
题目传送门 /* 矩阵快速幂:求第n项的Fibonacci数,转置矩阵都给出,套个模板就可以了.效率很高啊 */ #include <cstdio> #include <algori ...
- 实现Web上的用户登录功能
关于如何实现web上的自动登录功能 文章来源http://coolshell.cn/articles/5353.html Web上的用户登录功能应该是最基本的功能了,可是在我看过一些站点的用户登录功能 ...