hdu 5210 Delete(set)

Delete

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)

Total Submission(s): 209    Accepted Submission(s): 142

Problem Description

WLD likes playing with numbers. One day he is playing with
N
integers. He wants to delete K
integers from them. He likes diversity, so he wants to keep the kinds of different integers as many as possible after the deletion. But he is busy pushing, can you help him?

Input

There are Multiple Cases. (At MOST
100)

For each case:

The first line contains one integer N(0<N≤100).

The second line contains N
integers a1,a2,...,aN(1≤ai≤N),
denoting the integers WLD plays with.

The third line contains one integer K(0≤K<N).

Output

For each case:

Print one integer. It denotes the maximum of different numbers remain after the deletion.

Sample Input

4
1 3 1 2
1

Sample Output

3

Hint

if WLD deletes a 3, the numbers remain is [1,1,2],he‘ll get 2 different numbers.
if WLD deletes a 2, the numbers remain is [1,1,3],he‘ll get 2 different numbers.
if WLD deletes a 1, the numbers remain is [1,2,3],he‘ll get 3 different numbers.

题意:

从n个数中删k个数,求剩下的数中最多有多少个不同的数

代码:
#include<cstdio>
#include<set>
using namespace std;

int a[105];

int main()
{
    set<int> st;
    int n;
    while(scanf("%d",&n)==1)
    {
        st.clear();
        for(int i=0;i<n;i++)
        {
            scanf("%d",&a[i]);
            st.insert(a[i]);
        }
        int cnt=n-st.size();
        int k;
        scanf("%d",&k);
        if(k<=cnt)
            printf("%d\n",st.size());
        else
            printf("%d\n",st.size()-k+cnt);
    }
    return 0;
}
时间: 2024-08-28 10:02:48

hdu 5210 Delete(set)的相关文章

HDU - 5210 - Delete &amp;&amp; 5211 - Mutiple (BestCoder Round #39)

题目传送:HDU - 5210 HDU - 5210 - Delete 思路:简单题 AC代码: #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #include <cmath> #include <queue> #include <stack> #include <vector> #include &l

[ACM] hdu 1260 Tickets (动态规划)

Tickets Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other) Total Submission(s) : 4   Accepted Submission(s) : 2 Font: Times New Roman | Verdana | Georgia Font Size: ← → Problem Description Jesus, what a great movie! Thou

hdu 4296 Buildings(贪心)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4296 Buildings Time Limit: 5000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1822    Accepted Submission(s): 722 Problem Description Have you ever heard the sto

HDU 4816 Bathysphere(数学)(2013 Asia Regional Changchun)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4816 Problem Description The Bathysphere is a spherical deep-sea submersible which was unpowered and lowered into the ocean on a cable, and was used to conduct a series of dives under the sea. The Bathys

hdu 1494 跑跑卡丁车(动态规划)

Problem Description 跑跑卡丁车是时下一款流行的网络休闲游戏,你可以在这虚拟的世界里体验驾驶的乐趣.这款游戏的特别之处是你可以通过漂移来获得一种加速卡,用这种加速卡可以在有限的时间里提高你的速度.为了使问题简单化,我们假设一个赛道分为L段,并且给你通过每段赛道的普通耗时Ai和用加速卡的耗时Bi.加速卡的获得机制是:普通行驶的情况下,每通过1段赛道,可以获得20%的能量(N2O).能量集满后获得一个加速卡(同时能量清0).加速卡最多可以储存2个,也就是说当你有2个加速卡而能量再次

HDU 5826 physics(物理)

HDU 5826 physics(物理) Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)   Description 题目描述 There are n balls on a smooth horizontal straight track. The track can be considered to be a number line. The balls can be con

hdu 4864 Task (贪心)

# include <stdio.h> # include <algorithm> # include <string.h> using namespace std; struct node { int t; int v; int yy; }; struct node a[100010],b[100010]; bool cmp(node a1,node a2) { if(a1.t==a2.t)//先按时间从大到小 return a1.v>a2.v;//再按水平从大

HDU 4832 Chess (DP)

Chess Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 24    Accepted Submission(s): 10 Problem Description 小度和小良最近又迷上了下棋.棋盘一共有N行M列,我们可以把左上角的格子定为(1,1),右下角的格子定为(N,M).在他们的规则中,"王"在棋盘上的走法遵循十字路线.

hdu 3123 GCC(数学题)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3123 GCC Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) Total Submission(s): 3808    Accepted Submission(s): 1234 Problem Description The GNU Compiler Collection (u