HDU 1789 Doing Homework again(贪心)
来源:互联网 发布:淘宝价格区间设置不了 编辑:程序博客网 时间:2024/06/14 14:04
Doing Homework again
Time Limit : 1000/1000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other)
Total Submission(s) : 5 Accepted Submission(s) : 3
Font: Times New Roman | Verdana | Georgia
Font Size: ← →
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
Author
Source
2007省赛集训队练习赛(10)_以此感谢DOOMIII
#include<stdio.h> #include<string.h> #include<algorithm> using namespace std; struct work { int time,score; } a[5001]; //先按分数从大到小排序,分数相同下按时间从小到大 bool cmp(work a,work b) { if(a.score==b.score) return a.time<b.time; else return a.score>b.score; } int main() { int visit[1001]={0}; //标志 int n,m,i,s,j; scanf("%d",&n); while(n--) { scanf("%d",&m); memset(visit,0,sizeof(visit)); //标志初始位 for(i=0; i<m; i++) //输入时间 scanf("%d",&a[i].time); for(i=0; i<m; i++) //输入扣分数 scanf("%d",&a[i].score); sort(a,a+m,cmp); //排序 //先选扣分数多的,依次标记所用的日期 s=0; for(i=0;i<m;i++) { j=a[i].time; while(j) { if(visit[j]==0) { visit[j]=1; break; } j--; } if(j==0) s+=a[i].score; } printf("%d\n",s); } } 例子:分数:7 6 5 4 3 2 1时间:4 2 4 2 1 4 6j = 4 visit[4] = 1;j = 2 visit[2] = 1;j = 4 visit[3] = 1;j = 2visit[1] = 1;j = 1 j--;j = 0 s+=3j = 4 j--;j = 0 s+=2j = 6 visit[6] = 1;
附上今天错误代码
#include<stdio.h>#include<iostream>#include<string.h>#include<algorithm>#include<cstdlib>using namespace std;struct node{ int t,w,vis;}a[1005];int cmp(node a,node b){ if(a.t>b.t) return 1; else if (a.t==b.t&&a.w>b.w) return 1; return 0;}int main(){ //freopen("in.txt","r",stdin);int t,n,i,j;scanf("%d",&t);while(t--){ int maxtime,sum=0; memset(a,0,sizeof(a)); scanf("%d",&n); for(int i=0;i<n;i++) { scanf("%d",&a[i].t); maxtime=max(maxtime,a[i].t); } for(int i=0;i<n;i++) { scanf("%d",&a[i].w); sum+=a[i].w; } sort(a,a+n,cmp); int ans=0; for(i=maxtime;i>0;i--) { int maxw=0,flag=0; for(j=0;j<n;j++) { if(a[j].t>=i&&a[j].vis==0) { if(maxw<a[j].w) { maxw=a[j].w; flag=j; } //printf("%d\n",ans); } } if(a[flag].vis==0) { ans+=a[flag].w; //printf("%d\n",ans); a[flag].vis=1; } } printf("%d\n",sum-ans);}return 0;}
0 0
- hdu 1789 Doing Homework again 贪心算法
- hdu 1789 Doing Homework again (贪心)
- hdu 1789 Doing Homework again(贪心)
- HDU 1789 Doing Homework again (贪心)
- HDU 1789 Doing Homework again (贪心)
- hdu 1789 Doing Homework again 贪心算法
- HDU 1789 Doing Homework again(贪心~!)
- HDU 1789 Doing Homework Again( 贪心 )
- hdu 1789 doing homework again 贪心
- 贪心-hdu-1789-Doing Homework again
- hdu 1789 Doing Homework again (贪心)
- HDU 1789 Doing Homework again 贪心
- HDU 1789 Doing Homework again(贪心)
- hdu 1789 Doing Homework again (贪心)
- HDU 1789 Doing Homework again (贪心)
- HDU 1789 Doing Homework again(贪心)
- HDU 1789 Doing Homework again(贪心)
- HDU 1789 Doing Homework again(贪心)
- android 5.0的新控件 RecycleView
- git配置使用
- 搜索专题 ps批量操作
- 快速判断一个数是否为质数
- angular2学习笔记(6)
- HDU 1789 Doing Homework again(贪心)
- 属性动画 向右消失 向左出来
- skynet 控制台管理使用技巧
- Confluence安装
- 二叉树的路径和
- Hibernate框架学习(三) 关系映射
- HttpClient与HttpURLConnection分析
- 程序员好的记录
- Android开发中常见adb命令的使用