hdoj 5210 Delete 【水题】

来源:互联网 发布:ios运行windows程序 编辑:程序博客网 时间:2024/06/05 18:47

题目链接:hdoj 5210 Delete

Delete

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 1049 Accepted Submission(s): 509

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

#include <cstdio>#include <iostream>#include <algorithm>#include <cstring>#define CLR(a, b) memset(a, (b), sizeof(a))using namespace std;typedef long long LL;const int INF = 0x3f3f3f3f;const int MAXN = 1e5 + 10;bool vis[110];int main(){    int n;    while(scanf("%d", &n) != EOF) {        CLR(vis, false); int sum1 = 0, sum2 = 0;        for(int i = 0; i < n; i++) {            int v; scanf("%d", &v);            if(!vis[v]) {                sum1++;                vis[v] = true;            }            else {                sum2++;            }        }        int k; scanf("%d", &k);        int ans;        if(k <= sum2) {            ans = sum1;        }        else {            k -= sum2;            ans = sum1 - k;        }        printf("%d\n", ans);    }    return 0;}
0 0