我是靠谱客的博主 有魅力钢笔,这篇文章主要介绍lightoj 1148 - Mad Counting 简单数学,现在分享给大家,希望可以做个参考。

统计人数,询问了n个人每个人都回答了除了自己外支持同一球队的其他人数是多少,问最小有多少人。

统计每个数字出现多少次,有a[i]+1个人回答的一样可以刚好组成一个团体...如果有剩余的话也是一个新的团体。

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define mod 1000007
#define inf 0x3f3f3f3f
#define N 100100
using namespace std;
int a[50];
int main()
{
int t;
scanf("%d",&t);
for(int cas=1; cas<=t; cas++)
{
int n;
scanf("%d",&n);
for(int i=0;i<n;i++)
scanf("%d",&a[i]);
sort(a,a+n);
a[n]=-1;
int ans=0,cnt;
for(int i=0;i<n;i++)
{
cnt=1;
while(a[i]==a[i+1])
i++,cnt++;
ans+=(cnt/(a[i]+1))*(a[i]+1)+(cnt%(a[i]+1)==0?0:a[i]+1);
}
printf("Case %d: %dn",cas,ans);
}
return 0;
}


最后

以上就是有魅力钢笔最近收集整理的关于lightoj 1148 - Mad Counting 简单数学的全部内容,更多相关lightoj内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(70)

评论列表共有 0 条评论

立即
投稿
返回
顶部