hdu 1789 Doing Homework again 贪心
HDU 贪心 again
2023-09-14 08:56:55 时间
Doing Homework again
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 20510 Accepted Submission(s): 11813
Problem Description
Ignatius
has just come back school from the 30th ACM/ICPC. Now he has a lot of
homework to do. Every teacher gives him a deadline of handing in the
homework. If Ignatius hands in the homework after the deadline, the
teacher will reduce his score of the final test. And now we assume that
doing everyone homework always takes one day. So Ignatius wants you to
help him to arrange the order of doing homework to minimize the reduced
score.
Input
The
input contains several test cases. The first line of the input is a
single integer T that is the number of test cases. T test cases follow.
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.
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.
Output
For each test case, you should output the smallest total reduced score, one line per test case.
Sample Input
3
3
3 3 3
10 5 1
3
1 3 1
6 2 3
7
1 4 6 4 2 4 3
3 2 1 7 6 5 4
Sample Output
0
3
5
题意:给你完成每一个作业的截止日期,和每一个超过截至日期扣的分数,规定每天只能完成一项作业,要求完成所有作业使扣的总分数最小
题解:按扣分从大到小排序,若扣分相同,截止日期小的排在前面;按排序后的顺序处理作业,从该作业的截至日期开始往前遍历,若还有某天未做作业(vis[i]==0),则该作业不计罚分
#include<iostream> #include<algorithm> #include<string.h> #define ll long long using namespace std; struct node { ll t; ll s; }p[1005]; bool cmp(node a,node b) { if(a.s!=b.s) return a.s>b.s; else return a.t<b.t; } int vis[1005]; int main() { int t,n; cin>>t; while(t--) { cin>>n; memset(vis,0,sizeof(vis)); for(int i=1;i<=n;i++) cin>>p[i].t; for(int i=1;i<=n;i++) cin>>p[i].s; sort(p+1,p+1+n,cmp); ll ans=0; for(int i=1;i<=n;i++) { int flag=0; for(int j=p[i].t;j>=1;j--) { if(vis[j]==0) { vis[j]=1; flag=1; break; } } if(flag==0) ans=ans+p[i].s; } cout<<ans<<endl; } return 0; }
相关文章
- hdu 2222 Keywords Search 模板题
- hdu 1251 统计难题 前缀出现次数
- HDU 3681 Prison Break(状态压缩dp + BFS)
- 【38.63%】【hdu 3047】Zjnu Stadium
- 【hdu 2108】Shape of HDU
- 【hdu 6194】string string string
- HDU 5301(Buildings-贪心构造)
- hdu 5444 Elven Postman(长春网路赛——平衡二叉树遍历)
- HDU-4628 Pieces 如压力DP
- HDU 1711 Number Sequence(kmp)
- HDU 1598 find the most comfortable road (最小生成树) >>
- HDU-4879-ZCC loves march(map+set+并查集)
- HDU 3265 Posters(线段树)
- HDU 4735 Little Wish~ lyrical step~(DLX , 反复覆盖)
- HDU 1051 Wooden Sticks (贪心)