Lottery - CodeForces 589I(水)

题目大意:有N个球K个人,现在要给这N个球涂上K种颜色,要求使抽到球的不同颜色的概率一致(N确保是K的倍数),求出来至少要给多少个球重新涂上颜色。

分析:先求出来所有球的每种颜色的个数,然后不到平均数的加上距离平均数的个数即可。

代码如下:

--------------------------------------------------------------------------------------------------------------------------------------

#include<stdio.h>
#include<string.h>

const int MAXN = 107;

int color[MAXN];

int main()
{
    int N, K, ci;

    while(scanf("%d%d", &N, &K) != EOF)
    {
        memset(color, 0, sizeof(color));

        for(int i=0; i<N; i++)
        {
            scanf("%d", &ci);
            color[ci] += 1;
        }

        int ave = N/K, ans=0;

        for(int i=1; i<=K; i++)
        {
            if(color[i] < ave)
                ans += ave - color[i];
        }

        printf("%d\n", ans);
    }

    return 0;
}
时间: 2025-01-07 03:27:50

Lottery - CodeForces 589I(水)的相关文章

CodeForces 589I Lottery (暴力,水题)

题意:给定 n 和 k,然后是 n 个数,表示1-k的一个值,问你修改最少的数,使得所有的1-k的数目都等于n/k. 析:水题,只要用每个数减去n/k,然后取模,加起来除以2,就ok了. 代码如下: #pragma comment(linker, "/STACK:1024000000,1024000000") #include <cstdio> #include <string> #include <cstdlib> #include <cma

Pearls in a Row CodeForces 620C 水题

题目:http://codeforces.com/problemset/problem/620/C 文章末有一些测试数据仅供参考 题目大意:就是给你一个数字串,然后将分成几个部分,要求每个部分中必须有一对儿相等的数字,每个数字都属于某个部分,输出划分的部分数量以及对应区间. 很简单一道题,输入的数据都不用存的,输入一个检测一个就好了,用map打标记,用容器存一下要输出的区间端点值,最后挨个儿输出就好了 代码如下: #include<iostream> #include<map> #

CodeForces 520C 水构造

//520C - DNA Alignment 1 #include "iostream" 2 #include "cstdio" 3 using namespace std; 4 const __int64 mod = 1e9 + 7; 5 int n; 6 char str[100010]; 7 int Count[5]; 8 9 __int64 bin(__int64 n, __int64 k) 10 { 11 __int64 res = 1; 12 while

Codeforces 734C [水][暴力][贪心]

题意: 要生产n个物品,每个花费时间为x. 有两种魔法,每种最多使用1个. 其中第一种魔法可以使每个物品生产的花费时间变为ai,相应的花费是bi;第二种魔法可以减少ci个物品,相应的花费是di,并且保证对于i<j ci<=cj 且 di<=dj; #include<bits/stdc++.h> using namespace std; long long b[200050],c[200050],d[200050]; pair<long long ,long long&g

Army Creation CodeForces - 813E (水题)

题意: 给定序列, 每次询问一个区间[l,r], 问[l,r]中最多能选多少个数且每种数字不超过k 相当于加强版 HH的项链, 对于一个数t, 主席树维护上k次出现的位置pre[t], 每次查询相当于求区间内pre<左端点的总数 #include <iostream> #include <queue> #define REP(i,a,n) for(int i=a;i<=n;++i) #define mid ((l+r)>>1) using namespace

codeforces 589 I - Lottery(水)

I - Lottery Time Limit:2000MS     Memory Limit:524288KB     64bit IO Format:%I64d & %I64u Submit Status Practice CodeForces 589I Description Today Berland holds a lottery with a prize — a huge sum of money! There are k persons, who attend the lottery

Codeforces Round #367 (Div. 2)

A. Beru-taxi (Codeforces 706A) 水题,求一下到每个点的距离,取最小值即可 #include<stdio.h> #include<string.h> #include<math.h> #include<algorithm> #define N using namespace std; int n,x,y,p,q,s; double t,ans=1000000000; int main() { scanf("%d%d%d&

Minimum Integer CodeForces - 1101A (思维+公式)

You are given qq queries in the following form: Given three integers lili, riri and didi, find minimum positive integer xixi such that it is divisible by didi and it does not belong to the segment [li,ri][li,ri]. Can you answer all the queries? Recal

Theatre Square 题解代码

Theatre Square CodeForces - 1A 水题水题... 最开始的程序是这个,可是AC不了我也不知道为什么......QAQ... #include <stdio.h>#include<stdlib.h>int main(){    int m,n,a,ans,tmp,k,h,tep,i,j;    scanf("%d %d %d",&m,&n,&a);    if(m%a==0)    {        if(n%a