题目传送门

 /*
贪心水题:找出出现次数>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. Android第三方jar包ClassNotFind

    转载请注明http://www.cnblogs.com/vanezkw/archive/2012/06/25/2561393.html 相信很多朋友在使用第三方包时都遇到过此类问题.今天就此问题进行一 ...

  2. error LNK2038: 检测到“_ITERATOR_DEBUG_LEVEL”的不匹配项:值“0”不匹配值“2”

    error: vtkCommon.lib(vtkSmartPointerBase.obj) : error LNK2038: 检测到“_ITERATOR_DEBUG_LEVEL”的不匹配项:值“0”不 ...

  3. Tomcat ClassLoader机制介绍

    本文旨在介绍JVM的类加载机制:同时分析Tomcat不能采用默认的加载机制的原因,并对其加载机制做了介绍. 1.JVM中的类加载机制 在Java2之后的版本中,类的加载采用的是一种称为双亲委派的代理模 ...

  4. Centos 7 安装LAMP环境

    一.安装Centos 官网下载Centos 7刻录成光盘后安装 二.安装apache yum install httpd #根据提示,输入Y安装即可成功安装 systemctl start httpd ...

  5. HDOJ 1863 prim算法 HDOJ 1879

    #include<cstdio> #include<cstring> #define inf 0xffffff ][]; int ans; void prim(int n) { ...

  6. ubuntu14.04安装OpenVirteX

    官网链接: http://ovx.onlab.us/getting-started/installation/ step1: System requirements: Recommended 4 Co ...

  7. 【SpringMVC】SpringMVC系列9之Model数据返回到View

    9.Model数据返回到View 9.1.概述     Spring MVC 提供了以下几种途径输出模型数据: ModelAndView: 处理方法返回值类型为 ModelAndView 时, 方法体 ...

  8. 算法:comparable比较器的排序原理实现(二叉树中序排序)

    Comparable比较器排序远离实现 package test.java.api.api13; /** * 手工实现二叉树的比较算法: 第一遍感觉很神秘,但是真正自己写下来,就感觉很简单,理解就好: ...

  9. Dynamic Web Module 3.0 requires Java 1.6 or newer

    在maven工程的pom.xml文件中加入如下代码: 在<build>里面加入如下代码: <plugins> <plugin> <groupId>org ...

  10. TinyMCE textarea 输入框外部程序动态修改方法

    TinyMCE textarea 输入框外部程序动态修改方法 Public Function C2IE_TINYMCE(ByVal id As String, ByVal value As Strin ...