标签:des blog os io for ar div 代码
#include"iostream" #include"cstdio" #include"cstring" #include"cstdio" #include"map" #include"algorithm" using namespace std; const int ms=1e5+1; struct node { int time; int level; }machine[ms],task[ms]; bool cmp(const node &a,const node &b) { if(a.time==b.time) return a.level>b.level; return a.time>b.time; } int main() { int i,j,k,n,m; long long ans,sum; map<int,int> mp; while(scanf("%d%d",&n,&m)==2) { for(i=0;i<n;i++) scanf("%d%d",&machine[i].time,&machine[i].level); for(i=0;i<m;i++) scanf("%d%d",&task[i].time,&task[i].level); mp.clear(); sort(machine,machine+n,cmp); sort(task,task+m,cmp); ans=0;sum=0;j=0; for(i=0;i<m;i++) { while(j<n&&machine[j].time>=task[i].time) { mp[machine[j].level]++; j++; } map<int,int>::iterator it=mp.lower_bound(task[i].level); if(it!=mp.end()) { ans++; sum+=(500*task[i].time+2*task[i].level); int t=it->first; mp[t]--; if(mp[t]==0) mp.erase(t); } } printf("%I64d %I64d\n",ans,sum); } return 0; }
超时代码:付下
/* Name: Copyright: Author: Date: 06/08/14 14:38 Description: */ #include"iostream" #include"cstdio" #include"cstring" #include"algorithm" using namespace std; const int ms=100001; struct node { int time; int level; }task[ms],machine[ms]; bool cmp(const node &a,const node &b) { if(a.time==b.time) return a.level<b.level; return a.time<b.time; } int vis[ms]; int main() { int i,j,k,n,m; freopen("1004.in","r",stdin); freopen("1004a.txt","w",stdout); while(scanf("%d%d",&n,&m)==2) { for(i=1;i<=n;i++) { scanf("%d%d",&machine[i].time,&machine[i].level); } for(i=1;i<=m;i++) { scanf("%d%d",&task[i].time,&task[i].level); } sort(machine+1,machine+1+n,cmp); sort(task+1,task+1+m,cmp); int ans=0; long long sum=0; memset(vis,0,sizeof(vis)); for(i=m;i;i--) { int minv=0xffffff; j=n; int id=0; while(j&&machine[j].time>=task[i].time) { if(machine[j].level>=task[i].level&&vis[j]==0) { if(machine[j].level<minv){ minv=machine[j].level; id=j;} } j--; } if(id){ vis[id]=1; ans++; sum+=500*task[i].time+2*task[i].level; } } //printf("%d %d\n",ans,sum); cout<<ans<<" "<<sum<<endl; } return 0; }
标签:des blog os io for ar div 代码
原文地址:http://www.cnblogs.com/767355675hutaishi/p/3894916.html