zoukankan      html  css  js  c++  java
  • Physical Examination

    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
     
     
    水题,贪心
    a1*b2 < a2*b1 的情况选a
     
    #include <iostream>
    #include <algorithm>
    using namespace std;
    
    #define Mod (365*24*60*60)
    struct S
    {
        long long a,b;
    };
    
    bool cmp(S x, S y)
    {
        return x.a*y.b < x.b*y.a;
    }
    
    S s[100002];
    
    int main()
    {
        int n;
        
        while (cin >> n, n)
        {
            for (int i = 0; i < n; ++i)
            {
                cin >> s[i].a >> s[i].b;
            }
            
            sort(s, s+n, cmp);
            
            long long ans = 0;
            for (int i = 0; i < n; ++i)
            {
                if (ans != 0)
                {
                    ans += (s[i].b*ans)%Mod;
                    
                    ans %= Mod;
                }
                
                ans += s[i].a;
                
                ans %= Mod;
            }
            
            cout << ans << endl;    
            
        }
    }
    View Code
  • 相关阅读:
    【亲身测试成功】windows7 32位操作系统 环境下安装 windows7 64位操作系统
    Deprecated: Function ereg_replace() is deprecated in ……【解决方法】
    20100526(开始上班咯···)
    20100608
    String与string的区别
    Jquery CheckBox全选方法
    与技术无关
    jquery之对象访问(是不是API里出错了呢?)
    工作四个月之后的小感
    关于数据库中的AK(Alternate Key)
  • 原文地址:https://www.cnblogs.com/chenyg32/p/3136700.html
Copyright © 2011-2022 走看看