HDU 1789 Doing Homework again
来源:互联网 发布:大数据板块龙头股票 编辑:程序博客网 时间:2024/06/10 04:21
Doing Homework again
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 14812 Accepted Submission(s): 8634
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
lcy
Source
2007省赛集训队练习赛(10)_以此感谢DOOMIII
题意:给n门课程在n天完成,每门课程完成的时间是a[i],如果不能在a[i](包括a[i]那天)就会被扣b[i]分,求最小被扣的分数
这题和另外一题及其相似,http://poj.org/problem?id=1827,只是后者的数据更大,这里介绍两种:
1.按损失排序,损失大的排在前面,损失相同时间小的放在前面,然后从时间逆向开始扫一遍,能够完成标记为1,那一天被占领,如果没能完成的话另ans加上,这种方法两题都可以AC
#include<iostream>#include<cstdio>#include<algorithm>#include<cstring>#include<string>#include<stack>#include<queue>#include<deque>#include<set>#include<map>#include<cmath>#include<vector>using namespace std;typedef long long ll;typedef unsigned long long ull;typedef pair<int, int> PII;#define pi acos(-1.0)#define eps 1e-10#define pf printf#define sf scanf#define lson rt<<1,l,m#define rson rt<<1|1,m+1,r#define e tree[rt]#define _s second#define _f first#define all(x) (x).begin,(x).end#define mem(i,a) memset(i,a,sizeof i)#define for0(i,a) for(int (i)=0;(i)<(a);(i)++)#define for1(i,a) for(int (i)=1;(i)<=(a);(i)++)#define mi ((l+r)>>1)#define sqr(x) ((x)*(x))struct node{ int x,y;}p[1100];const int inf=0x3f3f3f3f;int t,n;bool vis[1100];bool cmp(const node& a,const node& b){ if(a.y!=b.y)return a.y>b.y; return a.x>b.x;}int main(){ sf("%d",&t); while(t--) { int ans=0; sf("%d",&n); for1(i,n) sf("%d",&p[i].x); for1(i,n) sf("%d",&p[i].y); mem(vis,0); sort(p+1,p+n+1,cmp); for1(i,n) { int tag=0; for(int j=p[i].x;j>=1;j--) { if(!vis[j]) { vis[j]=1; tag=1; break; } } if(!tag)ans+=p[i].y; } pf("%d\n",ans); } return 0;}
2.按时间排序,时间小的放前面,如果时间相同损失大的放前面,当当前天数大于必须要完成这一任务时,找到前面一个已经完成损失比它小的替换即可,当n值较大时会TLE
#include<algorithm>#include<iostream>#include<cstring>#include<stdio.h>#include<math.h>#include<string>#include<stdio.h>#include<queue>#include<stack>#include<map>#include<deque>using namespace std;int T,n,b[1010];bool vis[1100];struct node{ int t,c;};node a[1001];const int inf=0x3f3f3f3f;bool cmp(node x,node y){ if(x.t!=y.t) return x.t<y.t; return x.c>y.c;}int main(){ int ans,t; scanf("%d",&T); while(T--) { memset(vis,0,sizeof(vis)); ans=0; scanf("%d",&n); for(int i=0;i<n;i++) scanf("%d",&a[i].t); for(int i=0;i<n;i++) scanf("%d",&a[i].c); sort(a,a+n,cmp); t=1; for(int i=0;i<n;i++) { int tag=0; if(a[i].t>=t) { vis[i]=1; t++; } else { int x=i; int p=i,c=a[i].c; for(int j=0;j<i;j++) { if(vis[j]&&a[j].c<c) { p=j; c=a[j].c; } } if(p!=x) vis[x]=1; vis[p]=0; ans+=a[p].c; } } printf("%d\n",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
- 【剑指offer】面试题57(2):和为S的连续正数序列
- c语言中a|b 是什么意思
- 数据库学习纪要(一):hive-1
- 还是畅通工程
- jsp页面中的path 与 bathPath区别
- HDU 1789 Doing Homework again
- python函数内部变量通过函数属性实现全局变量
- caffe随记(三) --- solver 简析
- JavaScript进阶:正则表达式
- hdu3667 最小费用流 拆边题
- Angular 组件间通信
- 有符号数据的符号位扩展
- POJ 1442 Black Box treap || 树状数组 || 优先队列
- #Java was started but returned exit code=13.....