关闭

HDU 5210

标签: HDU
174人阅读 评论(0) 收藏 举报
分类:

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<N100).

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

The third line contains one integer K(0K<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 然后输入一个 长度为n的数组,然后输入一个k ,如果k大于这个数组里面数字重复的数字就输出

System.out.println(n -num- (k - num));//num是数组不同数字的数字

反之直接输出这个数组的不同数字的个数

思路: 贪心 水题


import java.util.Scanner;

public class Main{
    private static int n = 0, k = 0, num = 0;
    private static int[] array;
    private static int[] resArray;
    public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    while (scanner.hasNext()) {
        num = 0;
        n = scanner.nextInt();
        array = new int[n];
        resArray = new int[n];
        for (int i = 0; i < n; i++) {
        int temp = scanner.nextInt();
        if (judge(temp)) {
            array[i] = temp;
        } else {
            resArray[i] = temp;
            num++;
        }
        }
        k = scanner.nextInt();
        if (k <= num) {
        System.out.println(n - num);
        } else {
        System.out.println(n -num- (k - num));
        }

    }
    scanner.close();
    }

    private static boolean judge(int x) {
    for (int i = 0; i < array.length; i++) {
        if (array[i] == x) {
        return false;
        }
    }
    return true;
    }

}
0
0
查看评论

SQL Server 附加数据库 错误5210

那天在弄机房的时候,附加数据库总是附加不上,然而将附加数据库文件放到优盘里,就可以附加成功。我也不知道为什么了,但是这次还是别 将就了。于是乎,上网查了查原来是权限不够啊。这可怎么办,见下面三种方法: 【方法一】 设置mdf文件夹下的权限,在文件夹上右击——属性——安全,如图所示: &#...
  • zlt995768025
  • zlt995768025
  • 2015-06-20 09:35
  • 2560

hdu 5210

hdu 5210 简单的代码,但是不明白为什么不memset就出错
  • u013956878
  • u013956878
  • 2015-05-01 00:38
  • 193

hdu 5210 Delete

best code 2015/4/26 第一题,简直水的不行   问题描述 wld有n个数(a1,a2,...,an),他希望进行k次删除一个数的操作,使得最后剩下的n−k个数中有最多的不同的数,保证1≤n≤100,0≤kn,1≤ai≤n(对于任意1≤i≤n) 输入描述 ...
  • zafkiel_nightmare
  • zafkiel_nightmare
  • 2015-04-27 13:35
  • 649

HDU 5210 Delete

比赛的时候,yy的贪心策略错了,wa了6次(哭瞎) 正确的贪心策略是,先把重复的数字的个数跟删除操作的次数比较,如果小于等于重复数字的个数,则在集合内的个数就是答案,如果大于重复数字的个数,那就在集合中删数,最后输出集合的剩余个数 #include #include #include #i...
  • u013617636
  • u013617636
  • 2015-04-30 08:24
  • 262

hdu 5210 Delete(set)

Delete Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 209  &...
  • xky1306102chenhong
  • xky1306102chenhong
  • 2015-04-27 23:37
  • 321

HDU 5210 DELETE

题目链接:delete 题面: Delete Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submi...
  • David_Jett
  • David_Jett
  • 2015-06-04 22:36
  • 544

MOXA NPort5210 串口设备联网服务器

 
  • nport5110
  • nport5110
  • 2008-03-20 14:15
  • 474

sqlserver2012 Microsoft SQL Server,错误: 5120

标题: Microsoft SQL Server Management Studio ------------------------------ 附加数据库 对于 服务器“PC-20131005ROZP”失败。  (Microsoft.SqlServer.Smo) ...
  • yzw945
  • yzw945
  • 2014-05-25 19:09
  • 281

hdu 5210 Greatest Greatest Common Divisor

Greatest Greatest Common Divisor Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submiss...
  • qq_24451605
  • qq_24451605
  • 2015-06-06 23:28
  • 205

youbot在ROS中启动youbot_driver_ros_interface中遇到的问题

youbot在ROS中启动youbot_driver_ros_interface中遇到下面的报错: [ INFO] [1480844087.022008325]: 9 EtherCAT slaves found [ INFO] [1480844087.035314211]: BaseLeftFro...
  • qingdu007
  • qingdu007
  • 2016-12-04 18:05
  • 531
    个人资料
    • 访问:112175次
    • 积分:1387
    • 等级:
    • 排名:千里之外
    • 原创:41篇
    • 转载:3篇
    • 译文:0篇
    • 评论:32条
    博客专栏
    最新评论