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* ...
随机推荐
- Mac OS 上设置 JAVA_HOME
Mac OS 上设置 JAVA_HOME 原文链接:http://han.guokai.blog.163.com/blog/static/136718271201301183938165/ 由于需要, ...
- CSLight研究院之学习笔记结合NGUI(一)
原地址:http://www.xuanyusong.com/archives/3088 这两天一直在研究CSLight,目前Unity热更新的方式有两种,一种是ulua这个网上的例子已经很多了.还有一 ...
- Jsp helloWorld
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEnco ...
- 关于com组件注册的问题
问题是这样的: 在调用摄像头的时候,用到com组件,我已经在工程中添加了com组件,但是运行的时候却报这样的错误. 解决方案:程序生成中,目标平台为Any CPU ,应该改为x86 具体原因不知道……
- Android核心分析之十四Android GWES之输入系统
Android输入系统 依照惯例,在研究Android输入系统之前给出输入系统的本质描述:从哲学的观点来看,输入系统就是解决从哪里来又将到哪里去问题.输入的本质上的工作就是收集用户输入信息 ...
- 阿里巴巴fastJson进行json数据解析
1.生成JsonObject:将Java bean转换成易于处理和传输的strig的key value形式. 2.解析JsonObject:将收到的字符串转换成JsonObejct这种对象形式,Jso ...
- iOS开发--提交github代码
将的SampleTable例子提交到github 具体步骤如下: a. 首先登陆github b. 创建新的reponsitory name, description c. 打开terminal, c ...
- onCreateOptionsMenu 和 onPrepareOptionsMenu 的区别
onCreateOptionsMenu 第一次创建时调用 onPrepareOptionsMenu 运行时每次点击菜单按钮时都会调用这个函数,可以动态改变菜单项 public boolean onPr ...
- 一个简单的以User权限启动外部应用程序(用NetUserAdd函数和USER_INFO_1结构体动态添加用户,然后用CreateProcessWithLogonW启动程序)
版权声明:本文为博主原创文章,未经博主允许不得转载. BOOL ExecuteAsUser(LPCWSTR lpszUserName, LPCWSTR lpszPassword, LPCWSTR lp ...
- 关于python中模块的import路径
前两天被一个同事问了一个python的问题: 为什么一个目录里的python文件引用不要另一个兄弟目录的python文件,但是这两个目录的父母录运行时是可以引用到了.当时感觉一直是模块和包的机制问题, ...