Codeforces Round #452 (Div. 2) A B C
Codeforces Round #452 (Div. 2)
A Splitting in Teams
题目链接:
http://codeforces.com/contest/899/problem/A
思路:
统计1和2出现的次数,尽量使2能够与1匹配尽可能多用。假设1再匹配完2之后还有剩余,则求出3个1可组成的方案
代码:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 200005;
ll num,cnt[3];
int main() {
ll n;
scanf("%I64d",&n);
for(ll i=0;i<n;++i) {
scanf("%I64d",&num);
cnt[num]++;
}
ll res=min(cnt[1],cnt[2]);
printf("%I64d\n",res+(cnt[1]-res)/3);
return 0;
}
B Proper Nutrition
题目链接:
http://codeforces.com/contest/899/problem/B
思路:
暴力枚举4种情况,24可以跨越三年,谨记...
代码:
#include <bits/stdc++.h>
using namespace std;
int b[4][36]={
{31,28,31,30,31,30,31,31,30,31,30,31,31,28,31,30,31,30,31,31,30,31,30,31,31,28,31,30,31,30,31,31,30,31,30,31},
{31,28,31,30,31,30,31,31,30,31,30,31,31,28,31,30,31,30,31,31,30,31,30,31,31,29,31,30,31,30,31,31,30,31,30,31},
{31,28,31,30,31,30,31,31,30,31,30,31,31,29,31,30,31,30,31,31,30,31,30,31,31,28,31,30,31,30,31,31,30,31,30,31},
{31,29,31,30,31,30,31,31,30,31,30,31,31,28,31,30,31,30,31,31,30,31,30,31,31,28,31,30,31,30,31,31,30,31,30,31}
};
int a[24];
int main() {
int n;
scanf("%d",&n);
for(int i=0;i<n;++i) scanf("%d",&a[i]);
int flag=0;
for(int i=0;i<4;++i) {
for(int j=0;j<36;++j) {
int l=j,r=0;
while(a[r]==b[i][l]) {
++r;
++l;
if(r==n) break;
}
if(r==n) {
flag=1;
break;
}
}
if(flag) break;
}
if(flag) printf("YES\n");
else printf("NO\n");
return 0;
}
C Phone Numbers
题目链接:
http://codeforces.com/contest/899/problem/C
思路:
我们尽可能让两组都尽可能趋近于sum/2。因为给出的n个数字是从1到n连续的,所以利用这个性质,假定其中较小的一组必定是连续的,标记为1。输出没有被标记的即可。特判一下n=2的情况。
代码:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int a[60005];
int main() {
ll n;
ll dis=0;
ll cnt=0;
scanf("%I64d",&n);
if(n==2) {
printf("1\n");
printf("1 1\n");
return 0;
}
memset(a,0,sizeof(a));
ll sum=(1+n)*n/2;
sum/=2;
for(ll i=1;i<=n;++i) {
if(sum%(i+i+1)==0) {
ll temp=sum/(i+i+1);
if(temp<=i) {
cnt=n-temp*2;
for(ll j=i-temp+1;j<=i+temp;++j) {
a[j]=1;
dis+=j;
}
break;
}
}
}
printf("%I64d\n",abs((1+n)*n/2-dis-dis));
printf("%I64d ",cnt);
int index=0;
for(int i=1;i<=n;++i) {
if(a[i]==0) {
if(index==0) printf("%d",i);
else printf(" %d",i);
++index;
}
}
printf("\n");
return 0;
}
Codeforces Round #452 (Div. 2) A B C的更多相关文章
- Codeforces Round #452 (Div. 2) 899E E. Segments Removal
题 OvO http://codeforces.com/contest/899/problem/E Codeforces Round #452 (Div. 2) - e 899E 解 用两个并查集(记 ...
- Codeforces Round #452 (Div. 2)-899A.Splitting in Teams 899B.Months and Years 899C.Dividing the numbers(规律题)
A. Splitting in Teams time limit per test 1 second memory limit per test 256 megabytes input standar ...
- Codeforces Round #452 (Div. 2) C. Dividing the numbers(水)
C. Dividing the numbers Petya has n integers: 1, 2, 3, ..., n. He wants to split these integers in t ...
- Codeforces Round #452 (Div. 2)
第一次打..(太弱(+99积分是几个意思 A 题意:一堆数,只有1和2,问最多凑出多少个3. 分情况即可 #include<cstdio> int main(){ int a=0,b=0, ...
- 【Codeforces Round #452 (Div. 2) A】 Splitting in Teams
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 贪心 1优先和2组队. 如果1没有了 就结束. 如果1还有多余的. 那么就自己3个3个组队 [代码] #include <bi ...
- 【Codeforces Round #452 (Div. 2) B】Months and Years
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 闰,平,平 平,闰,平 平,平,闰 平,平,平 4种情况都考虑到就好. 可能有重复的情况. 但是没关系啦. [代码] #includ ...
- 【Codeforces Round #452 (Div. 2) C】 Dividing the numbers
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] n为偶数. l = 1, r = n (l,r)放在一组 l++,r-- 新的l,r放在另外一组 直到l+1==r 这个时候,判断两 ...
- 【Codeforces Round #452 (Div. 2) D】Shovel Sale
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 让N乘2->a 然后看一下位数是多少. 假设有x位(x>=2) 则(0..(a%10-1) ) + (99..9)[x- ...
- Codeforces Round #366 (Div. 2) ABC
Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...
随机推荐
- 学习笔记02form
1.<form>为表单标签*如果要把数据提交到服务器,则需要将<input> <textarea> <select>等表单元素放到<from> ...
- Angular开发规范
目录 一. 前言 1.1. 规范目的 1.2. 局限性 二. 文件规范 2.1. 文件结构约定 2.2. 单一职责原则 ...
- Django学习day5——创建app
app应用与project项目的区别 一个app实现某个功能,比如博客.公共档案数据库或者简单的投票系统 一个project是配置文件和多个app的集合,这些app组合成整个站点 一个project可 ...
- Pandas常用基本功能
Series 和 DataFrame还未构建完成的朋友可以参考我的上一篇博文:https://www.cnblogs.com/zry-yt/p/11794941.html 当我们构建好了 Series ...
- 「BZOJ1576」[Usaco2009 Jan] 安全路经Travel------------------------P2934 [USACO09JAN]安全出行Safe Travel
原题地址 题目描述 Gremlins have infested the farm. These nasty, ugly fairy-like creatures thwart the cows as ...
- PCA降维的原理、方法、以及python实现。
PCA(主成分分析法) 1. PCA(最大化方差定义或者最小化投影误差定义)是一种无监督算法,也就是我们不需要标签也能对数据做降维,这就使得其应用范围更加广泛了.那么PCA的核心思想是什么呢? 例如D ...
- jQuery 触发事件 移动端和pc端的区别
jQuery 触发事件 移动端和pc端的区别 <pre>mousedown event.pageXmousemove event.pageXmouseup event.pageXtouch ...
- ES6学习笔记01 -- 暂时性死区 ( temporal dead zone )
参考文档: let 和 const 命令 - ECMAScript6入门 暂时性死区(temporal dead zone) 理解ES6中的TDZ(暂时性死区) ES6 中 let 暂时性死区详解 ...
- 【原创】使用批处理脚本自动生成并上传NuGet包
Hello 大家好,我是TANZAME,我们又见面了. NuGet 是什么这里就不再重复啰嗦,园子里一搜一大把.今天要跟大家分享的是,在日常开发过程中如何统一管理我们的包,如何通过批处理脚本生成包并自 ...
- 用例图浅谈以及OOA再到情景分析的面向对象电梯的设计(慕课东北大学)面向对象设计思维模式
上班初期还不太适应,平时学习进度也跟不上,节奏慢下来会有时间更新的了. Diagram 这边以学生课程报名系统为例 这就是一种简单的用例图 用例图可以给读者提供的信息非常丰富,但是缺点是都是概 ...