您的位置:首页 > 其它

HDU 4544 湫湫系列故事――消灭兔子

2013-08-08 20:30 239 查看



HDU 4544




Tags: 数据结构,贪心

Analysis:

将兔子的血量从大到小排序,将箭的杀伤力从大到小排序,对于每一个兔子血量,

将比他大的杀伤力大的剑压入优先队列,优先队列自己重写,让它每次抛出的数为价钱最小。

Code:

#include <cstdio>
#include <queue>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long LL;
const int maxn = 100010;
struct tt {
int d;
int p;
bool operator <(const tt& t) const {
return d>t.d||(d==t.d&&p<t.p);
}
} pt[maxn];
int b[maxn];
priority_queue<int , vector<int>, greater<int> > q;
int main()
{
int n, m, i, j;
while(~scanf("%d%d",&n,&m)) {
for(i=1; i<=n; i++) scanf("%d",&b[i]);
for(i=1; i<=m; i++) scanf("%d",&pt[i].d);
for(i=1; i<=m; i++) scanf("%d",&pt[i].p);
sort(b+1,b+1+n,greater<int>());
sort(pt+1,pt+1+m);
while(!q.empty()) q.pop();
LL ans = 0;
bool flag = 1;
for(i=1,j=1; i<=n; i++) {
while(j<=m&&pt[j].d>=b[i]) {
q.push(pt[j].p);
j++;
}
if(!q.empty()) {
ans += q.top();
q.pop();
} else {
flag = 0;
break;
}
}
if(flag) printf("%I64d\n",ans);
else printf("No\n");
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: