地址https://www.codechef.com/LTIME58B?order=desc&sortBy=successful_submissions

简单做了一下,前三题比较水,第四题应该算是经典题

AChef and Friends

直接暴力枚举即可

#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int MAXN = , INF = 1e9 + ;
inline int read() {
char c = getchar(); int x = , f = ;
while(c < '' || c > '') {if(c == '-') f = -; c = getchar();}
while(c >= '' && c <= '') x = x * + c - '', c = getchar();
return x * f;
}
int N, ans = ;
char s[MAXN];
main() {
#ifdef WIN32
freopen("a.in", "r", stdin);
#endif
N = read();
for(int i = ; i <= N; i++) {
scanf("%s", s + );
int L = strlen(s + );
for(int j = ; j <= L - ; j++) {
if((s[j] == 'c' && s[j + ] == 'h')||
(s[j] == 'h' && s[j + ] == 'e')||
(s[j] == 'e' && s[j + ] == 'f'))
{ans++; break;}
}
}
printf("%d", ans);
}

A

BMagic Elements

维护一个所有元素的和,直接模拟即可

#include<cstdio>
#include<cstring>
#include<algorithm>
#define int long long
using namespace std;
const int MAXN = 1e6 + , INF = 1e9 + ;
inline int read() {
char c = getchar(); int x = , f = ;
while(c < '' || c > '') {if(c == '-') f = -; c = getchar();}
while(c >= '' && c <= '') x = x * + c - '', c = getchar();
return x * f;
}
int N, K, ans = ;
int a[MAXN];
main() {
#ifdef WIN32
freopen("a.in", "r", stdin);
#endif
int T = read();
while(T--) {
N = read(); K = read();
int sum = , ans = ;
for(int i = ; i <= N; i++) a[i] = read(), sum += a[i];
for(int i = ; i <= N; i++)
if(a[i] + K > sum - a[i])
ans++;
printf("%d\n", ans);
}
}

B

CThree Integers

把式子化成$2B = A +C$的形式,不难看出改B一定是最优的。

特判一下奇偶性即可

#include<cstdio>
#include<cstring>
#include<algorithm>
#define int long long
using namespace std;
const int MAXN = 1e6 + , INF = 1e9 + ;
inline int read() {
char c = getchar(); int x = , f = ;
while(c < '' || c > '') {if(c == '-') f = -; c = getchar();}
while(c >= '' && c <= '') x = x * + c - '', c = getchar();
return x * f;
}
main() {
#ifdef WIN32
freopen("a.in", "r", stdin);
#endif
int N = read();
while(N--) {
int A = read(), B = read(), C = read();
int ans = abs( * B - A - C);
if(ans & ) printf("%lld\n", ans / + );
else printf("%lld\n", ans / );
}
}

C

DPartitions

个人感觉是一道比较好的题

设所有元素的和为$sum$

不难发现,不论如何分,分成的段数一定是$sum$的因子

而且不论如何分,第一段一定是$1-x$(以$1$为起点)

这样我们遇到一个因子就枚举一边序列暴力分割就可以

这题TM居然卡常

#include<cstdio>
#include<cstring>
#include<algorithm>
#define int long long
using namespace std;
const int MAXN = 1e6 + , INF = 1e9 + ;
inline int read() {
char c = getchar(); int x = , f = ;
while(c < '' || c > '') {if(c == '-') f = -; c = getchar();}
while(c >= '' && c <= '') x = x * + c - '', c = getchar();
return x * f;
}
int a[MAXN];
char ans[MAXN];
main() {
#ifdef WIN32
freopen("a.in", "r", stdin);
#endif
int T = read();
while(T--) {
int N = read(), sum = ;
for(int i = ; i <= N; i++) a[i] = read(), sum += a[i];
for(int i = ; i <= N; i++) {
if(sum % i != ) {ans[i] = ''; continue;}
int cur = , num = ;
for(int j = ; j <= N; j++) {
cur += a[j];
if(cur == sum / i) cur = ;
else if(cur > sum / i) {ans[i] = ''; break;}
}
ans[i] = (cur == ? '' : '');
}
for(int i = ; i <= N; i++)
putchar(ans[i]);
puts("");
}
}

D

