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 ...
随机推荐
- MIT线性代数:19.行列式和代数余子式
- numpy.array 中的运算
简单运算 现在有有个需求,给定一个数组,让数组中每一个数乘以2,怎么做呢 n = 10 L = [i for i in range(n)] L # [0, 1, 2, 3, 4, 5, 6, 7, 8 ...
- [考试反思]0822NOIP模拟测试29:延续
想保持优秀很困难 但是想持续垫底却很简单 但是你不想垫底的话持续垫底也很容易... 分AB卷,A卷共15人. skyh,tdcp,kx155,B哥145... 我:35,倒数第一. 板子专题,爆零快乐 ...
- 开源 ERP 系统 GoodERP
如果你有一个苹果,我也有一个苹果,彼此交换后,你我还是一人一个苹果,但是如果你有一个想法,我有一个想法,彼此交换后,你我就都有两个想法,三个人呢?一百个人呢? 使用openobject框架 重写全部功 ...
- Kubernetes 挂载文件到pod里面
下面以chart为例子: 1.创建ConfigMap,这里要注意config.js为挂载的文件名 [root@cn-hongkong templates]# cat app-config.yaml a ...
- centos6的JDK安装
1. 通过如下命令查看当前操作系统是否存在JDK rpm -qa | grep java 如果出现以下内容说明你的操作系统存在jdk 2.那么依次通过如下命令进行删除它 rpm -e - -nodep ...
- Keras 中间层可视化,附代码详解,以Mnist数字为对象
最近搭建了个Resnet50 的神经网络模型,相看一看中间某一层的输出结果,想感性的感受下逐层提取特征的过程,以数字0为对象,对数字0逐层提取特征,话不多说直接上代码,关于如何搭建Resnet,可以参 ...
- 自建yum仓库,该仓库为默认仓库
YUM REPO: http://content.example.com/rhel7.0/x86_64/dvd 创建自建yum REPO文件: vim /etc/yum.repos.d/redhat. ...
- 0x8000FFFF 错误的解决方式
问题描述: 在F盘新建文件夹或文件的时候提示0x8000FFFF灾难性错误: 解决方法: 1.在F盘的位置,右击选择属性 2.在弹出的窗口中选择工具,点击检查 3.根据系统提示进行响应的驱动扫描与修复 ...
- 创建sql自定义的函数及商品分页sql存储过程
--商品筛选时判断品牌ID是否存在 --select dbo.isValite(94,94)create function isValite(@brandId int,@bId int)returns ...