HDU_1789_doing homework again_贪心
2016-05-13 15:04
429 查看
Doing Homework again
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 10705 Accepted Submission(s): 6299
[align=left]Problem Description[/align]
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.
[align=left]Input[/align]
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.
[align=left]Output[/align]
For each test case, you should output the smallest total reduced score, one line per test case.
[align=left]Sample Input[/align]
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
[align=left]Sample Output[/align]
0
3
5
之前做doing homework是用的dp,这道题一来也想用dp,没想到思路,想了好久,然后搜了题解,发现是用的贪心,然后又不知道怎么贪。。。
最后用了题解的思路,按罚分由大到小排序,deadline之前只要有空着的天,那么就在最晚的那一天完成这项任务,否则,无空闲天,则会被罚分。
#include<iostream> #include<cstdio> #include<algorithm> #include<cstring> using namespace std; struct Node { int dead; int sco; } node[1005]; int dead[1005]; int sco[1005]; bool cmp(Node a,Node b) { if(a.sco>b.sco) return 1; return 0; } int vis[1005]; int main() { int t,n; scanf("%d",&t); while(t--) { memset(vis,0,sizeof(vis)); scanf("%d",&n); for(int i=0; i<n; i++) scanf("%d",&dead[i]); for(int i=0; i<n; i++) scanf("%d",&sco[i]); for(int i=0; i<n; i++) { node[i].dead=dead[i]; node[i].sco=sco[i]; } sort(node,node+n,cmp); int day=1,spent=0; for(int i=0; i<n; i++) { int j; for( j=node[i].dead; j>=1; j--) { if(vis[j]==0) { vis[j]=1; break; } } if(j==0) spent+=node[i].sco; } printf("%d\n",spent); } return 0; }
View Code
相关文章推荐
- 安装cassandra作为kairosdb的数据存储
- 【POJ 2010 Moo University-Financial Aid】优先级队列
- matplotlib InstallationError: Command python setup.py egg_info failed with error code 1
- pair类型
- 人工智能过去60年沉浮史,未来60年将彻底改变人类
- int main(int argc,char* argv[])浅析
- 问题:connect() failed (111: Connection refused) while connecting to upstream
- kail2.0下hping3的安装和使用(二)
- 利用wait()和notify()实现生产者与消费者问题
- Selenium - Waits
- airdrop分享, Sender kSFOperationEventErrorOccured {
- Determining IP information for eth0... failed; no link present. Check cable?
- IIC 读写时候提示 timeout waiting for bus ready
- 2011版MacBook Air win7安装教程
- 查看当前的git用户名以及email
- failed to obtain a cell from its dataSource 解决方案
- poj1681Painter's Problem 增广矩阵消元法错误水过版
- http://blog.csdn.net/ta893115871/article/details/46955791/
- 【华为OJ】【054-Redraiment的走法】
- UVa - 514 Rails(栈模拟)