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. Logic BIST

    Logic BIST is crucial for many applications, in particular for life-critical and mission-critical ap ...

  2. ThinkPHP讲解(七)——修改删除

    修改数据 方式一:数组方式,直接将数据库里需要修改的内容进行修改 function Update() { //1.数组方式 $model=D("Info"); $attr=arra ...

  3. C语言初学者代码中的常见错误与瑕疵(19)

    见:C语言初学者代码中的常见错误与瑕疵(19)

  4. 关于mac book 的启动选项

    苹果电脑是用EFI的,没有BIOS,唯一可以设置的是开机的启动选项.可以在基于 Intel 的 Mac 电脑上使用下列启动键组合启动时按住 C 键——从可启动 CD 或 DVD 光盘启动,如随机附带的 ...

  5. struct termios结构体【转】

    本文转载自:http://blog.csdn.net/vevenlcf/article/details/51096122 一.数据成员 termios 函数族提供了一个常规的终端接口,用于控制非同步通 ...

  6. uboot启动参数

    bootcmd=nand read.jffs2 0x30007FC0 kernel; bootm 0x30007FC0bootdelay=2baudrate=115200ethaddr=08:00:3 ...

  7. Mac OX 隐藏文件夹,文件,应用,磁盘的2种方法 hide finder folder, file, application, volume in 2 ways

    经常需要主目录下隐藏一些文件夹之类的, 第一想到的当然就是:在要隐藏的文件夹前面加『.』(leading dot),这个用法当然可以的了 用习惯了Linux/GNU系统的,基本习惯使用这种办法 但是, ...

  8. kvm虚拟机virt-manager启动报错

    安装kvm,用virt-manager启动时报错如下: Traceback (most recent call last):  File "/usr/share/virt-manager/v ...

  9. 使用 ViewPager 和 RadioGroup 封装的一个导航控件

    import android.animation.ObjectAnimator; import android.content.Context; import android.graphics.dra ...

  10. Java生产者消费者模型

    在Java中线程同步的经典案例,不同线程对同一个对象同时进行多线程操作,为了保持线程安全,数据结果要是我们期望的结果. 生产者-消费者模型可以很好的解释这个现象:对于公共数据data,初始值为0,多个 ...