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));
        }
    }
  • 相关阅读:
    jquery 滚动条插件 jquery.nanoscroller.js
    Lost connection to MySQL server at 'reading initial communication packet' 错误解决
    ajax上传图片 jquery插件 jquery.form.js 的方法 ajaxSubmit; AjaxForm与AjaxSubmit的差异
    转:MVC3系列:~Html.BeginForm与Ajax.BeginForm
    转:MVC2表单验证失败后,直接返回View,已填写的内容就会清空,可以这样做;MVC2输出文本;MVC2输出PDF文件
    Java中的Dom4j
    Java插件之Jrebel
    Idea中的一些快捷键
    Java中的XML
    SQL Server 表值函数
  • 原文地址:https://www.cnblogs.com/qscqesze/p/4458550.html
Copyright © 2011-2022 走看看