nyoj757 期末考试【队列】
来源:互联网 发布:布比网络 编辑:程序博客网 时间:2024/06/05 19:45
期末考试
时间限制:1000 ms | 内存限制:65535 KB
难度:2
- 描述
- 马上就要考试了,小T有许多作业要做,而且每个老师都给出来了作业要交的期限,如果在规定的期限内没交作业就会扣期末成绩的分数,假设完成每门功课需要一天的时间,你能帮助小T扣除的分数最小吗?
- 输入
- 输入n,表示n门功课(n<2000),接下来n行,每行两个数a,b,分别表示交作业的最后期限,迟交扣除的分数。
(以文件结尾) - 输出
- 输出扣除的最小分数。
- 样例输入
33 103 53 131 63 21 371 34 26 14 72 64 53 4
- 样例输出
035
分析:
没有啥好说的,代码简单明了。不知道队列的自己去预习功课
代码:
#include<stdio.h>#include<string.h>#include<queue>#include<algorithm>using namespace std;struct node{int day;//期限 int gk;//分数 }pre[2000];bool cmp(node a,node b){if(a.day<b.day)return true;if(a.day==b.day&&a.gk<b.gk)return true;elsereturn false;}/*struct node{int day;//期限 int gk;//分数 }pre[2000];*/int main(){int n;int sum;priority_queue<int,vector<int>,greater<int> >s;while(scanf("%d",&n)!=EOF){while(!s.empty())s.pop();for(int i=0;i<n;i++)scanf("%d%d",&pre[i].day,&pre[i].gk);sort(pre,pre+n,cmp);sum=0;for(int i=0;i<n;i++){if(s.size()<pre[i].day)s.push(pre[i].gk);else{int x=s.top();if(x<pre[i].gk){s.pop();s.push(pre[i].gk);sum+=x;}elsesum+=pre[i].gk;}}printf("%d\n",sum);}return 0;}
0 0
- nyoj757 期末考试【队列】
- nyoj757 期末考试 (优先队列)
- nyoj757期末考试
- 期末考试(优先队列)
- nyoj 757 期末考试【优先队列】【快排】
- NYOJ 757 期末考试(优先队列)
- nyoj 757 期末考试 【STL 优先队列】
- 期末考试
- 期末考试
- 期末考试
- 期末考试????
- 期末考试
- 期末考试......
- 期末考试
- 期末考试
- 期末考试
- 南阳oj 757 期末考试【优先队列+sort排序】
- 写在期末考试
- Qt使用的一些总结
- iOS webview 和 js 交互
- Qt4.8.6插件化编程例程--仅供参考
- ios 微博分享
- HTML中引号多层嵌套的问题
- nyoj757 期末考试【队列】
- EJB学习笔记三(有状态和无状态SessionBean的区别)
- Number of Digit One
- Algorithm——QuickSort
- background:url(imagepath)不能显示图片
- 不使用软件在Win7下查找大文件的方法
- CNN之Caffe配置
- Hot_Topic_Recognition
- cxf+spring实现ws-security的数字证书验证方式的记录(包括生成证书步骤)