CodeChef March Lunchtime 2018 div2的更多相关文章

  1. 【启发式搜索】Codechef March Cook-Off 2018. Maximum Tree Path

    有点像计蒜之道里的 京东的物流路径 题目描述 给定一棵 N 个节点的树,每个节点有一个正整数权值.记节点 i 的权值为 Ai.考虑节点 u 和 v 之间的一条简单路径,记 dist(u, v) 为其长 ...

  2. Codechef March Cook-Off 2018. Maximum Tree Path

    目录 题意 解析 AC_code @(Codechef March Cook-Off 2018. Maximum Tree Path) 题意 给你一颗\(n(1e5)\)个点有边权有点权的树,\(Mi ...

  3. Codechef October Challenge 2018 游记

    Codechef October Challenge 2018 游记 CHSERVE - Chef and Serves 题目大意: 乒乓球比赛中,双方每累计得两分就会交换一次发球权. 不过,大厨和小 ...

  4. Codechef September Challenge 2018 游记

    Codechef September Challenge 2018 游记 Magician versus Chef 题目大意: 有一排\(n(n\le10^5)\)个格子,一开始硬币在第\(x\)个格 ...

  5. 「Codechef April Lunchtime 2015」Palindromeness

    「Codechef April Lunchtime 2015」Palindromeness 解题思路 : 考虑对于回文子串 \(s\) 贡献的定义: \[ value_s = [\ s[1,\lflo ...

  6. Codechef March Challenge 2014——The Street

    The Street Problem Code: STREETTA https://www.codechef.com/problems/STREETTA Submit Tweet All submis ...

  7. codechef February Challenge 2018 简要题解

    比赛链接:https://www.codechef.com/FEB18,题面和提交记录是公开的,这里就不再贴了 Chef And His Characters 模拟题 Chef And The Pat ...

  8. Codechef STMINCUT S-T Mincut (CodeChef May Challenge 2018) kruskal

    原文链接http://www.cnblogs.com/zhouzhendong/p/9010945.html 题目传送门 - Codechef STMINCUT 题意 在一个有边权的无向图中,我们定义 ...

  9. codechef January Lunchtime 2017简要题解

    题目地址https://www.codechef.com/LTIME44 Nothing in Common 签到题,随便写个求暴力交集就行了 Sealing up 完全背包算出得到长度≥x的最小花费 ...

随机推荐

  1. set(string str)变量传参为int的问题

    if (bo.getAnesthesiaMode() != null) { if (bo.getAnesthesiaMode() != null) { CodeMstrCoMpare codeMstr ...

  2. Linux下C语言操作MySQL数据库

    MySQL是Linux系统下广泛使用的开源免费数据库,是Linux应用程序数据存储的首选. Ubuntu下安装 […]

  3. JS获取屏幕分辨率以及当前对象大小等

    <script type="text/javascript"> function getInfo(){ var s = ""; s += " ...

  4. pt-duplicate-key-checker使用

    pt-duplicate-key-checker工具可以检测表中重复的索引,对于一些业务量很大的表,而且开发不规范的情况下有用.基本用法: 看一下我们的测试表: mysql> desc new_ ...

  5. 【转】关于色彩空间sRGB和Adobe RGB...

    以前对这个问题一直很困惑.... 下面采用问答形式.A:相机中的SRGB和ADOBE RGB有什么区别 ADOBE貌似颜色淡.什么时候有用处呢? B:不是这样的,ADOBE RGB的色域要比SRGB要 ...

  6. Grunt 使用(一)基础搭建

    jQuery在使用grunt,bootstrap在使用grunt,百度UEditor在使用grunt,你没有理由不学.不用!废话不多说,直接上干货. 1.安装node.js并检查node -v 和 n ...

  7. vagrant安装centos7

    1. 安装VirtualBox 去官网https://www.virtualbox.org/wiki/Downloads下载最新版的Virtualbox,然后双击安装,一直点击确认完成. 2. 安装V ...

  8. 通过CXF,开发rest协议接口

    1. 引入cxf的jar包 pom文件里面直接增加依赖 < dependency> <groupId > junit</ groupId> <artifact ...

  9. 【深入理解JAVA虚拟机】第4部分.程序编译与代码优化.2.运行期优化。这章提到的具体的优化技术,应该对以后做性能工作会有帮助。

    1.概述 Java程序最初是通过解释器(Interpreter)进行解释执行的,当虚拟机发现某个方法或代码块的运行特别频繁时,就会把这些代码认定为“热点代码”(Hot Spot Code). 为了提高 ...

  10. 如何给Docker hub用户上传头像

    我第一次使用Docker hub时,觉得很奇怪,这个网站上面没有允许用户上传头像的地方. 后来经过研究才发现,需要用在Docker hub上注册用户的同一个邮箱到Gravatar这个网站上再注册一个账 ...