贪心 BestCoder Round #39 1001 Delete
题目传送门
1 /* 2 贪心水题:找出出现次数>1的次数和res,如果要减去的比res小,那么总的不同的数字tot不会少; 3 否则再在tot里减去多余的即为答案 4 用set容器也可以做,思路一样 5 */ 6 #include <cstdio> 7 #include <iostream> 8 #include <cstring> 9 #include <string> 10 #include <algorithm> 11 using namespace std; 12 13 const int MAXN = 1e4 + 10; 14 const int INF = 0x3f3f3f3f; 15 int cnt[110]; 16 17 int main(void) //BestCoder Round #39 1001 Delete 18 { 19 //freopen ("1001.in", "r", stdin); 20 21 int n; 22 while (scanf ("%d", &n) == 1) 23 { 24 int k; 25 memset (cnt, 0, sizeof (cnt)); 26 27 int tot = 0, res = 0, x; 28 for (int i=1; i<=n; ++i) 29 { 30 scanf ("%d", &x); 31 if (cnt[x] == 0) tot++; 32 else if (cnt[x] >= 1) res++; 33 cnt[x]++; 34 } 35 36 scanf ("%d", &k); 37 if (res >= k) printf ("%d\n", tot); 38 else printf ("%d\n", tot - (k - res)); 39 } 40 41 return 0; 42 }
1 #include <cstdio> 2 #include <iostream> 3 #include <cstring> 4 #include <string> 5 #include <algorithm> 6 #include <set> 7 using namespace std; 8 9 int main(void) //BestCoder Round #39 1001 Delete 10 { 11 //freopen ("1001.in", "r", stdin); 12 13 set<int> S; 14 int n, k; 15 16 while (cin >> n) 17 { 18 S.clear (); 19 int x; 20 for (int i=1; i<=n; ++i) 21 { 22 cin >> x; S.insert (x); 23 } 24 25 cin >> k; 26 cout << ((n-S.size () <= k) ? n - k : S.size ()) << endl; 27 } 28 29 return 0; 30 }
使用set容器
转载于:https://www.cnblogs.com/Running-Time/p/4459855.html
贪心 BestCoder Round #39 1001 Delete相关推荐
- 字符串处理 BestCoder Round #43 1001 pog loves szh I
题目传送门 1 /* 2 字符串处理:是一道水题,但是WA了3次,要注意是没有加'\0'的字符串不要用%s输出,否则在多组测试时输出多余的字符 3 */ 4 #include <cstdio&g ...
- BestCoder Round #39 解题报告
现场只做出前三题w 不过不管怎样这既是第一次认真打BC 又是第一次体验用在线编译器调代码 订正最后一题花了今天一整个下午(呜呜 收获还是比较大的^_^ Delete wld有n个数(a1,a2,... ...
- BestCoder Round #91 1001 Lotus and Characters
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6011 题意: Lotus有nn种字母,给出每种字母的价值以及每种字母的个数限制,她想构造一个任意长度的 ...
- HDU 5944 Fxx and string BestCoder Round #89 1001(细节)
Fxx and string Accepts: 213 Submissions: 1867 Time Limit: 2000/1000 MS (Java/Others) Memory Limi ...
- 贪心/二分查找 BestCoder Round #43 1002 pog loves szh II
题目传送门 1 /* 2 贪心/二分查找:首先对ai%=p,然后sort,这样的话就有序能使用二分查找.贪心的思想是每次找到一个aj使得和为p-1(如果有的话) 3 当然有可能两个数和超过p,那么an ...
- hdu4932 Miaomiao#39;s Geometry (BestCoder Round #4 枚举)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4932 Miaomiao's Geometry Time Limit: 2000/1000 MS (Ja ...
- 矩阵快速幂---BestCoder Round#8 1002
当要求递推数列的第n项且n很大时,怎么快速求得第n项呢? 可以用矩阵快速幂来加速计算. 我们可以用矩阵来表示数列递推公式 比如fibonacci数列 可以表示为 [f(n) f(n-1)] = [ ...
- hdu4585 amp; BestCoder Round #1 项目管理(vector应用)
主题链接:http://acm.hdu.edu.cn/showproblem.php?pid=4858 项目管理 Time Limit: 2000/1000 MS (Java/Others) M ...
- HDU 5228 ZCC loves straight flush( BestCoder Round #41)
题目链接:ZCC loves straight flush 题面: ZCC loves straight flush Time Limit: 2000/1000 MS (Java/Others) ...
最新文章
- 曾今的代码系列——获取当天最大流水号存储过程
- 【Flutter】底部导航栏实现 ( BottomNavigationBar 底部导航栏 | BottomNavigationBarItem 导航栏条目 | PageView )
- 在QT中结构体快速从二进制文件中读取数据
- .configure
- [Windows]_[0基础]_[使用命令行工具dumpbin分析文件]
- 数据中心传输需求成以太网市场巨大推动力
- Qt工作笔记-在ListWidget中多线程检索数据
- linux的安装方式(一)
- 定量库存控制模型_经济订货批量不是最终的订货批量,计算订货批量的最高库存定量法...
- c++程序设计原理与实践 第二十四章部分答案
- linux bind 源码,rpcbind 源码 分析
- 解决网站80端口被封,本地公网IP加速25mb/s网站访问速度
- Prolog入门教程(完整版+专家系统案例)
- BeyondCompare4.0比较代码内容相同但显示红色问题终结方案
- 学习SQLServer: 设置QUOTED_IDENTIFIER
- 互联网医院源码|互联网医院软件体现智慧医疗的优势
- 突发!继22岁拼多多女员工猝死后,又一悲剧:拼多多员工家中跳楼自杀!公司紧急通告!...
- 【记录】kali制作绕过火绒检测的木马(仅通过MSF的方式)
- 装饰设计模式缓冲流转换流序列化与反序列化
- shopee海外仓如何申请及 收 费 标 准
热门文章
- python高阶函数看不懂_Python进阶:高阶函数的详细说明
- 我的世界java 内存_我的世界如何分配内存
- Java写入磁盘阵列_磁盘阵列RAID介绍及计算公式
- 用matlab数学综合实验,MATLAB与数学实验(第2版)
- jquery 获取键值对中最大值_jQuery的AJAX发送数据键值对
- java object数组转实体类_详解Java中String JSONObject JSONArray List实体类转换
- 【youcans 的 OpenCV 例程 200 篇】112. 滤波反投影重建图像
- 我的Go+语言初体验——(2)IDE 详细安装教程
- youcans 的 OpenCV 学习课—1.安装与环境配置
- python输入逗号分隔_命令行Python逗号分隔的用户输入int值