HDU1789时间贪心
Posted zzq
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了HDU1789时间贪心相关的知识,希望对你有一定的参考价值。
Doing Homework again
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 13883 Accepted Submission(s):
8053
Each test case start with a positive integer N(1<=N<=1000) which indicate the number of homework.. Then 2 lines follow. The first line contains N integers that indicate the deadlines of the subjects, and the next line contains N integers that indicate the reduced scores.
#include<bits/stdc++.h>
using namespace std;
int vis[10005];
struct node
{
int a,b;
}P[1005];
bool cmp(node A,node B)
{
if(A.b==B.b) return A.a>B.a;
else return A.b>B.b;
}
int main()
{
int t,n,m,i,j;
cin>>t;
while(t--){memset(vis,0,sizeof(vis));
cin>>n;int ans=0,sumn=0;
for(i=1;i<=n;++i) cin>>P[i].a;
for(i=1;i<=n;++i) cin>>P[i].b,sumn+=P[i].b;
sort(P+1,P+1+n,cmp);
//for(i=1;i<=n;++i) cout<<P[i].a<<" "<<P[i].b<<endl;
for(i=1;i<=n;++i){
for(j=P[i].a;j>=1;j--){
if(!vis[j]) {vis[j]=1;ans+=P[i].b;break;}
}
}//cout<<ans<<endl;
cout<<sumn-ans<<endl;
}
return 0;
}
以上是关于HDU1789时间贪心的主要内容,如果未能解决你的问题,请参考以下文章
HDU1789Doing Homework again(贪心)
HDU 1789 Doing Homework again(贪心)
hdu 1789 Doing Homework again 贪心