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* ...
随机推荐
- Appstore提交 被拒绝
Reasons 16.1: Apps that present excessively objectionable or crude content will be rejected 16.1 We ...
- iptables使用multiport 添加多个不连续端口 不指定
iptables使用multiport 添加多个不连续端口 碟舞飞扬 , 01:26 , Linux技术 , 评论(0) , 引用(0) , 阅读(12214) , Via 本站原创 大 | 中 ...
- 【译】 沙箱中的间谍 - 可行的 JavaScript 高速缓存区攻击
王龑 - MAY 27, 2015 原文连接 The Spy in the Sandbox – Practical Cache Attacks in Javascript 相关论文可在 https:/ ...
- IE8中能继续使用Expression的解决方案
在实际工作中,长的报表需要固定表头,比如DataGrid等控件. 过去在用IE8以前版本的时候,只需要在css中加上 position:relative ; top:expresion(this.of ...
- P==NP??
注:基础知识见下方 下面是关于P==NP ??? 一些讨论,挺好玩的. 1. 首先强调一下数学上还没有证明这个问题!但是我们看看其他角度来看这个问题. 其次,心理上来说,要是可以证明P==NP那么早 ...
- D&F学数据结构系列——二叉排序树
二叉排序树(Binary Sort Tree) 定义:对于树中的每个结点X,它的左子树中所有关键字值小于X的关键字值,而它的右子树中所有关键字值大于X的关键字值. 二叉查找树声明: #ifndef _ ...
- Spring MVC 教程,快速入门,深入分析(转)
原文地址:http://elf8848.iteye.com/blog/875830/
- 卷积相关公式的matlab代码
取半径=3 用matlab代码实现上式公式: length=3;for Ki = 1:length for Kj = 1:length for Kk = 1:length Ksigma(Ki,Kj,K ...
- WordPress主题制作教程2:导航菜单制作
实现自定义菜单,需要用到的函数是wp_nav_menu(); 在主题目录下的functions.php的 <?php ….. ?> 之间,添加以下菜单注册代码,这样你就可以在主题文件中使用 ...
- Intellij Idea 15 生成serialVersionUID的方法
默认情况下Intellij IDEA是关闭了继承了Serializable接口的类生成serialVersionUID的警告.如果需要ide提示生成serialVersionUID,那么需要做以下设置 ...