Codeforces 931 C. Laboratory Work
http://codeforces.com/problemset/problem/931/C
题意:
给定一个数列,要求构造一个等长的数列,使得数列的平均值等于给定数列,并且使得构造出的数列中与原数列相同的数字个数最小,输出最小相同数字个数与构造的数列。
数列长度不超过100000,给定数列中最大的数字与最小的数字相差不超过2。
要求构造出的数列中最大值与最小值不能大于或小于原数列中的最大值与最小值。
如果最大-最小=0,那只能使用原数列
如果最大-最小=1,也还是只能使用原数列
如果最大-最小=2
要么把每2个次大的改成一个最小和一个最大,要么把一个最大和一个最小改成2个次大
两种情况取最优
#include<cstdio>
#include<iostream>
#include<algorithm> using namespace std; #define N 100001 int a[N]; void read(int &x)
{
x=; int f=; char c=getchar();
while(!isdigit(c)) { if(c=='-') f=-; c=getchar(); }
while(isdigit(c)) { x=x*+c-''; c=getchar(); }
x*=f;
} int main()
{
int n;
read(n);
for(int i=;i<=n;++i) read(a[i]);
sort(a+,a+n+);
if(a[n]-a[]<=)
{
printf("%d\n",n);
for(int i=;i<=n;++i) printf("%d ",a[i]);
return ;
}
int s1=,s2=,s3=;
for(int i=;i<=n;++i)
{
if(a[i]==a[]) s1++;
else if(a[i]==a[n]) s3++;
else s2++;
}
int t=min(s1,s3),k=s2/;
int m=a[];
if(t>k)
{
for(int i=;i<=t;++i) a[i]=m+;
for(int i=;i<=t;++i) a[n-i+]=m+;
printf("%d\n",n-t*);
for(int i=;i<=n;++i) printf("%d ",a[i]);
}
else
{
for(int i=;i<=k;++i) a[s1+i*-]=m,a[s1+i*]=m+;
printf("%d\n",n-k*);
for(int i=;i<=n;++i) printf("%d ",a[i]);
}
}
Codeforces 931 C. Laboratory Work的更多相关文章
- Codeforces 931C:Laboratory Work(构造)
C. Laboratory Work time limit per test : 1 second memory limit per test : 256 megabytes input : stan ...
- Codeforces 931.F Teodor is not a liar!
F. Teodor is not a liar! time limit per test 1 second memory limit per test 256 megabytes input stan ...
- Codeforces 931.D Peculiar apple-tree
D. Peculiar apple-tree time limit per test 1 second memory limit per test 256 megabytes input standa ...
- Codeforces 931 概率DP
A #include <bits/stdc++.h> #define PI acos(-1.0) #define mem(a,b) memset((a),b,sizeof(a)) #def ...
- 【codeforces】【比赛题解】#931 CF Round #468 (Div. 2)
因为太迟了,所以没去打. 后面打了Virtual Contest,没想到拿了个rank 3,如果E题更快还能再高,也是没什么想法. [A]Friends Meeting 题意: 在数轴上有两个整点\( ...
- Codeforces Round #468 (Div. 2, based on Technocup 2018 Final Round)C. Laboratory Work
Anya and Kirill are doing a physics laboratory work. In one of the tasks they have to measure some v ...
- 【Codeforces Round #420 (Div. 2) A】Okabe and Future Gadget Laboratory
[题目链接]:http://codeforces.com/contest/821/problem/A [题意] 给你一个n*n的数组; 然后问你,是不是每个位置(x,y); 都能找到一个同一行的元素q ...
- CodeForces 931C Laboratory Work 水题,构造
*这种题好像不用写题解... 题意: 一个人要改动别人的实验记录,实验记录记录是一个集合 实验记录本身满足:$max(X)-min(X)<=2$ 改动结果要求: 1.新的集合平均值和之前的一样 ...
- Codeforces 931D Peculiar apple-tree(dfs+思维)
题目链接:http://codeforces.com/contest/931/problem/D 题目大意:给你一颗树,每个节点都会长苹果,然后每一秒钟,苹果往下滚一个.两个两个会抵消苹果.问最后在根 ...
随机推荐
- 记录Jenkins+gitlab+maven
摘要 昨天抽空将jenkins+gitlab(git)+maven整合了一下,再次记录一下以防下次再去查找省的麻烦. git.maven.java配置 启动jenkins之后进入系统管理里面的Glob ...
- 《Macro-Micro Adversarial Network for Human Parsing》论文阅读笔记
<Macro-Micro Adversarial Network for Human Parsing> 摘要:在人体语义分割中,像素级别的分类损失在其低级局部不一致性和高级语义不一致性方面 ...
- CryptoZombies学习笔记——Lesson2
第二课是僵尸猎食,将把app变得更像一个游戏,添加多人模式,建立更多创造僵尸的方法. chapter1 依然是简介 chapter2:映射和地址 映射相当于一个索引,指向不同地址,不同地址存储的数据不 ...
- mysql select 字段别名是否可以用在 select中或者where中
select column1+10 as c1,c1+10 as c2 from table1;想实现上面的效果,结果在mysql里面报错了,提示找不到c1这个列; -- 不同的 数据库不一样 一般不 ...
- 《Linux内核分析与设计实现》读书笔记一
第一章 Linux内核简介 1.1 Unix的历史 Unix的特点: Unix很简洁,仅仅提供几百个系统调用并且有一个非常明确的设计目的: 在Unix中,所有的东西都被当做文件对待. Unix的内核和 ...
- Zero-shot learning(零样本学习)
一.介绍 在传统的分类模型中,为了解决多分类问题(例如三个类别:猫.狗和猪),就需要提供大量的猫.狗和猪的图片用以模型训练,然后给定一张新的图片,就能判定属于猫.狗或猪的其中哪一类.但是对于之前训练图 ...
- 共享服务Samba,实现liunx与Windows文件共享
Samba服务程序 是一款SMB协议并有服务器和客户端组成的开源文件共享软件,实现了Linux 与Windows系统之间的文件共享 Samba的配置文件有太多注释的东西,为了方便使用下面的命令,可以更 ...
- Alpha 冲刺十
团队成员 051601135 岳冠宇 051604103 陈思孝 031602629 刘意晗 031602248 郑智文 031602234 王淇 会议照片 项目燃尽图 项目进展 完善各自部分 项目描 ...
- PAT 甲级 1078 Hashing
https://pintia.cn/problem-sets/994805342720868352/problems/994805389634158592 The task of this probl ...
- Access restriction: The type 'BASE64Decoder' is not API
Access restriction: The type 'BASE64Decoder' is not API (restriction on required library 'C:\Program ...