CodeChef March Lunchtime 2018 div2
地址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的更多相关文章
- 【启发式搜索】Codechef March Cook-Off 2018. Maximum Tree Path
有点像计蒜之道里的 京东的物流路径 题目描述 给定一棵 N 个节点的树,每个节点有一个正整数权值.记节点 i 的权值为 Ai.考虑节点 u 和 v 之间的一条简单路径,记 dist(u, v) 为其长 ...
- Codechef March Cook-Off 2018. Maximum Tree Path
目录 题意 解析 AC_code @(Codechef March Cook-Off 2018. Maximum Tree Path) 题意 给你一颗\(n(1e5)\)个点有边权有点权的树,\(Mi ...
- Codechef October Challenge 2018 游记
Codechef October Challenge 2018 游记 CHSERVE - Chef and Serves 题目大意: 乒乓球比赛中,双方每累计得两分就会交换一次发球权. 不过,大厨和小 ...
- Codechef September Challenge 2018 游记
Codechef September Challenge 2018 游记 Magician versus Chef 题目大意: 有一排\(n(n\le10^5)\)个格子,一开始硬币在第\(x\)个格 ...
- 「Codechef April Lunchtime 2015」Palindromeness
「Codechef April Lunchtime 2015」Palindromeness 解题思路 : 考虑对于回文子串 \(s\) 贡献的定义: \[ value_s = [\ s[1,\lflo ...
- Codechef March Challenge 2014——The Street
The Street Problem Code: STREETTA https://www.codechef.com/problems/STREETTA Submit Tweet All submis ...
- codechef February Challenge 2018 简要题解
比赛链接:https://www.codechef.com/FEB18,题面和提交记录是公开的,这里就不再贴了 Chef And His Characters 模拟题 Chef And The Pat ...
- Codechef STMINCUT S-T Mincut (CodeChef May Challenge 2018) kruskal
原文链接http://www.cnblogs.com/zhouzhendong/p/9010945.html 题目传送门 - Codechef STMINCUT 题意 在一个有边权的无向图中,我们定义 ...
- codechef January Lunchtime 2017简要题解
题目地址https://www.codechef.com/LTIME44 Nothing in Common 签到题,随便写个求暴力交集就行了 Sealing up 完全背包算出得到长度≥x的最小花费 ...
随机推荐
- stylish——一键为网页换肤,改变字体大小,去除广告
今天给大家介绍的是一款非常好用的插件stylishstylish是一款可以为网站自定义主题的插件 可以在chrome的应用商店找到也可以通过网址访问https://userstyles.org/ 应用 ...
- python小练习2
结果 代码 鞋子价格=0 男孩价格=0 爆米花价格=0 计算完毕=0 for 鞋子动态价格 in range(0,20): if (计算完毕==1): break; #print("鞋子动态 ...
- 基于bootstrap的手机界面tab样式调整
这是调整后手机页面的样子(pc端的样式还是bootstrap原来的样式,没有改变的): html结构为: <div class="tab" role="tabpan ...
- leetcode-wildcard matching-ZZ
http://yucoding.blogspot.com/2013/02/leetcode-question-123-wildcard-matching.html 几个例子: (1) acbdeabd ...
- Python学习---线程锁/信号量/条件变量同步/线程池1221
线程锁 问题现象: 多线程情况下,CPU遇到阻塞会进行线程的切换,所以导致执行了tmp-=1的值还未赋值给num=tmp,另一个线程2又开始了tmp -=1,所以导致最后的值重复赋值给了num,所以出 ...
- redis外网连接的一些坑
前言 在使用阿里云和腾讯云的redis 可以减少很大的维护量.但是在我们的业务场景中遇到了一个情况,阿里和腾讯的redis均不支持外网访问.因此,正好帮人解决一个问题,就拿出来分享一下. 阿呆的故事 ...
- OID OAM WLS等Oracle 中间件日志位置汇总
WLS的log:/tip/IMP/bea/user_projects/domains/IDMDomain/servers/AdminServer/logsOID的log:/tip/IMP/bea/us ...
- 如何使git忽略某些文件或文件夹
为什么要忽略某些文件或文件夹的变化? git作为一款项目文件变更版本管理软件,其主要功能之一就是追踪项目文件夹内各种文件及文件夹的变更情况.但是,在日常使用中,并非项目文件夹下的所有文件及文件夹变更都 ...
- List 的 removeAll 方法的效率
List 的 removeAll 方法的效率低的原因: 要遍历source,对dest进行contain操作,而contain又要遍历dest进行equal比较. 解决办法:dest转为set,用se ...
- 51nod 1837 砝码称重【数学,规律】
题目链接:51nod 1837 砝码称重 小 Q 有 n 个砝码,它们的质量分别为 1 克. 2 克.……. n 克. 他给 i 克的砝码标上了编号 i (i = 1, 2, ..., n),但是编号 ...