Codeforces 944B Laboratory Work

华为AC外置Portal认证方案配置步骤指南 阅读详情

传送门:Codeforces 944B


B. Laboratory Work
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Anya and Kirill are doing a physics laboratory work. In one of the tasks they have to measure some value n times, and then compute the average value to lower the error.

Kirill has already made his measurements, and has got the following integer values: x1, x2, ..., xn. It is important that the values are close to each other, namely, the difference between the maximum value and the minimum value is at most 2.

Anya does not want to make the measurements, however, she can't just copy the values from Kirill's work, because the error of each measurement is a random value, and this coincidence will be noted by the teacher. Anya wants to write such integer values y1, y2, ..., yn in her work, that the following conditions are met:

  • the average value of x1, x2, ..., xn is equal to the average value of y1, y2, ..., yn;
  • all Anya's measurements are in the same bounds as all Kirill's measurements, that is, the maximum value among Anya's values is not greater than the maximum value among Kirill's values, and the minimum value among Anya's values is not less than the minimum value among Kirill's values;
  • the number of equal measurements in Anya's work and Kirill's work is as small as possible among options with the previous conditions met. Formally, the teacher goes through all Anya's values one by one, if there is equal value in Kirill's work and it is not strike off yet, he strikes off this Anya's value and one of equal values in Kirill's work. The number of equal measurements is then the total number of strike off values in Anya's work.

Help Anya to write such a set of measurements that the conditions above are met.

Input

The first line contains a single integer n (1 ≤ n ≤ 100 000) — the numeber of measurements made by Kirill.

The second line contains a sequence of integers x1, x2, ..., xn ( - 100 000 ≤ xi ≤ 100 000) — the measurements made by Kirill. It is guaranteed that the difference between the maximum and minimum values among values x1, x2, ..., xn does not exceed 2.

Output

In the first line print the minimum possible number of equal measurements.

In the second line print n integers y1, y2, ..., yn — the values Anya should write. You can print the integers in arbitrary order. Keep in mind that the minimum value among Anya's values should be not less that the minimum among Kirill's values, and the maximum among Anya's values should be not greater than the maximum among Kirill's values.

If there are multiple answers, print any of them.

Examples
input
Copy
6
-1 1 1 0 0 -1
output
2
0 0 0 0 0 0 
input
Copy
3
100 100 101
output
3
101 100 100 
input
Copy
7
-10 -9 -10 -8 -10 -9 -9
output
5
-10 -10 -9 -9 -9 -9 -9 
Note

In the first example Anya can write zeros as here measurements results. The average value is then equal to the average value of Kirill's values, and there are only two equal measurements.

In the second example Anya should write two values 100 and one value 101 (in any order), because it is the only possibility to make the average be the equal to the average of Kirill's values. Thus, all three measurements are equal.

In the third example the number of equal measurements is 5.


分析:数字的范围控制在2内,构造时候枚举最小数字的个数

加几个剪枝,减去不合条件的枚举

具体实现见代码


代码如下:

#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;

const int INF = 1<<30;
const int maxn = 100000+5;
int w[3];
int a[maxn];
int n,mn,sum;

int main(){
    scanf("%d",&n);
    mn = INF; sum = 0;
    memset(w,0,sizeof(w));
    for (int i=1; i<=n; i++) scanf("%d",&a[i]),mn = min(mn,a[i]);
    for (int i=1; i<=n; i++) {
        a[i] = a[i]-(mn+1);
        sum += a[i];
        w[a[i]+1]++;
    }

    int ans = INF;
    int v1,v2,v3;
    for (int i=0; i<=n; i++) {
        int tmp = sum+i;
        if (tmp<0) continue;
        if (tmp>0 && !w[2]) continue;
        if (n-tmp-i<0) continue;
        if (n-tmp-i>0 && !(w[1] || w[2])) continue;
        int tot = min(i,w[0])+min(n-tmp-i,w[1])+min(tmp,w[2]);
        if (tot<ans) {
            ans = tot;
            v1 = i;
            v2 = n-tmp-i;
            v3 = tmp;
        }
    }

    printf("%d\n",ans);
    for (int i=1; i<=v1; i++) printf("%d ",mn);
    for (int i=1; i<=v2; i++) printf("%d ",mn+1);
    for (int i=1; i<=v3; i++) printf("%d ",mn+2);
    return 0;
}

