Physical Examination

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

Total Submission(s): 6155 Accepted Submission(s): 1754

Problem 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≤ai,bi<231.

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.

题意

给你n个考试,每个考试会花费ai+bi*t的花费,t表示当前的时间是多少

题解

我们首先只考虑两个,排序不同的花费分别为

a1+a2+a1b2

a2+a1+a2
b1

然后我们随便推一推,可以发现这是一个贪心的策略,我们只要按照a1b2<a2b1这个来进行排序,然后跑一发就好

代码

struct node
{
LL x;
LL y;
};
bool cmp(node a,node b)
{
return a.x*b.y<b.x*a.y;
}
const LL mod=365*24*60*60;
node a[maxn];
int main()
{
int n;
while(RD(n)!=-1)
{
if(n==0)
break;
REP_1(i,n)
RD(a[i].x),RD(a[i].y);
sort(a+1,a+n+1,cmp);
LL ans=0;
REP_1(i,n)
{
ans+=a[i].x+ans*a[i].y;
ans%=mod;
}
cout<<ans%mod<<endl;
}
}

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:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64 ...

  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. hdu4442 Physical Examination(贪心)

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

  6. 题解报告:hdu 2647 Reward(拓扑排序)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2647 Problem Description Dandelion's uncle is a boss ...

  7. 2017 Multi-University Training Contest - Team 1 1002&&HDU 6034 Balala Power!【字符串,贪心+排序】

    Balala Power! Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)T ...

  8. HDU 6034 Balala Power!(贪心+排序)

    Balala Power! Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) ...

  9. HDU 5821 Ball (贪心排序) -2016杭电多校联合第8场

    题目:传送门. 题意:T组数据,每组给定一个n一个m,在给定两个长度为n的数组a和b,再给定m次操作,每次给定l和r,每次可以把[l,r]的数进行任意调换位置,问能否在转换后使得a数组变成b数组. 题 ...

随机推荐

  1. MySQL参数设置

    InnoDB配置 从MySQL 5.5版本开始,InnoDB就是默认的存储引擎并且它比任何其它存储引擎的使用要多得多.那也是为什么它需要小心配置的原因. 1 innodb_file_per_table ...

  2. mysqli链接数据库示例代码

    $mysqli = new mysqli("localhost", "数据库用户名", "数据库密码", "数据库名称" ...

  3. Django集成Xadmin list index out of range报错解决方案

    return self.render(context) File "C:\Python36\lib\site-packages\django\template\defaulttags.py& ...

  4. 教你用DrawLayout 实现Android 侧滑菜单

    现在的APP越来越注重用户体验,百度视频客户端有一个特效还是挺吸引人的,在主界面手指向右滑动,就可以将菜单展示出来,而主界面会被隐藏大部分,但是仍有左侧的一小部分同菜单一起展示.类似的还有天天动听,人 ...

  5. docker stack 部署 seafile(http)

    =============================================== 2018/5/13_第1次修改                       ccb_warlock == ...

  6. Maven 基础知识

    Maven MavenMaven 简介 Maven MavenMaven 是 Apache Apache Apache 软件基金会组织维护的 软件基金会组织维护的 软件基金会组织维护的 软件基金会组织 ...

  7. Linux 命令find、grep

    本文就向大家介绍find.grep命令,他哥俩可以算是必会的linux命令,我几乎每天都要用到他们.本文结构如下: find命令 find命令的一般形式 find命令的常用选项及实例 find与xar ...

  8. GreenPlum学习笔记:新手入门命令

    1.命令行登录数据库 psql -h 192.168.111.111 -U username -d dbname 其中,username为数据库用户名,dbname为数据库名,执行后提示输入密码.(可 ...

  9. RabbitMQ系列之高可用集群

    为了实现高可用,我采用LVS+双节点RabbitMq , 架构图如下: 在RabbitMQ之前放了LVS, LVS 采用 rr 轮询算法 , 目的是将请求平均分配到两个真实节点,并配置5672端口监控 ...

  10. LoadRunner中的IP欺骗的设置以及误区

    LoadRunner中的IP欺骗的设置以及误区 最近在忙着部署web性能测试的环境后,对IP欺骗进行设置,特地做个笔记,给自己的学习历程留下点足迹. 一. 什么是IP欺骗? 做什么事首先要问个为什么, ...