首页 > 其他 > 详细

期末考试(优先队列)

时间:2015-07-29 08:58:00      阅读:193      评论:0      收藏:0      [点我收藏+]

 

期末考试

时间限制:1000 ms  |  内存限制:65535 KB
难度:2
 
描述
马上就要考试了,小T有许多作业要做,而且每个老师都给出来了作业要交的期限,如果在规定的期限内没
交作业就会扣期末成绩的分数,假设完成每门功课需要一天的时间,你能帮助小T扣除的分数最小吗?
 
输入
输入n,表示n门功课(n<2000),接下来n行,每行两个数a,b,分别表示交作业的最后期限,迟交扣除的分数。
(以文件结尾)
输出
输出扣除的最小分数。
样例输入
3
3 10
3 5
3 1
3
1 6
3 2
1 3
7
1 3
4 2
6 1
4 7
2 6
4 5
3 4
样例输出
0
3
5
题解:sort先排序,然后判断扣分值,先做分高的;优先队列从小到大,长度代表天;
代码:
 1 #include<stdio.h>
 2 #include<queue>
 3 #include<algorithm>
 4 #include<string.h>
 5 using namespace std;
 6 struct Node{
 7     int time,score;
 8 };
 9 int cmp(Node a,Node b){
10     if(a.time!=b.time)return a.time<b.time;
11     else return a.score>b.score;
12 }
13 Node m[2010];
14 int main(){
15     int n,day,tot;
16     while(scanf("%d",&n),n){priority_queue<int,vector<int>,greater<int> >work;tot=0;
17     memset(m,0,sizeof(m));
18         for(int i=0;i<n;++i)scanf("%d%d",&m[i].time,&m[i].score);
19         sort(m,m+n,cmp);
20         for(int i=0;i<n;++i){day=work.size();
21             if(m[i].time>day)work.push(m[i].score);
22             else{
23                 if(!work.empty()&&m[i].score>work.top())tot+=work.top(),work.pop(),work.push(m[i].score);
24             else tot+=m[i].score;
25             }
26         }
27         printf("%d\n",tot);
28     }
29     return 0;
30 }

 

期末考试(优先队列)

原文:http://www.cnblogs.com/handsomecui/p/4684942.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!