您的位置:首页 > 其它

hdu 4544 湫湫系列故事——消灭兔子(贪心,优先队列)

2016-06-30 13:07 387 查看


湫湫系列故事——消灭兔子

Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)

Total Submission(s): 2327    Accepted Submission(s): 771


Problem Description

  湫湫减肥

  越减越肥!

  

  最近,减肥失败的湫湫为发泄心中郁闷,在玩一个消灭免子的游戏。

  游戏规则很简单,用箭杀死免子即可。

  箭是一种消耗品,已知有M种不同类型的箭可以选择,并且每种箭都会对兔子造成伤害,对应的伤害值分别为Di(1 <= i <= M),每种箭需要一定的QQ币购买。

  假设每种箭只能使用一次,每只免子也只能被射一次,请计算要消灭地图上的所有兔子最少需要的QQ币。

 

Input

输入数据有多组,每组数据有四行;

第一行有两个整数N,M(1 <= N, M <= 100000),分别表示兔子的个数和箭的种类;

第二行有N个正整数,分别表示兔子的血量Bi(1 <= i <= N);

第三行有M个正整数,表示每把箭所能造成的伤害值Di(1 <= i <= M);

第四行有M个正整数,表示每把箭需要花费的QQ币Pi(1 <= i <= M)。

特别说明:

1、当箭的伤害值大于等于兔子的血量时,就能将兔子杀死;

2、血量Bi,箭的伤害值Di,箭的价格Pi,均小于等于100000。

 

Output

如果不能杀死所有兔子,请输出”No”,否则,请输出最少的QQ币数,每组输出一行。

 

Sample Input

3 3
1 2 3
2 3 4
1 2 3
3 4
1 2 3
1 2 3 4
1 2 3 1

 

Sample Output

6
4

思路:从大到小排序,队列里的攻击力一定能满足消灭之后的兔子,然后每次取出最少的即可。

代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
using namespace std;
#define N 100050
int b
,n;
struct Node
{
int d,p;
friend bool operator<(Node c,Node d)
{
return c.p>d.p;
}
} arrow
;
bool cmp(int a,int c)
{
return a>c;
}
bool cmp1(Node a,Node c)
{
return a.d>c.d;
}
int main()
{
int m;
while(scanf("%d %d",&n,&m)!=EOF)
{
priority_queue<Node> q;
for(int i=1; i<=n; i++)
scanf("%d",&b[i]);
for(int i=1; i<=m; i++)
scanf("%d",&arrow[i].d);
for(int i=1; i<=m; i++)
scanf("%d",&arrow[i].p);
sort(b+1,b+1+n,cmp);
sort(arrow+1,arrow+1+m,cmp1);
int cnt=1,flag=0;
long long ans=0;
for(int i=1; i<=n; i++)
{
while(cnt<=m&&arrow[cnt].d>=b[i])
q.push(arrow[cnt++]);
if(!q.empty())
{
ans+=q.top().p;
q.pop();
}
else
{
flag=1;
break;
}
}
if(flag) printf("No\n");
else printf("%lld\n",ans);
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: