题解:P15083 [ICPC 2024 Chengdu R] Recover Statistics

· · 题解

思路

构造方法

这里 a 表示原数据集的 P50 值,b 表示原数据集的 P95 值,c 表示原数据集的 P99 值。

我们可以令该数据集大小为 100,其中前 50 个数为 a,后 45 个数为 b,再后 4 个数为 c,最后一个数为 c+1

证明

显然,a<b<c

那么该数据集只有前 50 个数小于或等于(实际上都等于)a,同时前 50 个数又都小于 b,因此有 95 个数小于或等于 b,以此类推。

代码

#include<cstdio>
int main()
{
    int a,b,c;
    scanf("%d%d%d",&a,&b,&c);
    printf("100\n");
    for(int i=1;i<=50;i++)printf("%d ",a);
    for(int i=1;i<=45;i++)printf("%d ",b);
    for(int i=1;i<=4;i++)printf("%d ",c);
    printf("%d",c+1);
    return 0;
}