地址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. Canvas中的save方法和restore方法

    初学者也许会误认为canvas中save方法是用来保存绘图状态的图形,而restore方法是用来还原之前保存的绘图状态的图形,其实不然. save():保存当前的绘图状态. restore():恢复之 ...

  2. input框中如何添加搜索

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  3. OA电子表单设计-年假申请单-数据验证

    OA从年初上线到现在已经过去半年了,时光飞逝. 上月底,行政文员找到我,说最近有新来的部门文员填<年假申请单>时,有乱填的情况,让我想办法处理. 我一查还真是,这文员是个男的,同一天给同一 ...

  4. Apache服务器运维笔记(2)----使用apxs来进行编译安装 mod_txt 模块

    mod_txt是一个非常有趣的模块,它实现了文本的输出过滤器,它可以在指定类型的网页上,将你指定的txt文件显示在网页的头部和尾部. 在它的主页 http://apache.webthing.com/ ...

  5. c++开发ocx入门实践二

    原文:http://blog.csdn.net/yhhyhhyhhyhh/article/details/51374355         IDE:vs2010,c++,测试工具,vs自带的TstCo ...

  6. 【OBJC】数字转中文大写

    博客园都不知道怎么外链图片…… - (void)numToString:(double)num{ ; NSMutableString *szChMoney = [[NSMutableString al ...

  7. Element和vue框架报错提示

    上面报错提示Error in render function: "TypeError:Cannot read property '$options' of undefined" 就 ...

  8. ComboBox赋值ItemsSource数据源的时候会触发SelectionChanged改变事件的解决办法

    我用的方法是设置开关 bool flag = false;//默认开关关闭(全局变量) flag = false;在赋值数据源之前设置关闭box.ItemsSource = lstProperty;/ ...

  9. 【Leetcode】【Medium】3Sum Closest

    Given an array S of n integers, find three integers in S such that the sum is closest to a given num ...

  10. gulp 前端构建工具入门

    gulp 前端构建工具入门 标签(空格分隔): gulp 1. 安装gulp npm i -g gulp 2. 创建gulp项目 2.1 Hello world 使用npm init初始化项目文件夹. ...