Physical Examination

Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u

Description

WANGPENG is a freshman. He is requested to have a physical examination when entering the university. 
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

There are several test cases. Each test case starts with a positive integer n in a line, meaning the number of subjects(queues). 
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

For each test case, output one line with an integer: the earliest time (counted by seconds) that WANGPENG can finish all exam subjects. Since WANGPENG is always confused by years, just print the seconds mod 365×24×60×60.
 

Sample Input

5
1 2
2 3
3 4
4 5
5 6
0
 

Sample Output

1419

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的更多相关文章

  1. HDU 4442 Physical Examination(贪心)

    HDU 4442 Physical Examination(贪心) 题目链接http://acm.split.hdu.edu.cn/showproblem.php?pid=4442 Descripti ...

  2. hdu 4442 Physical Examination 贪心排序

    Physical Examination Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others ...

  3. HDU 4442 Physical Examination(关于贪心排序)

    这个题目用贪心来做,关键是怎么贪心最小,那就是排序的问题了. 加入给定两个数a1, b1, a2, b2.那么如果先选1再选2的话,总的耗费就是a1 + a1 * b2 + a2; 如果先选2再选1, ...

  4. hdu 4442 Physical Examination (2012年金华赛区现场赛A题)

    昨天模拟赛的时候坑了好久,刚开始感觉是dp,仔细一看数据范围太大. 题目大意:一个人要参加考试,一共有n个科目,每个科目都有一个相应的队列,完成这门科目的总时间为a+b*(前面已完成科目所花的总时间) ...

  5. hdu 4442

    一道超级easy的贪心 一眼看出了他的本质: 代码: #define mod 31536000 #include<cstdio> #include<algorithm> #in ...

  6. hdu 4442 37届金华赛区 A题

    题意:给出一些队伍,每个队伍有初始等待时间和每秒增加的时间,求最短时间 假设有两个队初始时间和每秒增加时间为a1,b1和a2,b2 若第选择第一个的时间小于第二个,则 a1+a2+a1*b2<a ...

  7. hdu4442 Physical Examination(贪心)

    这种样式的最优解问题一看就是贪心.如果一下不好看,那么可以按照由特殊到一般的思维方式,先看n==2时怎么选顺序(这种由特殊到一般的思维方式是思考很多问题的入口): 有两个队时,若先选第一个,则ans= ...

  8. 2012 Asia JinHua Regional Contest

    Draw Something http://acm.hdu.edu.cn/showproblem.php?pid=4450 o(n)统计输入每个数的平方和. #include<cstdio> ...

  9. 【POJ 3162】 Walking Race (树形DP-求树上最长路径问题,+单调队列)

    Walking Race   Description flymouse's sister wc is very capable at sports and her favorite event is ...

随机推荐

  1. zw版【转发·台湾nvp系列Delphi例程】HALCON SelectObj

    zw版[转发·台湾nvp系列Delphi例程]HALCON SelectObj procedure TForm1.Button1Click(Sender: TObject);var img : HIm ...

  2. [php/html/CSS]给Aptana3 安装 Emmet插件

    aptana studio3 安装 zencoding(Emmet) 插件 zen coding 更名为Emmet emmet 谷歌主页地址:http://code.google.com/p/zen- ...

  3. Rsync详解

    Rsync详解 1.什么是RsyncRsync(remote synchronize)是一个远程数据同步工具,可通过LAN/WAN快速同步多台主机间的文件.Rsync使用所谓的“Rsync算法”来使本 ...

  4. pycharm如何调试scrapy

    其实很简单,按下右上角的这个按钮 点击 跳出一个弹框 选择好 这三个基本就可以了 script是要运行的脚本即python中的Lib中的site-packages里面对应模块的执行文件(不懂的话,自行 ...

  5. 在Win8下无法打开 hlp 帮助文件的问题

    需要安装Win8针对该问题的补丁程序,并且修改注册表,详细的解决方案: http://support.microsoft.com/kb/917607/zh-cn#fixit4me

  6. linux设备驱动归纳总结(八):2.总线、设备和驱动的关系【转】

    本文转载自:http://blog.chinaunix.net/uid-25014876-id-110295.html linux设备驱动归纳总结(八):2.总线.设备和驱动的关系 xxxxxxxxx ...

  7. 使用BusyBox制作根文件系统【转】

    本文转载自:http://www.cnblogs.com/lidabo/p/5300180.html 1.BusyBox简介 BusyBox 是很多标准 Linux 工具的一个单个可执行实现.Busy ...

  8. Intel Edison 参考链接2

    Edison的breakout板子的引脚: http://iotdk.intel.com/docs/master/mraa/java/edison.html Edison的引脚 http://www. ...

  9. cpu进程调度---RT Throttling【转】

    转自:http://book.2cto.com/201302/16291.html RT Throttling是对分配给实时进程的CPU时间进行限制的功能.使用实时调度策略的进程由于bug等出现不可控 ...

  10. grads 读取浓度值