zoukankan      html  css  js  c++  java
  • hdu 5210 delete 水题

    Delete

    Time Limit: 1 Sec  Memory Limit: 256 MB

    题目连接

    http://acm.hdu.edu.cn/showproblem.php?pid=5210

    Description

    wld有n个数(a1,a2,...,an),他希望进行k次删除一个数的操作,使得最后剩下的n−k个数中有最多的不同的数,保证1≤n≤100,0≤k<n,1≤ai≤n(对于任意1≤i≤n)

    Input

    多组数据(最多100组)
    对于每组数据:
    第一行:一个数n表示数的个数
    接下来一行:n个数,依次为a1,a2,…,an
    接下来一行:一个数k表示操作数

    Output

    对于每组数据:
    输出最多剩下的不同的数的个数

    Sample Input

    4
    1 3 1 2
    1

    Sample Output

    3

    HINT

    题意

    题解:

    最简单的做法就是按照数量排序,然后贪心做就好了~

    不过水题,各有各的水法

    代码:

    //qscqesze
    #include <cstdio>
    #include <cmath>
    #include <cstring>
    #include <ctime>
    #include <iostream>
    #include <algorithm>
    #include <set>
    #include <vector>
    #include <sstream>
    #include <queue>
    #include <typeinfo>
    #include <fstream>
    #include <map>
    #include <stack>
    typedef long long ll;
    using namespace std;
    //freopen("D.in","r",stdin);
    //freopen("D.out","w",stdout);
    #define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
    #define maxn 200001
    #define mod 10007
    #define eps 1e-9
    int Num;
    char CH[20];
    //const int inf=0x7fffffff;   //нчоч╢С
    const int inf=0x3f3f3f3f;
    /*
    
    inline void P(int x)
    {
        Num=0;if(!x){putchar('0');puts("");return;}
        while(x>0)CH[++Num]=x%10,x/=10;
        while(Num)putchar(CH[Num--]+48);
        puts("");
    }
    */
    //**************************************************************************************
    inline ll read()
    {
        int x=0,f=1;char ch=getchar();
        while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
        while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
        return x*f;
    }
    inline void P(int x)
    {
        Num=0;if(!x){putchar('0');puts("");return;}
        while(x>0)CH[++Num]=x%10,x/=10;
        while(Num)putchar(CH[Num--]+48);
        puts("");
    }
    
    int a[101];
    int main()
    {
        int n;
        while(scanf("%d",&n)!=EOF)
        {
            for(int i=1;i<=n;i++)
                a[i]=0;
            for(int i=1;i<=n;i++)
            {
                int tmp=read();
                a[tmp]=1;
            }
            int k=read();
            k=n-k;
            int ans=0;
            for(int i=1;i<=n;i++)
            {
                if(a[i])
                    ans++;
            }
            P(min(ans,k));
        }
    }
  • 相关阅读:
    .net 自带的oracleclient 的一点小问题
    重新感受Windows 的激情
    三点定面的算法实现
    回归.NET的世界
    .NET 基础题, 可以做面试题, 不断更新 20111
    C#根据字符串生成唯一的数字
    最近看的书
    代码中的注释, 需要面向功能注释,而非使用注释
    html 页面嵌入 Silverlight , Silverlight控件覆盖悬浮HTML元素的解决方法.
    gitlab clone或者pull 仓库
  • 原文地址:https://www.cnblogs.com/qscqesze/p/4458550.html
Copyright © 2011-2022 走看看