标签:style blog io color sp for div log bs
1 #include<cstdio> 2 #include<algorithm> 3 #include<cstring> 4 using namespace std; 5 int n,ans; 6 struct node 7 { 8 int score; 9 int ddl; 10 }; 11 node a[1010]; 12 bool day[1010]; 13 bool cmp(node x,node y) 14 { 15 return x.score>y.score; 16 } 17 int main() 18 { 19 int T; 20 scanf("%d",&T); 21 for (int t=1;t<=T;t++) 22 { 23 memset(a,0,sizeof(a)); 24 memset(day,0,sizeof(day)); 25 ans=0; 26 scanf("%d",&n); 27 for (int i=1;i<=n;i++) scanf("%d",&a[i].ddl); 28 for (int i=1;i<=n;i++) scanf("%d",&a[i].score); 29 sort(a+1,a+n+1,cmp); 30 for (int i=1;i<=n;i++) 31 { 32 int p=a[i].ddl; 33 while (p>0 && day[p]==1) p--; 34 if (p==0) ans+=a[i].score; 35 else day[p]=1; 36 } 37 printf("%d\n",ans); 38 } 39 return 0; 40 }
贪心/hdu 1789 Doing Homework again
标签:style blog io color sp for div log bs
原文地址:http://www.cnblogs.com/NicoleLam/p/4158670.html