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的更多相关文章

  1. Codeforces Round #452 (Div. 2) 899E E. Segments Removal

    题 OvO http://codeforces.com/contest/899/problem/E Codeforces Round #452 (Div. 2) - e 899E 解 用两个并查集(记 ...

  2. 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 ...

  3. 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 ...

  4. Codeforces Round #452 (Div. 2)

    第一次打..(太弱(+99积分是几个意思 A 题意:一堆数,只有1和2,问最多凑出多少个3. 分情况即可 #include<cstdio> int main(){ int a=0,b=0, ...

  5. 【Codeforces Round #452 (Div. 2) A】 Splitting in Teams

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 贪心 1优先和2组队. 如果1没有了 就结束. 如果1还有多余的. 那么就自己3个3个组队 [代码] #include <bi ...

  6. 【Codeforces Round #452 (Div. 2) B】Months and Years

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 闰,平,平 平,闰,平 平,平,闰 平,平,平 4种情况都考虑到就好. 可能有重复的情况. 但是没关系啦. [代码] #includ ...

  7. 【Codeforces Round #452 (Div. 2) C】 Dividing the numbers

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] n为偶数. l = 1, r = n (l,r)放在一组 l++,r-- 新的l,r放在另外一组 直到l+1==r 这个时候,判断两 ...

  8. 【Codeforces Round #452 (Div. 2) D】Shovel Sale

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 让N乘2->a 然后看一下位数是多少. 假设有x位(x>=2) 则(0..(a%10-1) ) + (99..9)[x- ...

  9. 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 ...

随机推荐

  1. [py2neo]Ubuntu14 安装py2neo失败问题解决

    环境 1.操作系统Ubuntu14 2.py2neo版本4.1 3.python版本python3.4 问题 pip install py2neo==4.1  安装失败,提示: Cannot unin ...

  2. NOIP模拟 34

    次芝麻,喝喝喝,长寿花! 什么鬼畜题面...一看就不是什么正经出题人 skyh双双双AK了..太巨了... T1 次芝麻 稍稍手玩就能发现分界点以一个优美的方式跳动 然后就愉快地帮次货们次掉了这个题- ...

  3. ie浏览器兼容性的入门解决方案

    IE浏览器的兼容性素来是令人头疼的问题,大名鼎鼎的FUCK-IE不是浪得虚名的. 这里使用的解决方案是HACK,具体原理就是针对不同的浏览器写不同的HTML.CSS样式,从而使各种浏览器达到一致的渲染 ...

  4. Markdown基本语法小结

    目录 Typore Markdown基本语法 1.标题 一级标题 二级标题 三级标题 2.字体加粗 3.斜体 4.文本高亮 5.上标 6.下标 7.引用代码 1 8.代码引用2 9.代码引用3 10. ...

  5. phpstorm设置内存限制的方法

    phpstorm设置内存限制的方法有时候用phpstorm写代码 1个文件代码多的话会很卡 那就要修改内存限制 E:\Program Files (x86)\JetBrains\PhpStorm 20 ...

  6. 说一说,“NetWork Wall”所用到技术

    2010年1月17日,Google在其官方网站上发布了一篇名为<A new approach to China>的博文,在博文中,Google官方透露,将停止过滤搜索结果.在国内市场上停止 ...

  7. 使用JSP脚本在页面输出九九乘法表

    <% int i,j; for(i=1;i<10;i++) { for(j=1;j<=i;j++) { out.println(i+"*"+j+"=&q ...

  8. hdu 4337 King Arthur's Knights (Hamilton)

    King Arthur's KnightsTime Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Oth ...

  9. nyoj 260-数数小木块 (打表)

    260-数数小木块 内存限制:64MB 时间限制:3000ms 特判: No 通过数:17 提交数:24 难度:1 题目描述: 在墙角堆放着一堆完全相同的正方体小木块,如下图所示: 因为木块堆得实在是 ...

  10. 力扣(LeetCode)长按键入 个人题解

    你的朋友正在使用键盘输入他的名字 name.偶尔,在键入字符 c 时,按键可能会被长按,而字符可能被输入 1 次或多次. 你将会检查键盘输入的字符 typed.如果它对应的可能是你的朋友的名字(其中一 ...