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的更多相关文章

  1. Codeforces 931C:Laboratory Work(构造)

    C. Laboratory Work time limit per test : 1 second memory limit per test : 256 megabytes input : stan ...

  2. 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 ...

  3. Codeforces 931.D Peculiar apple-tree

    D. Peculiar apple-tree time limit per test 1 second memory limit per test 256 megabytes input standa ...

  4. Codeforces 931 概率DP

    A #include <bits/stdc++.h> #define PI acos(-1.0) #define mem(a,b) memset((a),b,sizeof(a)) #def ...

  5. 【codeforces】【比赛题解】#931 CF Round #468 (Div. 2)

    因为太迟了,所以没去打. 后面打了Virtual Contest,没想到拿了个rank 3,如果E题更快还能再高,也是没什么想法. [A]Friends Meeting 题意: 在数轴上有两个整点\( ...

  6. 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 ...

  7. 【Codeforces Round #420 (Div. 2) A】Okabe and Future Gadget Laboratory

    [题目链接]:http://codeforces.com/contest/821/problem/A [题意] 给你一个n*n的数组; 然后问你,是不是每个位置(x,y); 都能找到一个同一行的元素q ...

  8. CodeForces 931C Laboratory Work 水题,构造

    *这种题好像不用写题解... 题意: 一个人要改动别人的实验记录,实验记录记录是一个集合 实验记录本身满足:$max(X)-min(X)<=2$ 改动结果要求: 1.新的集合平均值和之前的一样 ...

  9. Codeforces 931D Peculiar apple-tree(dfs+思维)

    题目链接:http://codeforces.com/contest/931/problem/D 题目大意:给你一颗树,每个节点都会长苹果,然后每一秒钟,苹果往下滚一个.两个两个会抵消苹果.问最后在根 ...

随机推荐

  1. C#_Winfrom将浏览器生成Image

    using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...

  2. Jq_javascript跨域问题

    为什么浏览器不能跨域   现在很多人特别是前端开发人员,在ajax请求,XMLHttpRequest的过程中会碰到一个问题,那就是跨域请求: 当我们javaScript脚本试图跨域访问时,浏览器会告诉 ...

  3. 高精度加法--C++

    高精度加法--C++ 仿照竖式加法,在第一步计算的时候将进位保留,第一步计算完再处理进位.(见代码注释) 和乘法是类似的. #include <iostream> #include < ...

  4. 自动化部署-Jenkins+SVN+MSBuild

    这篇文章主要介绍下使用Jenkins实现自动化部署 下载 https://jenkins.io/download/ 安装 按步骤安装即可,下载的是windows版本,安装完成后,会看到这样一个正在运行 ...

  5. PS官方正式中文版(搬砖分享)

    https://pan.baidu.com/s/1c3IdQq0 PS官方正式中文版(搬砖分享) 注意事项: 1.安装开始前请先断网,在成功破解激活前请全程断网: 2.安装完成后先试运行软件一次,然后 ...

  6. B1041. 考试座位号(15)

    这题比较简单,没有调试,一次通过,虽然简单,不过也有借鉴意义. #include<bits/stdc++.h> using namespace std; const int N=1005; ...

  7. 基于tensorflow2.0 使用tf.keras实现Fashion MNIST

    本次使用的是2.0测试版,正式版估计会很快就上线了 tf2好像更新了蛮多东西 虽然教程不多 还是找了个试试 的确简单不少,但是还是比较喜欢现在这种写法 老样子先导入库 import tensorflo ...

  8. PAT甲题题解-1077. Kuchiguse (20)-找相同后缀

    #include <iostream> #include <cstdio> #include <algorithm> #include <string.h&g ...

  9. 使用jQuery的分页插件jquery.pagination.js进行分页

    1,需要用到jquery.pagination.js和pagination.css https://pan.baidu.com/s/1G3PLQSRGjvLxl2ryqpV76w https://pa ...

  10. js中判断是否包含某个字符串

    1,字符串中是否包含 str.indexOf("3")indexOf() 方法可返回某个指定的字符串值在字符串中首次出现的位置.如果要检索的字符串值没有出现,则该方法返回 -1. ...