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. 移动端默认meta标签

    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><met ...

  2. 浅谈js设计模式之单例模式

    单例模式的定义是:保证一个类仅有一个实例,并提供一个访问它的全局访问点. 单例模式是一种常用的模式,有一些对象我们往往只需要一个,比如线程池.全局缓存.浏览器中的 window 对象等.在 JavaS ...

  3. 神经网络中的激活函数tanh sigmoid RELU softplus softmatx

    所谓激活函数,就是在神经网络的神经元上运行的函数,负责将神经元的输入映射到输出端.常见的激活函数包括Sigmoid.TanHyperbolic(tanh).ReLu. softplus以及softma ...

  4. 如何从TFS(Visual Studio Team Foundation Server)映射下载本地文件夹

    1.连接tfs项目 首先打开vs2017 ——>工具栏 中的   团队——> 选择团队的管理链接 2.选择管理工作区 显示管理工作区的弹窗,点击 编辑  显示弹窗,选择本地文件夹(即要保存 ...

  5. java基础46 IO流技术(输出字符流/缓冲输出字符流)

    一.输出字符流 1.1.输出字符流体系 --------| Writer:输出字符流的基类(抽象类)  ----------| FileWriter:向文件输出数据输出字符流(把程序中的数据写到硬盘中 ...

  6. EVA:自定义字段实现

    原文链接:http://blog.csdn.net/ytangdigl/article/details/70145910 前言 自定义字段又叫做“开放模型”,用户可以根据自已的需求,添加需要的字段,实 ...

  7. 个人理解的Windows漏洞利用技术发展史

    大概四.五年前,看过陈皓的酷壳上面的一篇文章,上面有一句话我一直记得,是关于学习技术的心得和态度的. 要了解技术就一定需要了解整个计算机的技术历史发展和进化路线.因为,你要朝着球运动的轨迹去,而不是朝 ...

  8. 《HBase实战》学习笔记

    第二章  入门 HBase写路径: 增加新行和修改已有的行,内部机制是一样的. 写入的时候,会写到预写日志(WAL)和MemStore中. MenmStore是内存里的写入缓冲区.填满后,会将数据刷写 ...

  9. 【LOJ】#2052. 「HNOI2016」矿区

    题解 之前尝试HNOI2016的时候弃坑的一道,然后给补回来 (为啥我一些计算几何就写得好长,不过我写啥都长orz) 我们尝试给这个平面图分域,好把这个平面图转成对偶图 怎么分呢,我今天也是第一次会 ...

  10. MemSQL Start[c]UP 2.0 - Round 1 E - Three strings 广义后缀自动机

    E - Three strings 将三个串加进去,看每个节点在三个串中分别出现了多少次. #include<bits/stdc++.h> #define LL long long #de ...