hdu 1789 Doing Homework again(贪心)
2015-07-12 15:36
645 查看
题目:http://acm.hdu.edu.cn/showproblem.php?pid=1789
有t组测试数据,每组测试数据中有n门功课,第一排是完成它们的期限,第二排是未在限制的时间内完成的要扣除的分数,然后是需要求怎样安排才能使得扣的分数最少。
我是这样想的,从时间轴出发,尽量每天都安排有任务,假如某天有多个任务需要完成,就把未安排的score大的任务替换已安排的score小的任务,这样一直进行到最后一天。话说小小的思维漏洞真的很容易打击人的思考积极性啊,提交了两次WA后以为这种方法是错误的,后来发现计算reduced score有疏漏(开始认为被替换的任务的score之和就是解,其实有的任务根本就没push进去啊),重新改了便过了。另外按照score的大小降序排列也是不错的做法,针对每个任务让day从它的期限向前遍历到1,有空的一天就选中标记安排任务,如果不能就计入reduced
score。
有t组测试数据,每组测试数据中有n门功课,第一排是完成它们的期限,第二排是未在限制的时间内完成的要扣除的分数,然后是需要求怎样安排才能使得扣的分数最少。
我是这样想的,从时间轴出发,尽量每天都安排有任务,假如某天有多个任务需要完成,就把未安排的score大的任务替换已安排的score小的任务,这样一直进行到最后一天。话说小小的思维漏洞真的很容易打击人的思考积极性啊,提交了两次WA后以为这种方法是错误的,后来发现计算reduced score有疏漏(开始认为被替换的任务的score之和就是解,其实有的任务根本就没push进去啊),重新改了便过了。另外按照score的大小降序排列也是不错的做法,针对每个任务让day从它的期限向前遍历到1,有空的一天就选中标记安排任务,如果不能就计入reduced
score。
#include <iostream> #include<cstdio> #include<algorithm> #include<cstring> #include<queue> using namespace std; struct node{ int day,score; }work[1010]; bool cmp1(node a,node b){ return a.day<b.day; } struct cmp2{ bool operator()(node a,node b){ return a.score>b.score; } }; int main() { //freopen("cin.txt","r",stdin); int t; cin>>t; while(t--){ int n,sum=0; scanf("%d",&n); memset(work,0,sizeof(work)); for(int i=0;i<n;i++){ scanf("%d",&work[i].day); } for(int i=0;i<n;i++){ scanf("%d",&work[i].score); sum+=work[i].score; } sort(work,work+n,cmp1); priority_queue<node,vector<node>,cmp2> que; int day_t=1,i=0; //要用day_t(1---n) while(day_t<=work[n-1].day){ if(work[i].day>day_t){ que.push(work[i++]); } if(work[i].day==day_t){ que.push(work[i++]); while(work[i].day==day_t){ node tmp=que.top(); if(work[i].score>tmp.score){ que.pop(); que.push(work[i]); } i++; } } day_t++; } while(!que.empty()){ node tmp=que.top(); sum-=tmp.score; que.pop(); } printf("%d\n",sum); } return 0; }
相关文章推荐
- HDU 1532 Drainage Ditches 排水渠(最大流,入门)
- See you again(电影《速度与激情7》主题曲)
- TJU-3980Painting Tree(贪心)
- 酷融贷kurongdai来啦
- 微软官方Windows主题 英国之美2 Great Britain 高分辨率的壁纸
- 微软官方Windows主题 英国之美2 Great Britain 高分辨率的壁纸
- WIP jobs available to MRP
- macbook air 开机黑屏解决方法
- 安装rails遇到的问题
- LintCode Climbing Stairs 爬楼梯
- 【概率】Uva 10900 - So you want to be a 2n-aire?
- EF--Validation failed for one or more entities. See ‘EntityValidationErrors’解决方法
- Svnmailer部署及应用
- AIX系统维护手册二.双机配置,HACMP
- AIX系统维护手册一.系统盘镜像
- my email is nuoyaxingzhe@sina.com
- @(报错)could not find the main class, Program will exit(已解决)
- 2965 - Jurassic Remains
- AIX查看某个端口被哪个进程占用并处理
- LeetCode题解——Container With Most Water