当前位置: 首页 > news >正文

LightOJ - 1148 - Mad Counting

先上题目:

1148 - Mad Counting
 PDF (English)StatisticsForum
Time Limit: 0.5 second(s)Memory Limit: 32 MB

Mob was hijacked by the mayor of the Town "TruthTown". Mayor wants Mob to count the total population of the town. Now the naive approach to this problem will be counting people one by one. But as we all know Mob is a bit lazy, so he is finding some other approach so that the time will be minimized. Suddenly he found a poll result of that town where N people were asked "How many people in this town other than yourself support the same team as you in the FIFA world CUP 2010?" Now Mob wants to know if he can find the minimum possible population of the town from this statistics. Note that no people were asked the question more than once.

Input

Input starts with an integer T (≤ 100), denoting the number of test cases.

Each case starts with an integer N (1 ≤ N ≤ 50). The next line will contain N integers denoting the replies (0 to 106) of the people.

Output

For each case, print the case number and the minimum possible population of the town.

Sample Input

Output for Sample Input

2

4

1 1 2 2

1

0

Case 1: 5

Case 2: 1

 

  基础题,告诉你一个村子里面,某n个人支持他们支持的球队的村民(除了他自己以外)还有多少人,问村子里面至少有多少人。

  不多说,分析一下就可以出结果。

 

上代码:

 1 #include <cstdio>
 2 #include <cstring>
 3 #include <algorithm>
 4 #include <utility>
 5 #define MAX 1000002
 6 #define ll long long
 7 using namespace std;
 8 
 9 typedef pair<ll,int> pii;
10 
11 ll s[52];
12 pii p[52];
13 
14 int main()
15 {
16     int n,t,x,lo;
17     ll ans;
18     //freopen("data.txt","r",stdin);
19     scanf("%d",&t);
20     for(int z=1;z<=t;z++){
21         scanf("%d",&n);
22         for(int i=0;i<n;i++){
23             scanf("%d",&x);
24             s[i]=x+1;
25         }
26         sort(s,s+n);
27         memset(p,0,sizeof(p));
28         lo=0;
29         p[0].first=s[0];    p[0].second=1;
30         for(int i=1;i<n;i++){
31             if(p[lo].first==s[i]) p[lo].second++;
32             else{
33                 lo++; p[lo].first=s[i]; p[lo].second=1;
34             }
35         }
36         ans=0;
37         for(int i=0;i<=lo;i++){
38             if(p[i].first==p[i].second) ans+=p[i].second;
39             else if(p[i].first<p[i].second){
40                 ans+=p[i].second/p[i].first*p[i].first;
41                 if(p[i].second%p[i].first!=0) ans+=p[i].first;
42             }else{
43                 ans+=p[i].first;
44             }
45         }
46         printf("Case %d: %lld\n",z,ans);
47     }
48     return 0;
49 }
/*1148*/

 

 

转载于:https://www.cnblogs.com/sineatos/p/3905604.html

相关文章:

  • ubuntu里打开rar,zip文件方法
  • class 的使用
  • ViewSwitcher的功能和用法
  • 承上启下——牛腩新闻发布系统总结
  • Hyper Prefix Sets
  • Autofac
  • get和post请求的设置
  • 第二届360杯全国大学生信息安全技术大赛部分解题思路(数字取证)
  • php 获取请求参数
  • 关于Repeater嵌套绑定的问题
  • cefsharp设置默认语言
  • 华为2015校园招聘机试
  • c:if标签的使用
  • 字符串拼接 strcat ;数组和指针的区别
  • 概述
  • @jsonView过滤属性
  • 【跃迁之路】【444天】程序员高效学习方法论探索系列(实验阶段201-2018.04.25)...
  • 4. 路由到控制器 - Laravel从零开始教程
  • AWS实战 - 利用IAM对S3做访问控制
  • bootstrap创建登录注册页面
  • CSS 提示工具(Tooltip)
  • Javascript Math对象和Date对象常用方法详解
  • Laravel核心解读--Facades
  • Linux Process Manage
  • Linux快速配置 VIM 实现语法高亮 补全 缩进等功能
  • Python爬虫--- 1.3 BS4库的解析器
  • Python中eval与exec的使用及区别
  • React as a UI Runtime(五、列表)
  • 从0实现一个tiny react(三)生命周期
  • 读懂package.json -- 依赖管理
  • 开年巨制!千人千面回放技术让你“看到”Flutter用户侧问题
  • 坑!为什么View.startAnimation不起作用?
  • 那些被忽略的 JavaScript 数组方法细节
  • 如何将自己的网站分享到QQ空间,微信,微博等等
  • 数组的操作
  • !$boo在php中什么意思,php前戏
  • ${ }的特别功能
  • (JS基础)String 类型
  • (提供数据集下载)基于大语言模型LangChain与ChatGLM3-6B本地知识库调优:数据集优化、参数调整、Prompt提示词优化实战
  • (推荐)叮当——中文语音对话机器人
  • (转)编辑寄语:因为爱心,所以美丽
  • .gitignore文件_Git:.gitignore
  • .NET开发者必备的11款免费工具
  • .net实现客户区延伸至至非客户区
  • .so文件(linux系统)
  • ::before和::after 常见的用法
  • @Autowired注解的实现原理
  • [100天算法】-每个元音包含偶数次的最长子字符串(day 53)
  • [2018/11/18] Java数据结构(2) 简单排序 冒泡排序 选择排序 插入排序
  • [AIGC] Redis基础命令集详细介绍
  • [ajaxupload] - 上传文件同时附件参数值
  • [AX]AX2012 R2 出差申请和支出报告
  • [C/C++随笔] char与unsigned char区别
  • [CQOI 2011]动态逆序对
  • [Django开源学习 1]django-vue-admin