Codeforces Round #468 (Div. 2, based on Technocup 2018 Final Round)C. Laboratory Work

本文介绍了一个物理实验场景下的数据处理问题,旨在帮助学生Anya在遵循特定条件的情况下,生成一组与同学Kirill测量数据具有相同平均值但重复值尽可能少的新数据集。文章通过分类讨论的方式提供了具体的解决思路及实现代码。

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, …, ynin 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
6
-1 1 1 0 0 -1
output
2
0 0 0 0 0 0
input
3
100 100 101
output
3
101 100 100
input
7
-10 -9 -10 -8 -10 -9 -9
output
5
-10 -10 -9 -9 -9 -9 -9

题意:给出a串,保证每个数字是整数且所有数间差值最大不超过2,输出b串使其:1.两串总和相等 2.b串数取值范围和a串数相同 3.两串相同数尽量少
找规律题,分类讨论

#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#define INF 0x3f3f3f3f
#define lowbit(x) (x&(-x))
#define eps 0.00000001
#define pn printf("\n")
using namespace std;
typedef long long ll;

const int maxn = 1e5+7;
int n, a[maxn];
int MIN = INF, MAX = -INF, tot = 0;
int k = 0, fl = 0;
vector <int> vi;
map <int,int> mp;

int main()
{
    scanf("%d",&n);
    for(int i=0;i<n;i++)
    {
        scanf("%d",a+i);
        mp[a[i]] ++;
        tot += a[i];
        MIN = min(MIN, a[i]);
        MAX = max(MAX, a[i]);
    }

    if(MAX - MIN <= 1)
    {
        printf("%d\n", n);
        for(int i=0;i<n;i++)
        {
            if(i) printf(" ");
            printf("%d", a[i]);
        }pn;
    }
    else
    {
        if(!mp.count(MAX-1))
        {
            int mt, res;
            if(mp[MIN] < mp[MAX])
            {
                mt = mp[MIN];
                res = MAX;
            }
            else
            {
                mt = mp[MAX];
                res = MIN;
            }
            int mid = 2 * mt, fl = 0;
            printf("%d\n" ,n - mid);
            for(int i=0;i<mid;i++)
            {
                if(!fl) fl = 1;
                else printf(" ");
                printf("%d", MIN  +1);
            }
            for(int i=mid;i<n;i++)
            {
                if(!fl) fl = 1;
                else printf(" ");
                printf("%d", res);
            }
        }
        else // 1 2 2 2 2 3
        {
            if(min(mp[MIN],mp[MAX])*2 > mp[MIN+1]/2*2)
            {
                int mt, res;
                if(mp[MIN] < mp[MAX])
                {
                    mt = mp[MIN];
                    res = MAX;
                }
                else
                {
                    mt = mp[MAX];
                    res = MIN;
                }
                int mid = 2 * mt + mp[MIN+1], fl = 0;
                printf("%d\n" ,n -2 * mt);
                for(int i=0;i<mid;i++)
                {
                    if(!fl) fl = 1;
                    else printf(" ");
                    printf("%d", MIN  +1);
                }
                for(int i=mid;i<n;i++)
                {
                    if(!fl) fl = 1;
                    else printf(" ");
                    printf("%d", res);
                }

            }
            else
            {
                int mt = mp[MIN+1]/2;
                int ans = (mp[MIN+1]&1) + mp[MIN] + mp[MAX];
                printf("%d\n",ans);
                int fl = 0, cn = mp[MIN] + mt, cx = mp[MAX] + mt;
                if(mp[MIN+1]&1)
                {
                    printf("%d",MIN + 1); fl = 1;
                }
                for(int i=0;i<cn;i++)
                {
                    if(!fl) fl = 1;
                    else printf(" ");
                    printf("%d", MIN);
                }
                for(int i=0;i<cx;i++)
                {
                    if(!fl) fl = 1;
                    else printf(" ");
                    printf("%d", MAX);
                }
            }
        }
        pn;
    }

}
下载方式:https://pan.quark.cn/s/b4d8292ba69a 在构建食品品牌的市场整合营销推广方案时,我们必须首先深入探究品牌的由来、顾客的感知以及市场环境。 此案例聚焦于一款名为“某饼干产品”的食品,该产品自1998年进入河南市场以来,经历了销售业绩的波动。 1999至2000年期间,其销售额取得了明显的上升,然而到了2001年则出现了下滑。 在先前的宣传活动中,品牌主要借助大型互动活动如ROAD SHOW来吸引顾客,但收效甚微,这揭示了宣传信息与顾客实际认同感之间的偏差。 通过市场环境剖析,我们了解到消费者对“3+2”苏打夹心饼干的印象是美味、时尚且充满活力,但同时亦存在口感腻、价位偏高、饼身坚硬等负面评价。 实际上,该产品可以塑造为兼具美味、深度与创新性的休闲食品,适宜在多种情境下分享。 这暗示着品牌需更精确地传递产品特性,同时消解消费者的顾虑。 在策略制定上,我们可考虑将新产品与原有的3+2苏打夹心进行协同推广。 这种策略的长处在于能够借助既有产品的声誉和市场占有率,同时通过新产品的加入,刷新品牌形象,吸引更多元化的消费群体。 然而,这也可能引发一些难题,例如如何合理分配新旧产品间的资源,以及如何保障新产品的独特性和吸引力不被既有产品所掩盖。 为了提升推广成效,品牌可以实施以下举措:1. **定位修正**:基于消费者反馈,重新确立产品定位,突出其美味、创新与共享的特性,减少消费者感知的缺陷。 2. **创新宣传**:宣传信息应与消费者的实际体验相契合,运用更具魅力的创意手段,例如叙事式营销,让消费者体会到产品带来的愉悦和情感共鸣。 3. **渠道选择**:在目标消费者常去的场所开展活动,例如商业中心、影院或在线平台,以提高知名度和参与度。 4. **媒体联...
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值