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 题目大意:给你一颗树,每个节点都会长苹果,然后每一秒钟,苹果往下滚一个.两个两个会抵消苹果.问最后在根 ...
随机推荐
- Outlook2013修改数据文件默认存放目录
转载 当使用outlook 2013新建Email账户的时候,其数据文件(.ost文件)总是被保存在C盘默认目录“C:\Users\用户名\AppData\Local\Microsoft\Outloo ...
- 学习git 新手。这个写的不错
转自:https://www.cnblogs.com/wupeiqi/p/7295372.html 版本控制 说到版本控制,脑海里总会浮现大学毕业是写毕业论文的场景,你电脑上的毕业论文一定出现过这番景 ...
- 【LeetCode】数组--合并区间(56)
写在前面 老粉丝可能知道现阶段的LeetCode刷题将按照某一个特定的专题进行,之前的[贪心算法]已经结束,虽然只有三个题却包含了简单,中等,困难这三个维度,今天介绍的是第二个专题[数组] 数组( ...
- 分布式理论:深入浅出Paxos算法
前言 Paxos算法是用来解决分布式系统中,如何就某个值达成一致的算法.它晦涩难懂的程度完全可以跟它的重要程度相匹敌.目前关于paxos算法的介绍已经非常多,但大多数是和稀泥式的人云亦云,却很少有人能 ...
- Linux内核分析(第六周)
进程的控制与创建 一.进程的描述 1.操作系统内核的三大功能:进程管理(核心),内存管理,文件系统: 2.状态: fork() task_zombit(终止) task_running(就绪:但是没有 ...
- linux第一次实验报告
http://wwwcnblogs.com/20135228guoyao/4964477.html
- images & Skeleton
images & Skeleton image placeholder & loading ... skeleton.css https://github.com/dhg/Skelet ...
- 设置close
- Good Bye 2018 没打记
场外选手赛时只口胡出了CD感觉非常惨.只看了E并且还没看到题面里的wiki我能咋办 C:f只与gcd(n,k)有关. D:考虑每种起始位置,对于跨越的两个排列,只有前一个排列的后缀单减时不产生贡献.答 ...
- bzoj 4034: [HAOI2015]树上操作 (树剖+线段树 子树操作)
4034: [HAOI2015]树上操作 Time Limit: 10 Sec Memory Limit: 256 MBSubmit: 6779 Solved: 2275[Submit][Stat ...