HDU 4442 Physical Examination
Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u
Description
Now WANGPENG arrives at the hospital. Er….. There are so many students, and the number is increasing!
There are many examination subjects to do, and there is a queue for every subject. The queues are getting longer as time goes by. Choosing the queue to stand is always a problem. Please help WANGPENG to determine an exam sequence, so that he can finish all the physical examination subjects as early as possible.
Input
Then n lines follow. The i-th line has a pair of integers (ai, bi) to describe the i-th queue:
1. If WANGPENG follows this queue at time 0, WANGPENG has to wait for ai seconds to finish this subject.
2. As the queue is getting longer, the waiting time will increase bi seconds every second while WANGPENG is not in the queue.
The input ends with n = 0.
For all test cases, 0<n≤100000, 0≤a i,b i<2 31.
Output
Sample Input
1 2
2 3
3 4
4 5
5 6
0
Sample Output
Hint
- In the Sample Input, WANGPENG just follow the given order. He spends 1 second in the first queue, 5 seconds in the 2th queue, 27 seconds in the 3th queue, 169 seconds in the 4th queue, and 1217 seconds in the 5th queue. So the total time is 1419s. WANGPENG has computed all possible orders in his 120-core-parallel head, and decided that this is the optimal choice.
- #include<stdio.h>
- #include<string.h>
- #include<algorithm>
- using namespace std;
- struct Node
- {
- long long x;
- long long y;
- }a[];
- bool cmp(Node f,Node g)
- {
- return f.x*g.y<f.y*g.x;
- }
- int main()
- {
- int n;
- int i,j;
- long long s;
- while(scanf("%d",&n)!=EOF && n!=)
- {
- s=;
- for(i=;i<=n;i++)
- scanf("%I64d %I64d",&a[i].x,&a[i].y);
- sort(a+,a+n+,cmp);
- //long long o=0;
- for(i=;i<=n;i++)
- {
- s=(s+(a[i].x+s*a[i].y))%(***);
- //o=o+l;
- }
- printf("%I64d\n",s);
- }
- return ;
- }
HDU 4442 Physical Examination的更多相关文章
- HDU 4442 Physical Examination(贪心)
HDU 4442 Physical Examination(贪心) 题目链接http://acm.split.hdu.edu.cn/showproblem.php?pid=4442 Descripti ...
- hdu 4442 Physical Examination 贪心排序
Physical Examination Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others ...
- HDU 4442 Physical Examination(关于贪心排序)
这个题目用贪心来做,关键是怎么贪心最小,那就是排序的问题了. 加入给定两个数a1, b1, a2, b2.那么如果先选1再选2的话,总的耗费就是a1 + a1 * b2 + a2; 如果先选2再选1, ...
- hdu 4442 Physical Examination (2012年金华赛区现场赛A题)
昨天模拟赛的时候坑了好久,刚开始感觉是dp,仔细一看数据范围太大. 题目大意:一个人要参加考试,一共有n个科目,每个科目都有一个相应的队列,完成这门科目的总时间为a+b*(前面已完成科目所花的总时间) ...
- hdu 4442
一道超级easy的贪心 一眼看出了他的本质: 代码: #define mod 31536000 #include<cstdio> #include<algorithm> #in ...
- hdu 4442 37届金华赛区 A题
题意:给出一些队伍,每个队伍有初始等待时间和每秒增加的时间,求最短时间 假设有两个队初始时间和每秒增加时间为a1,b1和a2,b2 若第选择第一个的时间小于第二个,则 a1+a2+a1*b2<a ...
- hdu4442 Physical Examination(贪心)
这种样式的最优解问题一看就是贪心.如果一下不好看,那么可以按照由特殊到一般的思维方式,先看n==2时怎么选顺序(这种由特殊到一般的思维方式是思考很多问题的入口): 有两个队时,若先选第一个,则ans= ...
- 2012 Asia JinHua Regional Contest
Draw Something http://acm.hdu.edu.cn/showproblem.php?pid=4450 o(n)统计输入每个数的平方和. #include<cstdio> ...
- 【POJ 3162】 Walking Race (树形DP-求树上最长路径问题,+单调队列)
Walking Race Description flymouse's sister wc is very capable at sports and her favorite event is ...
随机推荐
- Immediate assertion
Imemdiate assertion可以放在任何procedural statement中, assertion被执行判断,当这个procedural code被执行的时候.其他时间是不会被执行的. ...
- yii2自动生成表单
视图中: 1.要use的两个文件类 use yii\helpers\Html; use yii\widgets\ActiveForm; 2.生成表单,以添加商品为例说明.注意红线区域:上传文件需要 ...
- Limit the query running time with Resource limit facility (RLF)
If you need to limit the query(package,plan) running time, but the JCL/JOB TIME parameters doesn't w ...
- redis 笔记06 发布与订阅、事务、慢查询日志、监视器
发布与订阅 1. 服务器状态在pubsub_channels字典保存了所有频道的订阅关系:SUBSCRIBE命令负责将客户端和被订阅的频道关联到这个字典里面,而UNSUBSCRIBE命令则负责 解除客 ...
- React笔记_(6)_react语法5
react的版本 目前主要的react有 ES5,ES6.也有ES5和ES6混合编写的.比较混乱. react官方提倡用ES6. 说到这里,就需要提到一个概念--mixin mixin在es6中被摒弃 ...
- sql回滚
rollback是针对事务的,你如果没有在执行语句之前开启事务,那么无法rollback,建议你还是想别的办法吧,事务语句如下(sqlserver的给你借鉴):--开启事务begin tran --执 ...
- JVM 指令集
指令码 助记符 说明 0x00 nop 什么都不做 0x01 aconst_null 将null推送至栈顶 0x02 iconst_m1 将int型-1推送至栈顶 0x03 iconst_0 将int ...
- WPF single instance
转自:http://www.cnblogs.com/z_lb/archive/2012/09/16/2687487.html public partial class App : Applicatio ...
- 【jQuery UI 1.8 The User Interface Library for jQuery】.学习笔记.4.Tabs控件
之前,我们已经介绍了 jQuery UI 库,CSS 框架.下面,我们将学习这些有增强可视化效果,高度可配置的用户交互组件. Tab 的特性是,点击 tab 后,会高亮该 tab,并显示他的关联con ...
- 在CentOS之上搭建VMware Player 7
1.下载VMware-Player-7.1.2安装包 百度网盘下载地址: 链接:http://pan.baidu.com/s/1nudfo6H 密码:oemc 直接下载地址: https://down ...