码迷,mamicode.com
首页 > 其他好文 > 详细

CF Gym 100500C ICPC Giveaways

时间:2015-07-27 20:45:54      阅读:111      评论:0      收藏:0      [点我收藏+]

标签:

读懂题意就是水题,按照出现次数对下标排一下序,暴力。。

#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
typedef long long ll;


const int maxn = 1e4+77;
ll cnt[maxn];
ll r[maxn];
bool cmp(int a,int b) { return cnt[a] > cnt[b]; }

int main()
{
    int T;
    scanf("%d",&T);
    for(int k = 1; k <= T; k++){
        int M,N,C;
        scanf("%d%d%d",&M,&N,&C);
        memset(cnt,0,sizeof(cnt));
        for(int i = 0; i < M; i++){
            int tmp;
            scanf("%d",&tmp);
            cnt[tmp]++;
        }
        for(int i = 0; i < N; i++) { r[i]  = i+1; }
        sort(r,r+N,cmp);
        ll amus = (r[0]*r[0])%C;
        ll best = cnt[r[0]]*amus;
        for(int i = 1; i < N; i++) {
            amus += (r[i]*r[i])%C;
            ll tmp = cnt[r[i]]*amus;
            best = max(best,tmp);
        }
        printf("Case %d: %I64d\n",k,best);
    }
    return 0;
}

 

CF Gym 100500C ICPC Giveaways

标签:

原文地址:http://www.cnblogs.com/jerryRey/p/4680838.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!