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. 学习笔记39_EF的DAL层(精)

    通用的分页查询 public IQueryable<UserInfo> GetPage<T>(int pageSize,int pageIndex,out int total, ...

  2. JavaScript入门经典(第7版)读书笔记

    断断续续看了十来天,终于看完了,还是学到些东西,这本书还是不错的,各方面都有涉及. 补充了下之前不完善的JS 知识 笔记一般只记必要的东西.‎ Table of Contents 1. JavaScr ...

  3. python经典算法题:Z字变形

    题目 直接看图! 思路第一步:分组 我们把传入的字符串进行分组, 每个框内的字母为1组: 我们发现每个相同颜色的框内的一组字母的特点是在传入的字符串中是连续的: 我们还发现每组字母的个数是由numRo ...

  4. python——自行实现sorted函数

    仿照内建函数sorted,自行实现一个sort函数,能够为列表进行排序 看下面实例的前提是掌握 0.掌握sorted函数的用法.1.函数基本概念.2.函数是如何传参的.3.掌握三元表达式.4.掌握内建 ...

  5. PHP创建文件命名中文乱码解决的方法

    PHP创建文件命名中文乱码解决的方法 <pre>iconv('utf-8', 'gbk', $dir); </pre> 因为系统环境是gbk 所以里面的字符也要gbk 编码一致 ...

  6. java架构之路(MQ专题)kafka集群配置和简单使用

    前面我们说了RabbitMQ和RocketMQ的安装和简单的使用,这次我们说一下Kafka的安装配置,后面我会用几个真实案例来说一下MQ的真实使用场景.天冷了,不愿意伸手,最近没怎么写博客了,还请见谅 ...

  7. Mysql 开启远程连接服务

    Mysql 开启远程连接服务 修改要远程访问的那个用户的 host 为 % use mysql; insert into user (host, user, password) values('%', ...

  8. nyoj 204-Coin Test (python count)

    204-Coin Test 内存限制:64MB 时间限制:3000ms 特判: No 通过数:2 提交数:2 难度:1 题目描述: As is known to all,if you throw a ...

  9. opencv 5 图像转换(1 边缘检测)

    边缘检测 一般步骤 canny算子 步骤 canny函数 彩色canny #include<opencv2/opencv.hpp> #include<opencv2/highgui/ ...

  10. LVM弹性硬盘

    LVM机制的基本概念 PV(物理卷) ----由多个pe组成 VG(卷组) LV(逻辑卷) 基本命令: 如: 服务器新增一块大小为1T的SCSI的硬盘(sdb) ,创建一个名字为(ceshi)的逻辑分 ...