【2023】Java利用modbus4j实现工业设备Modbus TCP数据采集与解析 本文详细介绍了在2023年使用Java和modbus4j库实现工业设备Modbus TCP数据采集与解析的完整实践。内容涵盖开发环境搭建、TCP连接建立、开关量与模拟量数据的读取与解析、批量读取性能优化、控制指令写入以及常见错误排查指南,为开发者构建稳定高效的工业物联网数据采集系统提供全面指导。 阅读详情

相关推荐

feko金属球远场RCS双站

feko金属球远场RCS双站

a264672的博客 6909

C. Laboratory Work(暴力或贪心)

Ⅰ.暴力判断\color{Red}Ⅰ.暴力判断Ⅰ.暴力判断 直接暴力就行了,毕竟所有数只可能是minn,minn+1,minn+2直接暴力就行了,毕竟所有数只可能是minn,minn+1,minn+2直接暴力就行了,毕竟所有数只可能是minn,minn+1,minn+2 当最大值减去最小值为不大于1时,输出原数列就行了(唯一构造方法)当最大值减去最小值为不大于1时,输出原数列就行了(唯一构造方法)当最大值减去最小值为不大于1时,输出原数列就行了(唯一构造方法) 否则,枚举minn+1的个数否则,枚举minn

jziwjxjd的博客 509

别再只接个放大器了!压电传感器测量电路(电压/电荷放大器)的5个实战配置要点

本文深入解析压电传感器测量电路中的5个关键实战配置要点,包括电缆长度选择、输入阻抗匹配、过载保护设计、低频噪声抑制及放大器选型策略。特别针对电压放大器和电荷放大器的应用场景差异提供工程实践建议,帮助工程师有效解决信号失真、噪声干扰等常见问题,提升测量精度和系统可靠性。

weixin_26869081的博客 301

C. Laboratory Work

Anya and Kirill are doing a physics laboratory work. In one of the tasks they have to measure some value n times, and then compute the average value to lower the error.Kirill has already made his meas...

海绵的博客 436

Image Sensor卷帘曝光(Rolling Shutter)基本原理以及对曝光行的通俗理解

由于CMOS sensor的曝光方式是一行一行的方式进行的,任何一个pixel的曝光时间是一样的,也就是同一行上的每个pixel的曝光开始点和曝光的时间都是一模一样的,所以同一行的所有点所接受到的能量是一样的,而在不同行之间虽然曝光时间都是一样的,但是曝光的开始点是不同的,所以不同行之间所接受到的能量是不一定相同的。至此完成了这一行的曝光。还是以桶装水为比喻: 排成一行的桶(桶的数量和每个桶的大小确定),每一曝光行为单位的时间内每一个桶加水都是一样,需要多少个曝光行才能使的所有水桶加起来的水达到1L。

大熊 3921

Easy系列PLC远程IO模块的安装配置和地址访问(EtherCAT总线)

EtherCAT分布式时钟DC(SOEM源码解析)EtherCAT分布式时钟DC(SOEM源码解析)_soem dc同步-优快云博客文章浏览阅读1.2k次。分布式时钟(DC,Dsitributed Clock)可以使所有 EtherCAT设备使用相同的系统时间,从而控制各设备任务的同步执行。_soem dc同步1200PLC连接分布式IO组态编程应用(ES200SP固件版本不同解决方法)

RXXW_Dor的博客 171

Codeforces 931C Laboratory Work

Anya and Kirill are doing a physics laboratory work. In one of the tasks they have to measure some value n times, and then compute the average value to lower the error.Kirill has already made his meas...

