HDOJ 1789 Doing Homework again
来源:互联网 发布:java归并排序算法 编辑:程序博客网 时间:2024/05/29 07:40
Doing Homework again
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 11637 Accepted Submission(s): 6837
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
333 3 310 5 131 3 16 2 371 4 6 4 2 4 33 2 1 7 6 5 4
Sample Output
035
贪心算法,根据分值大小排序大的优先如果那天空闲就安排在那天,如果不空闲就向前推,如果前面也没有那就扣分呗。刚接触贪心,感觉理解的不透彻。摸不准怎样才是局部最优。
#include<stdio.h>#include<string.h>#include<algorithm>using namespace std;struct WORK{int t;int s;}wok[1010];int cmp(WORK a,WORK b){return a.s>b.s;}int main(){int t,n,i,j,sum,a[1010],flag;scanf("%d",&t);while(t--){memset(a,0,sizeof(a));scanf("%d",&n);for(i=0;i<n;i++)scanf("%d",&wok[i].t);for(i=0;i<n;i++)scanf("%d",&wok[i].s);sort(wok,wok+n,cmp);/*for(i=0;i<n;i++)printf("%d ",wok[i].t);printf("\n");for(i=0;i<n;i++)printf("%d ",wok[i].s);*/sum=0;for(i=0;i<n;i++){if(a[wok[i].t]==0){a[wok[i].t]=1;continue;}if(a[wok[i].t]!=0){flag=0;for(j=wok[i].t-1;j>0;j--){if(a[j]==0){a[j]=1;flag=1;break;}}if(flag==0)sum+=wok[i].s;}}printf("%d\n",sum);}return 0;}
0 0
- HDOJ 1789 Doing Homework again
- hdoj 1789 Doing Homework again
- hdoj 1789 Doing Homework again
- hdoj 1789 Doing Homework again
- HDOJ 1789 Doing Homework again
- HDOJ-1789 Doing Homework again
- hdoj 1789 Doing Homework again
- hdoj-1789-Doing Homework again
- HDOJ 1789 Doing Homework again
- HDOJ 1789 Doing Homework again
- HDOJ 1789 Doing Homework again
- HDOJ-1789 Doing Homework again
- HDOJ 1789 Doing Homework again
- HDOJ 1789 Doing Homework again
- HDOJ 1789 Doing Homework again
- HDOJ 1789 Doing Homework again贪心
- HDOJ 1789 Doing Homework again (贪心)
- hdoj 1789 Doing Homework again 【贪心】
- 网络流之最大流 POJ 1273
- hdu5810——Balls and Boxes(数学推导)
- HDU 4778 Gems Fight!(博弈+状压)
- 【图形学与游戏编程】开发笔记-入门篇3:图形绘制
- deep features for text spotting 在windows上使用
- HDOJ 1789 Doing Homework again
- ListView的分页加载
- Java类
- Qt QToolTip详解
- 【杭电1081】To The Max
- Dijkstra 模板
- thinkphp注册
- 文章标题
- C++map关联容器