zoukankan      html  css  js  c++  java
  • 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 <cmath>
    #include <iostream>
    #include <cstring>
    #include <set>
    #include <queue>
    #include <algorithm>
    #include <vector>
    #include <map>
    #include <cctype>
    #include <stack>
    using namespace std ;
    
    typedef long long LL;
    typedef pair<int, int> P;
    const int INF = 0x3f3f3f3f;
    const double inf = 0x3f3f3f3f3f3f;
    const double PI = acos(-1.0);
    const double eps = 1e-8;
    const int maxn = 10 + 5;
    const int mod = 1e9 + 7;
    const char *mark = "+-*";
    const int dr[] = {0, 0, -1, 1};
    const int dc[] = {-1, 1, 0, 0};
    int n, m;
    inline bool is_in(int r, int c){
        return r >= 0 && r < n && c >= 0 && c < m;
    }
    int a[105];
    
    int main(){
        while(scanf("%d %d", &n, &m) == 2){
            memset(a, 0, sizeof(a));
            for(int i = 0; i < n; ++i){
                int x;
                scanf("%d", &x);
                ++a[x];
            }
            int x = n / m;
            int ans = 0;
            for(int i = 1; i <= m; ++i)
                ans += abs(x-a[i]);
            printf("%d
    ",ans/2);
        }
        return 0;
    }
    
  • 相关阅读:
    cocos2d游戏jsc文件格式解密,SpideMonkey大冒险
    抖音下载短视频去水印方法
    Metaspliot技术
    WAF bypass
    博客园美化
    Redis未授权访问利用
    网站后台getshell
    OpenVAS
    跨站脚本攻击与防御总结
    相同浏览器同一浏览器多用户登录问题
  • 原文地址:https://www.cnblogs.com/dwtfukgv/p/5758025.html
Copyright © 2011-2022 走看看