UVa 11292 The Dragon of Loowater 勇者斗恶龙
2013-07-20 14:15
453 查看
拿下面这组数据进行模拟:
23 8 5
7 8 4
将数据排序之后如下:
龙头:58
骑士:478
第一轮匹配,从第一个头和第一个骑士开始。发现第一个骑士不能够砍掉第一个头。再匹配第一个头和第二个骑士,发现可以砍掉第一个头,所以雇佣这个骑士。
第二轮匹配,将第二个头和第三个骑士开始匹配(因为,第一个骑士连<=当前龙头的龙头都不能砍掉,就更不能砍掉后面的龙头),发现可以砍掉第二个头,所以雇佣这个骑士。
最后输出的结果为:
15
这道题目是一个非常简单的排序+贪心。
附AC代码:
#include<stdio.h>
#include<math.h>
#include<iostream>
#include<cstdarg>
#include<algorithm>
#include<string.h>
#include<stdlib.h>
#include<string>
#include<list>
#include<vector>
#include<map>
#defineLLlonglong
#defineM(a)memset(a,0,sizeof(a))
usingnamespacestd;
voidClean(intcount,...)
{
va_listarg_ptr;
va_start(arg_ptr,count);
for(inti=0;i<count;i++)
M(va_arg(arg_ptr,int*));
va_end(arg_ptr);
}
intd[20009],p[20009];
intmain()
{
intn,m,kill,pay;
while(~scanf("%d%d",&n,&m)&&(n||m))
{
Clean(2,d,p);
for(inti=1;i<=n;i++)
scanf("%d",&d[i]);
for(inti=1;i<=m;i++)
scanf("%d",&p[i]);
sort(d+1,d+n+1);
sort(p+1,p+m+1);
kill=pay=0;
for(inti=1,j=1;i<=n&&j<=m;i++)
{
while(d[i]>p[j])j++;
if(p[j]>=d[i])kill+=1,pay+=p[j++];
}
if(kill>=n)printf("%d\n",pay);
elseputs("Loowaterisdoomed!");
}
return0;
}
相关文章推荐
- 例题5-1 UVA 11292 The Dragon of Loowater勇者斗恶龙
- 勇者斗恶龙(The Dragon of Loowater, UVa 11292)
- 勇者斗恶龙(The Dragon of Loowater) UVa 11292 HDU 1902
- Uva11292--------------(The Dragon of Loowater)勇者斗恶龙 (排序后贪心)
- 勇者斗恶龙(The Dragon of Loowater, UVa 11292)
- JAVA-勇者斗恶龙-The Dragon of Loowater,Uva 11292-排序后贪心
- UVA 11292 The Dragon of Loowater
- UVa11292 The Dragon of Loowater
- UVa 11292 The Dragon of Loowater
- UVa11292_The Dragon of Loowater[java]
- UVA 11292 The Dragon of Loowater 英文略长略长
- uva11292 The Dragon of Loowater (排序+贪心)
- UVa 11292 The Dragon of Loowater 简单的比较题
- The Dragon of Loowater, UVa 11292
- UVA 11292(HDU 1902)The Dragon of Loowater
- 勇者斗恶龙(The Dragon Loowater,UVA 11292)
- UVa11292 The Dragon of Loowater(sort排序直接比较)
- The Dragon of Loowater UVa 11292(排序后贪心)
- 贪心/思维题 UVA 11292 The Dragon of Loowater
- uva 11292 Dragon of Loowater (勇者斗恶龙)