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的最小花费 ...
随机推荐
- Android GridView设置行数
普通的做法是设置一个高度,然后里面能显示出来几行就是几行,如果里面的内容高度变了,就需要重新调整高度来适配. 观察了一下它的onMeasure @Override protected void onM ...
- 初学scrum及首次团队开发
一.初学scrum 1.什么是scrum Scrum在英语的意思是橄榄球里的争球.而在这里Scrum是一种迭代式增量软件开发过程,经常性的被用于敏捷软件开发.Scrum包括了一系列实践和预定义角色的过 ...
- SMBus Host Controller not enabled!
今天去官网下载最新的ubuntu ubuntukylin-16.10-desktop-amd64.iso,下载后vm 运行,安装后结果报了这个问题 之后google搜索得到答案: 1.复制 cp ...
- Less的guards and argument matching
less guards/argument matching: .setbackground(@number) when (@number>0){ .setbackground( @number ...
- SQL点点滴滴_常用函数
该文章转载自http://www.cnblogs.com/jiajiayuan/archive/2011/06/16/2082488.html 别人的总结,很详细. 以下所有例子均Studnet表为例 ...
- zimbra邮件服务器的搭建和迁移
背景: 公司最近由于服务器费用问题,需要将邮件服务器从亚马逊(新加坡)云服务器A迁移到阿里云(香港)云服务器B. 由于邮箱使用的是域名访问,但是没有进行备案,所以只能迁移到港澳台地区,才能正常使用. ...
- C++ 源代码到可执行代码的详细过程
编译,编译程序读取源程序(字符流),对之进行词法和语法的分析,将高级语言指令转换为功能等效的汇编代码,再由汇编程序转换为机器语言,并且按照操作系统对可执行文件格式的要求链接生成可执行程序. 源代码-- ...
- 【转载】Kali-linux安装之后的简单设置
1.更新软件源:修改sources.list文件:leafpad /etc/apt/sources.list然后选择添加以下适合自己较快的源(可自由选择,不一定要全部): #官方源deb h ...
- AngularJs学习笔记--I18n/L10n
原版地址:http://code.angularjs.org/1.0.2/docs/guide/i18n 一.I18n and L10n in AngularJS 1. 什么是I18n和L10n? 国 ...
- Oracle 查找带有CLOB字段的所有表
查找带有CLOB字段的以HEHE开头的所有表 select t.column_name ,DATA_TYPE,TABLE_NAMEfrom user_tab_columns twhere t.TABL ...