HDU 4442 Physical Examination
Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u
Description
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
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
Sample Input
1 2
2 3
3 4
4 5
5 6
0
Sample Output
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的更多相关文章
- HDU 4442 Physical Examination(贪心)
HDU 4442 Physical Examination(贪心) 题目链接http://acm.split.hdu.edu.cn/showproblem.php?pid=4442 Descripti ...
- hdu 4442 Physical Examination 贪心排序
Physical Examination Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others ...
- HDU 4442 Physical Examination(关于贪心排序)
这个题目用贪心来做,关键是怎么贪心最小,那就是排序的问题了. 加入给定两个数a1, b1, a2, b2.那么如果先选1再选2的话,总的耗费就是a1 + a1 * b2 + a2; 如果先选2再选1, ...
- hdu 4442 Physical Examination (2012年金华赛区现场赛A题)
昨天模拟赛的时候坑了好久,刚开始感觉是dp,仔细一看数据范围太大. 题目大意:一个人要参加考试,一共有n个科目,每个科目都有一个相应的队列,完成这门科目的总时间为a+b*(前面已完成科目所花的总时间) ...
- hdu 4442
一道超级easy的贪心 一眼看出了他的本质: 代码: #define mod 31536000 #include<cstdio> #include<algorithm> #in ...
- hdu 4442 37届金华赛区 A题
题意:给出一些队伍,每个队伍有初始等待时间和每秒增加的时间,求最短时间 假设有两个队初始时间和每秒增加时间为a1,b1和a2,b2 若第选择第一个的时间小于第二个,则 a1+a2+a1*b2<a ...
- hdu4442 Physical Examination(贪心)
这种样式的最优解问题一看就是贪心.如果一下不好看,那么可以按照由特殊到一般的思维方式,先看n==2时怎么选顺序(这种由特殊到一般的思维方式是思考很多问题的入口): 有两个队时,若先选第一个,则ans= ...
- 2012 Asia JinHua Regional Contest
Draw Something http://acm.hdu.edu.cn/showproblem.php?pid=4450 o(n)统计输入每个数的平方和. #include<cstdio> ...
- 【POJ 3162】 Walking Race (树形DP-求树上最长路径问题,+单调队列)
Walking Race Description flymouse's sister wc is very capable at sports and her favorite event is ...
随机推荐
- [记录]firefox繁体转换成简体的油猴脚本
// ==UserScript== // @name 繁简转换 // @include *.* // @author yecao // @version 0.1 // @include * // @e ...
- HTML5,超级链接
<a href="http://h123.date">预算控制系统</a><<br><a href="2.html&quo ...
- 关于 屏幕阅读器 和 sr-only
.sr-only = screen reader only 用于读屏器识别使用.
- Openstack的镜像上传原理
openstack的horizon的上传镜像流程 通过html的form表单上传文件 先上传到horizon指定的临时目录,存储起来 通过glance-api请求接口 实际上glance-api也是提 ...
- Elasticsearch--配置文件
config目录下有2个配置文件:es的配置文件:elasticsearch.yml日志配置文件:logging.yml,更多内容请参考:ELK教程 cluster.name: elasticsear ...
- 鸟哥的linux私房菜学习记录之账号管理与权限设定
每个登录者都会取到两个ID,一个使用者ID,一个群组ID
- python实现指定目录下批量文件的单词计数:串行版本
直接上代码. 练习目标: 1. 使用 Python 面向对象的方法封装逻辑和表达 : 2. 使用异常处理和日志API : 3. 使用文件目录读写API : 4. 使用 list, map, t ...
- Http的常见问题
A: HTTP(超文本传输协议)是一个基于请求与响应模式的.无状态的.应用层的协议. B: 文件传输协议FTP.电子邮件传输协议SMTP.域名系统服务DNS.HTTP协议等都同是应用层协议. C:HT ...
- crontab实现每秒执行
crontab: #!/bin/bash step=$1 #每多少秒执行一次 ; i < ; i=(i+step) )); do date +%Y%m%d' '%H:%M:%S >> ...
- Oracle 单行函数
一.什么是函数 任何东西,只要它能接收输入,对输入进行加工并产生输出,它就可以被称为函数. 二.单行函数简介 单行函数只对表中的一行数据进行操作,并且对每一行数据只产生一个输出结果.单行函数可以接受一 ...