包子不卖包子 731

本地玩转AI还得靠这个,SillyTavern(酒馆)到底有多强?

SillyTavern是一款本地运行的LLM交互前端,支持文本生成、图像生成、语音合成等功能。它最初是TavernAI的分支,现已独立开发,社区活跃,功能更新频繁。SillyTavern通过前端UI和插件系统连接各种大模型后端,如OpenAI、KoboldAI等,用户可以在本地创建“虚拟酒馆”与各种角色对话。其功能亮点包括角色卡、角色记忆、世界设定、多人聊天室、自定义UI和行为脚本、插件扩展支持等。SillyTavern适合AI创作用户、AI工程师、LLM爱好者和AIGC创作者。它有两个维护分支:relea

代码简单说 Vue、JAVA、PHP、Node.js 熟练运用,接口、架构、性能全搞定。 8031

codeforces 931 C. Laboratory Work

阅读量稍大的一道题目,理清关系后其实不难

toby的博客 480

Autosar诊断实战系列02-Dem(DTC&Event)要点及配置开发详解

Dem模块及其与Dcm等其他模块的交互是整个诊断Stack的重中之重,本文先对与其他模块的交互逻辑进行介绍,有一定掌握后继续重点介绍配置部分的开发。

initiallizer的博客 3330

YOLO11涨点优化:训练技巧 | 使用标签平滑(Label Smoothing)配合余弦退火学习率,防止过拟合,稳步提点

摘要: YOLO11凭借动态卷积核调度、自适应特征融合等创新成为2026年目标检测主流,但面临训练集过拟合问题。文章聚焦两种零推理开销的正则化技巧:标签平滑(Label Smoothing)和余弦退火学习率(Cosine Annealing LR)。标签平滑通过软化硬标签(如将[1,0]改为[0.9,0.1])防止模型过度自信,代码中通过label_smoothing=0.1一键启用;余弦退火则以平滑的余弦曲线调整学习率(cos_lr=True),避免阶梯衰减的震荡。两者组合可显著缩小YOLO11训练与验证

2601_95807009的博客 45

Codeforces 931.C Laboratory Work

C. Laboratory Worktime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputAnya and Kirill are doing a physics laboratory work. In one of the tasks they hav...

Yorozuya 400

搭建一个简单的 Django + Vue 项目

在本文中,我将为您详细介绍如何搭建一个简单的 Django + Vue 项目。Django 是一个使用 Python 编写的高级 Web 框架,而 Vue 是一个流行的 JavaScript 框架,用于构建用户界面。通过结合 Django 和 Vue,我们可以创建强大的全栈 Web 应用程序。创建 Django 项目设置 Django 后端创建 Vue 前端连接 Django 和 Vue让我们开始吧!

JfpBlockchain的博客 350

codeforces 944B - Laboratory Work

http://codeforces.com/contest/944/problem/B #include &lt;bits/stdc++.h&gt; using namespace std; const int INF=99999999; int n; int a[100005]; int num[3]; int x,y,z; int ans=INF; int Min=INF; int ma...

西瓜不甜的博客 3286

廖雪峰Python教程[完整版]

廖雪峰的python教程整理的,已经排好版了,而且还是完整的,适合小白

最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版

Part-E1-SDIO-Specification-Ver4.00-Final-120220.pdf:最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版,包括SDIO 接口的外设,SDIO 接口官方协议等。

【Codeforces】 Laboratory Work

题目大概意思就是:给出一组实验数据(变换前的数据每个之间最大相差为2),要求对这组实验数据进行变换,变换要符合三个要求:1.变换后的新数据的平均值和原数据一样。2.变换后得到的新数据的上下边界不能超过原来的实验数据 。3.两组实验数据相同的值要最少。思路:变换后得到的新数据的平均值一样和最大相差为二可以知道只存在两种变换:设a,b,c存在a=b+1,b=c+1关系一、a+c变换为2b二、2b变换为...

