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. https://www.yunpanjingling.com/

    https://www.yunpanjingling.com/ 账号  kein20 passwd a1234

  2. geoserver 启动闪退

    跟JDK版本有关: 比如geoserver2.11需要JDK版本为JDK1.8 windows配置两个jdk环境: 网上有方法,但如果只需要满足geoserver的话,可以只安装jdk(注意jdk和j ...

  3. WordPress“无法将上传的文件移动至wp-content/uploads/”的解决办法

    WordPress“无法将上传的文件移动至wp-content/uploads/”的问题在有些配置不完善的虚拟主机或服务器中会碰到,一般会出现以下症状:1.无论是从文章编辑页面还是媒体库页面都无法上传 ...

  4. less常用样式集,清除浮动、背景自适应、背景渐变、圆角、内外阴影、高度宽度计算。

    .clear-float() { content: ''; display: block; clear: both; height:; } //伪元素清除浮动 .after-clear() { &am ...

  5. Codeforces 552C Vanya and Scales(进制转换+思维)

    题目链接:http://codeforces.com/problemset/problem/552/C 题目大意:有101个砝码重量为w^0,w^1,....,w^100和一个重量为m的物体,问能否在 ...

  6. Python模块Pygame安装

    一.使用pip安装Python包 大多数较新的Python版本都自带pip,因此首先可检查系统是否已经安装了pip.在Python3中,pip有时被称为pip3. 1.在Linux和OS X系统中检查 ...

  7. 20165301 2017-2018-2《Java程序设计》课程总结

    20165301 2017-2018-2<Java程序设计>课程总结 每周作业链接汇总 预备作业1:我期待的师生关系 预备作业2:学习基础与c语言学习心得 预备作业3: Linux安装及命 ...

  8. Merkle tree在区块链中的应用

    上篇博文我们转载了一篇<Merkle Tree(默克尔树)算法解析>,那么大家是不是会有疑问,学习这个算法之后,我们改怎么去应用,区块链中又是如何应用的?今天这篇博客就以Merkle tr ...

  9. Linux下fastbin利用小结——fd覆盖与任意地址free(House of Spirit)

    linux下的fastbin是ctf中pwn题的重点出题点.去年(2015)中,XCTF就有两站是使用fastbin的利用作为pwn400的压轴题来出现,这也是我刚开始接触fastbin的利用,参考了 ...

  10. css实现360导航首页超链接变色

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...