ZOJ3519 BIT1004 Who is the Smartest Man

题意:

曹操要成为最聪明的人,输入的第一行的两个数据,第一个是他的对手的数量,第二个是他的IP

然后列出所有对手的IP,假设曹操战胜比他IP高的人,他的IP就加2,否则加1

并且假设曹操一定胜利,求曹操打赢这些人之后的最高的IP

解法:

很简单的贪心思想,将每个对手的IP排序一下,每次找到IP比他的高的人中的IP最小的那个,战胜他

最后没有比他IP高的了,再将剩下的人一一击败,一个for循环就搞定了

#include<iostream>
#include<algorithm>
#include<cstdio>
using namespace std;
int a[550];
int n,IP;
int counter;
int main()
{
	while(~scanf("%d %d",&n,&IP))
	{
		counter=0;
		for(int i=0;i<n;i++)
		{
			scanf("%d",&a[i]);
		}
		sort(a,a+n);
		for(int i=0;i<n;i++)
		{
			if(a[i]>IP)
			{
				counter++;
				IP+=2;
			}
		}
		printf("%d\n",IP+n-counter);
	}
	return 0;
}


你可能感兴趣的:(ZOJ3519 BIT1004 Who is the Smartest Man)