加载中…
个人资料
C_down
C_down
  • 博客等级:
  • 博客积分:0
  • 博客访问:74,819
  • 关注人气:27
  • 获赠金笔:0支
  • 赠出金笔:0支
  • 荣誉徽章:
相关博文
推荐博文
谁看过这篇博文
加载中…
正文 字体大小:

hdu 4442

(2012-10-30 11:07:38)
标签:

杂谈

分类: ACM比赛/cf

12金华赛区的第一题, 只能说很水的题。

 

我当时是在教练席上打酱油时看到, 推了下,马上就发现贪心策略。

 

一看题就知道是个贪心,排个序就行了。

设第一个为 x y

第二个为 x1 y1

则排序的比较函数就是 x*y1 与 y*x1 的关系了。

 

Physical Examination

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 592 Accepted Submission(s): 164


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, 0i,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.


 

Source


 

Recommend
zhuyuanchen520

 

 

#include
#include
#include
using namespace
std;
#define MOD 31536000
#define __int64 long long int
//貌似在金华赛区是用long long int的
struct
node
{

    __int64
x,y;
}
g[100100];


int
cmp(node t1,node t2)
{

    return
t1.x*t2.y <</FONT> t1.y*t2.x;
}


int
main()
{

    int
n;
    while
(scanf("%d",&n)&&n)
    {

        for
(int i=0;i<</FONT>n;i++)
        {

            scanf("%lld %lld",&g[i].x,&g[i].y);
        }

        sort(g,g+n,cmp);
        __int64
sum=0;
        for
(int i=0;i<</FONT>n;i++)
        {

            sum += (g[i].x+sum*g[i].y)%(MOD);
        }

        printf("%lld\n",sum%MOD);
    }

    return
0;
}

 

0

阅读 评论 收藏 转载 喜欢 打印举报/Report
前一篇:SGU 249
后一篇:hdu 4450
  • 评论加载中,请稍候...
发评论

    发评论

    以上网友发言只代表其个人观点,不代表新浪网的观点或立场。

    < 前一篇SGU 249
    后一篇 >hdu 4450
      

    新浪BLOG意见反馈留言板 电话:4000520066 提示音后按1键(按当地市话标准计费) 欢迎批评指正

    新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 会员注册 | 产品答疑

    新浪公司 版权所有