HDU ACM 5210 Delete 水题

题意:有n个数(a1,a2,...,an),进行k次删除一个数的操作,使得剩下的n-k个数中有最多的不同的种数。输出最多剩下的不同的数的种数。

#include<iostream>
using namespace std;

int main()
{
	int map[105];
	int i,n,k,sum,a;

	while(cin>>n)
	{
		sum=0;
		memset(map,0,sizeof(map));
		for(i=0;i<n;i++)
		{
			cin>>a;
			if(!map[a]) sum++;  //sum是不同的数的种数
			map[a]++;
		}
		cin>>k;
		k-=(n-sum);
		if(k<=0)               //删除k个数后种数没有减少
			cout<<sum<<endl;
		else                   //种数减少
			cout<<sum-k<<endl;
	}
    return 0;
}
时间: 2024-08-03 11:47:08

HDU ACM 5210 Delete 水题的相关文章

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表示数的个数接下来一行:

简单的dp hdu 数塔(水题)

数塔 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 21314    Accepted Submission(s): 12808 Problem Description 在讲述DP算法的时候,一个经典的例子就是数塔问题,它是这样描述的: 有如下所示的数塔,要求从顶层走到底层,若每一步只能走到相邻的结点,则经过的结点的数字之和最大是多少

hdu 2053 Switch Game 水题一枚,鉴定完毕

Switch Game Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 10200    Accepted Submission(s): 6175 Problem Description There are many lamps in a line. All of them are off at first. A series of op

HDU 2090 算菜价 --- 水题

/* HDU 2090 算菜价 --- 水题 */ #include <cstdio> int main() { char s[105]; double a, b, sum = 0; while (scanf("%s", s)==1){ scanf("%lf%lf", &a, &b); a *= b; sum += a; } printf("%.1f\n", sum); return 0; }

HDU 2091 空心三角形 --- 水题

/* HDU 2091 空心三角形 --- 水题 */ #include <cstdio> int main() { int kase = 0; char ch; int h, t; //h表示高 while (scanf("%c", &ch) == 1 && ch != '@'){ scanf("%d", &h); if (kase++){ printf("\n"); } getchar(); if

hdu 2212 DFS(水题)

DFS Time Limit: 5000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 4923    Accepted Submission(s): 3029 Problem Description A DFS(digital factorial sum) number is found by summing the factorial of every digit

hdu 5007(字符串水题)

题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=5007 Post Robot Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 327    Accepted Submission(s): 253 Problem Description DT is a big fan of digital

HDOJ/HDU 2560 Buildings(嗯~水题)

Problem Description We divide the HZNU Campus into N*M grids. As you can see from the picture below, the green grids represent the buidings. Given the size of the HZNU Campus, and the color of each grid, you should count how many green grids in the N

HDU 3316 爆搜水题

爆搜水题 模拟扫雷,规则和扫雷一样 给出原图,求在X,Y位置点一下以后的图形,没有弹出的点输出-1,弹出的点输出这个点的数字 从起始点DFS一下即可 #include "stdio.h" #include "string.h" int dir[8][2]={ {-1,0},{-1,1},{0,1},{1,1},{1,0},{1,-1},{0,-1},{-1,-1} }; int n; int hash[110][110]; char str[110][110]; i