题目传送门

 /*
贪心水题:找出出现次数>1的次数和res,如果要减去的比res小,那么总的不同的数字tot不会少;
否则再在tot里减去多余的即为答案
用set容器也可以做,思路一样
*/
#include <cstdio>
#include <iostream>
#include <cstring>
#include <string>
#include <algorithm>
using namespace std; const int MAXN = 1e4 + ;
const int INF = 0x3f3f3f3f;
int cnt[]; int main(void) //BestCoder Round #39 1001 Delete
{
//freopen ("1001.in", "r", stdin); int n;
while (scanf ("%d", &n) == )
{
int k;
memset (cnt, , sizeof (cnt)); int tot = , res = , x;
for (int i=; i<=n; ++i)
{
scanf ("%d", &x);
if (cnt[x] == ) tot++;
else if (cnt[x] >= ) res++;
cnt[x]++;
} scanf ("%d", &k);
if (res >= k) printf ("%d\n", tot);
else printf ("%d\n", tot - (k - res));
} return ;
}

 #include <cstdio>
#include <iostream>
#include <cstring>
#include <string>
#include <algorithm>
#include <set>
using namespace std; int main(void) //BestCoder Round #39 1001 Delete
{
//freopen ("1001.in", "r", stdin); set<int> S;
int n, k; while (cin >> n)
{
S.clear ();
int x;
for (int i=; i<=n; ++i)
{
cin >> x; S.insert (x);
} cin >> k;
cout << ((n-S.size () <= k) ? n - k : S.size ()) << endl;
} return ;
}

使用set容器

贪心 BestCoder Round #39 1001 Delete的更多相关文章

  1. 暴力+降复杂度 BestCoder Round #39 1002 Mutiple

    题目传送门 /* 设一个b[]来保存每一个a[]的质因数的id,从后往前每一次更新质因数的id, 若没有,默认加0,nlogn复杂度: 我用暴力竟然水过去了:) */ #include <cst ...

  2. 暴力 BestCoder Round #41 1001 ZCC loves straight flush

    题目传送门 /* m数组记录出现的花色和数值,按照数值每5个搜索,看看有几个已满足,剩下 5 - cnt需要替换 ╰· */ #include <cstdio> #include < ...

  3. 暴力 BestCoder Round #46 1001 YJC tricks time

    题目传送门 /* 暴力:模拟枚举每一个时间的度数 详细解释:http://blog.csdn.net/enjoying_science/article/details/46759085 期末考结束第一 ...

  4. 字符串处理 BestCoder Round #43 1001 pog loves szh I

    题目传送门 /* 字符串处理:是一道水题,但是WA了3次,要注意是没有加'\0'的字符串不要用%s输出,否则在多组测试时输出多余的字符 */ #include <cstdio> #incl ...

  5. BestCoder Round #75 1001 - King's Cake

    Problem Description It is the king's birthday before the military parade . The ministers prepared a ...

  6. BestCoder Round #39 解题报告

    现场只做出前三题w 不过不管怎样这既是第一次认真打BC 又是第一次体验用在线编译器调代码 订正最后一题花了今天一整个下午(呜呜 收获还是比较大的^_^ Delete wld有n个数(a1,a2,... ...

  7. BestCoder Round #92 1001 Skip the Class —— 字典树 or map容器

    题目链接:http://bestcoder.hdu.edu.cn/contests/contest_showproblem.php?cid=748&pid=1001 题解: 1.trie树 关 ...

  8. BestCoder Round #39

    -------好久没更新博客了,发现还是需要不断总结才能进步,所以还是把最近打的一些比赛记录一下. T1:Delete (hdu 5210) 题目大意: 给出n个数,然后要删掉k个,要求剩下的数中 不 ...

  9. BestCoder Round #61 1001 Numbers

    Problem Description There are n numbers A1,A2....An{A}_{1},{A}_{2}....{A}_{n}A​1​​,A​2​​....A​n​​,yo ...

随机推荐

  1. hdu.5195.DZY Loves Topological Sorting(topo排序 && 贪心)

    DZY Loves Topological Sorting Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 ...

  2. cf.295.B Two Buttons (bfs)

     Two Buttons time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...

  3. java笔记--使用线程池优化多线程编程

    使用线程池优化多线程编程 认识线程池 在Java中,所有的对象都是需要通过new操作符来创建的,如果创建大量短生命周期的对象,将会使得整个程序的性能非常的低下.这种时候就需要用到了池的技术,比如数据库 ...

  4. DNS服务器配置

    导读 DNS(Domain Name Server,域名服务器)是进行域名(domain name)和与之相对应的IP地址 (IP address)转换的服务器.DNS中保存了一张域名(domain ...

  5. 疯狂抨击ie6下各种扭曲行为

    从开始接触ie6就被它强大的力量给震住了,虽然它很可怕,但是我总归得想方设法把它给扼杀在摇篮外.以下是我在ie6下面碰到的一些扭曲行为,弱弱的把它给干掉!!! 1.浮动下margin翻倍问题(很典型, ...

  6. sql注入之你问我答小知识

    /*每日更新,珍惜少年时博客*/ 1.问:为啥order by 是排序.而在注入当中后面加的却不是字段而是数字捏? 答:第N个字段嘛.order by 5就是第五个字段,如果5存在,6不存在.就说明只 ...

  7. Linux Apache和Nginx网络模型详解

    进程阻塞和挂起的定义: 阻塞是由于进程所需资源得不到满足,并会最终导致进程被挂起     进程挂起的原因并不一定是由于阻塞,也有可能是时间片得不到满足,挂起状态是进程从内存调度到外存中的一种状态,若在 ...

  8. Floyd算法 及其运用

    #include<stdio.h> ][]; ][]; void floyd(int n) { ;k<=n;k++) { ;i<=n;i++) { ;j<=n;j++) ...

  9. Linux 系统安全 抵御TCP的洪水

    抵御TCP的洪水 分类: LINUX tcp_syn_retries :INTEGER默认值是5对 于一个新建连接,内核要发送多少个 SYN 连接请求才决定放弃.不应该大于255,默认值是5,对应于1 ...

  10. abstract class和interface的区别

    1. 引言 2. 概念引入 ●什么是接口? 接口是包含一组虚方法的抽象类型,其中每一种方法都有其名称.参数和返回值.接口方法不能包含任何实现,CLR允许接口可以包含事件.属性.索引 器.静态方法.静态 ...