hdu 4544 湫湫系列故事——消灭兔子 优先队列+贪心
2014-07-14 20:10
253 查看
将兔子的血量从小到大排序,箭的威力也从小到大排序,
对于每只兔子将威力大于血量的箭加入队列,写个优先队列使得出来数位价钱最少。。
#include<stdio.h>
#include<queue>
#include<algorithm>
#include<iostream>
#include<functional>
using namespace std;
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();
__int64 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=ans+q.top();
q.pop();
}
else
{
flag=0;
break;
}
}
if(flag)
printf("%I64d\n",ans);
else
printf("No\n");
}
return 0;
}
对于每只兔子将威力大于血量的箭加入队列,写个优先队列使得出来数位价钱最少。。
#include<stdio.h>
#include<queue>
#include<algorithm>
#include<iostream>
#include<functional>
using namespace std;
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();
__int64 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=ans+q.top();
q.pop();
}
else
{
flag=0;
break;
}
}
if(flag)
printf("%I64d\n",ans);
else
printf("No\n");
}
return 0;
}
相关文章推荐
- hdu 4544 湫湫系列故事——消灭兔子(贪心+优先队列)
- hdu 4544 湫湫系列故事——消灭兔子(贪心+优先队列)
- HDU 4544 湫湫系列故事——消灭兔子 (贪心+优先队列)
- hdu 4544 湫湫系列故事——消灭兔子(优先队列+贪心)
- HDU 4544 湫湫系列故事——消灭兔子(优先队列+贪心)
- hdu 4544 湫湫系列故事——消灭兔子 优先队列+贪心
- hdu 4544 湫湫系列故事——消灭兔子(贪心,优先队列)
- HDU - 4544 湫湫系列故事——消灭兔子 贪心+优先队列
- hdu 4544 湫湫系列故事——消灭兔子 贪心+优先队列 解题报告
- hdu 4544 湫湫系列故事——消灭兔子(优先队列 + 贪心)
- HDU 4544 湫湫系列故事――消灭兔子(优先队列)
- hdu-4544-湫湫系列故事——消灭兔子-贪心+stl
- hdu 4544 湫湫系列故事——消灭兔子(贪心)
- hdu 4544 湫湫系列故事——消灭兔子(优先队列)
- hdu 4544 湫湫系列故事——消灭兔子 贪心+sbt
- HDU-4544湫湫系列故事——消灭兔子
- hdu 4544 湫湫系列故事——消灭兔子
- HDU-4544-湫湫系列故事——消灭兔子
- HDU - 4544 湫湫系列故事――消灭兔子 2013腾讯编程马拉松复赛第三场
- HDU 4544 湫湫系列故事――消灭兔子