hdu2863Top Shooter
贪心:
枚举时间用范围最大的打高度最小的
先按时间后按高度从低到高排列
View Code
#include<iostream>
#include<queue>
using namespace std;
int sni[51];
const int INF=10000000;
int MIN,n,m;
struct node
{
int t,h;
node(){};
node(int _t,int _h):t(_t),h(_h){};
friend bool operator<(const node &a,const node&b)
{
if(a.t!=b.t)return a.t>b.t;
return a.h>b.h;
}
};
priority_queue<node> pq;
int pro()
{
int ans=0;
int i=1,j=0;
while(!pq.empty())
{
if(pq.top().t!=i){i++,j=0;}
node tmp=pq.top();
pq.pop();
if(tmp.h<MIN)continue;
if(j<n&&sni[j]<=tmp.h){j++,ans++;continue;}
else pq.push(node(i+1,tmp.h-1));
}
return ans;
}
int main()
{
while(scanf("%d%d",&n,&m)==2)
{
MIN=INF;
for(int i=0;i<n;i++)
{
scanf("%d",&sni[i]);
if(sni[i]<MIN)MIN=sni[i];
}
sort(sni,sni+n);
for(int i=0;i<m;i++)
{
node tmp;
scanf("%d%d",&tmp.t,&tmp.h);
pq.push(tmp);
}
printf("%d\n",pro());
}
}