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. 【POJ3744】Scout YYF I

    Description YYF是一个英勇的侦查员.现在他正在执行打入到敌方内部的危险任务.在解决了一系列的险情后,YYF到达了敌方著名的"地雷路"起始点.这条路非常长,上面被精心排 ...

  2. javascript创建一个基于数组的栈结构

    栈是一种遵从后进先出(LIFO)原则的有序集合.新添加或待删除的元素都保存在栈的同 一端,称作栈顶,另一端就叫栈底.在栈里,新元素都靠近栈顶,旧元素都接近栈底. 栈拥有以下方法: push(eleme ...

  3. NOIP模拟 8

    T1 水题,可是没A,惭愧. 值得一提的是,虽然我忘了kmp,现场制造的kmp因为缺少针对题目的特判挂了,但是现场制造的kmp板子能过字符串板子题.. 对..把板子改装了...而且改对了! nx[]= ...

  4. NOIP模拟 19

    最近试考的脑壳疼 晚上还有一场555 T1 count 研究性质题. 研究好了AC,研究不明白就没头绪 首先枚举n的因子d 其次发现因为是树,所以如果合法,贡献只能是1 然后发现如果合法,一定是一棵一 ...

  5. Scrapy爬取豆瓣图书数据并写入MySQL

    项目地址 BookSpider 介绍 本篇涉及的内容主要是获取分类下的所有图书数据,并写入MySQL 准备 Python3.6.Scrapy.Twisted.MySQLdb等 演示 代码 一.创建项目 ...

  6. Unity入门--实用知识

    目录 1. VS适配 2.实用快捷操作 3.Unity API文档 4.项目整理 1. VS适配 让你的VS完美支持Unity的脚本编写可以让你写起C#脚本来事半功倍,比如代码补全功能,可以参考下面这 ...

  7. containerd 与安全沙箱的 Kubernetes 初体验

    作者 | 易立  阿里云资深技术专家 containerd 是一个开源的行业标准容器运行时,关注于简单.稳定和可移植,同时支持 Linux 和 Windows. 2016 年 12 月 14 日,Do ...

  8. PHP 在 Laravel 中动态隐藏 API 字段

    我最近在 Laravel Brasil 社区看到一个问题,结果比看起来更有趣.想象一下你有一个 UsersResource 用下面的实现: <?php namespace App\Http\Re ...

  9. Python print函数使用

    本文链接:https://www.cnblogs.com/zyuanlbj/p/11905405.html 函数定义 def print(self, *args, sep=' ', end='\n', ...

  10. 关于 “'sqlite3' 不是内部或外部命令.....”问题

    学习django 按书上的  执行 manage.py dbshell 时, 报“'sqlite3' 不是内部或外部命令,也不是可运行的程序 或批处理文件.” 也就是指,环境变量中没有“sqlite3 ...