首页 > 其他 > 详细

贪心/hdu 1789 Doing Homework again

时间:2014-12-11 23:43:54      阅读:375      评论:0      收藏:0      [点我收藏+]
 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

原文:http://www.cnblogs.com/NicoleLam/p/4158670.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!