Maple丶峰 274

VC中sqlite的使用

在VC中对sqlite的使用,实现数据库大批数据的快速插入,读取数据库中的数据在ListCtrl中显示

CodeForces - 931C (思维题,最少相等数)

Anya and Kirill are doing a physics laboratory work. In one of the tasks they have to measure some value n times, and then compute the average value to lower the error.Kirill has already made his meas...

obsorb_knowledge的博客 489

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

Codeforces 930B Game with String

传送门:Codeforces 930B B. Game with Stringtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputVasya and Kolya play a game with a string, using the follow...

勇敢前进的ACMer 1889

Codeforces Round #468 C. Laboratory Work

C. Laboratory WorkAnya and Kirill are doing a physics laboratory work. In one of the tasks they have to measure some value n times, and then compute the average value to lower the error.Kirill has alr...

s540239976的博客 277

Laboratory Work CodeForces - 931C(平均值,构造)

Anya and Kirill are doing a physics laboratory work. In one of the tasks they have to measure some value n times, and then compute the average value to lower the error. Kirill has already made his mea...

tomjobs的博客 445

CodeForces - 931C Laboratory Work

C. Laboratory Worktime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputAnya and Kirill are doing a physics laboratory work. In one of the tasks they hav...

哇-WA 的博客 287

CodeForces 931 C. Laboratory Work

题意:    给定长度为n 的数组,数组的最大值与最小值的差值最大为2.对数组进行修改最大值最小值与原数列相同,且和与原数列相同。要求尽可能的使得修改尽可能的打。分析:    当最大的数与最小的数差值为1或者是0的时候我们不能对数组进行修改当差值为2的时候修改方法有两种:1 . Max + Min -  &gt; 2 Mid2 . 2 Mid - &gt; Max + Min比较一下那个转换方法可...

努力打工 330

Codeforce931C(思维)

Laboratory Work 传送门 题意:给你一个长为n的序列,该序列的元素之间的差值不超过二,现在要你找出一个新的大小同为n的序列,其平均数于原序列相等,并且里面的元素大小要在原序列的范围之内。 思路:要求大小为n,平均数相等,元素大小范围在原序列内,这说明要求在原序列中元素之间进行转化,而能转化的只有一种—a+1 + a+3 = 2*(a+2) 所以进行判断转化就可以了 ...

siyu 266

【codeforces】【速】931C

C. Laboratory Work 原题链接:931C. Laboratory Work 题意:给定一个最大值与最小值相差不超过2的数组,求一个平均值相同但数据相同个数最少的数组,并且需要输出他相同数据的个数,允许重复值 题解:如代码所示,利用桶,只有两种情况 a–>2b<–c — 变成 — 2b a<–2b–>c — 变成 — a c 考虑这两种情况中的最小值就好了...

Drmon.的博客 440

CodeForces 931 D. Peculiar apple-tree

题意:    有n个苹果长在树上,【i】位置的苹果下一秒会掉到p【i】位置。如果有两个苹果掉到一个位置两个苹果就都碰坏了,3个的话就有一个好的。每次只能接到1位置的苹果。分析:    通过分析我们其实可以发现只要考虑到1位置的步数就可以了。#include&lt;bits/stdc++.h&gt; using namespace std; #define N 100005 int n,res=0,...

努力打工 461

Codeforces Round #468 C. Laboratory Work(暴力)

C. Laboratory Work time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Anya and Kirill are doing a physic...

weixin_30425949的博客 146

codeforces 936B Sleepy Game

http://www.elijahqi.win/2018/02/26/codeforces-936b-sleepy-game/ Petya and Vasya arranged a game. The game runs by the following rules. Players have a directed graph consisting of n vertices and m edg...

Elijahqi 869
上一篇: FZU 1382 Area Ratio
下一篇: Codeforces 930B Game with String
罗侯
博客等级 码龄10年 135粉丝 258原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值