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
  • 相关阅读:
    Vue日常报错
    VUE学习笔记二
    VUE学习笔记一
    Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured
    Apache Shiro安全(权限框架)学习笔记二
    Apache Shiro安全(权限框架)学习笔记一
    SSH框架整合
    Spring SpringMVC 和 Springboot 的关系(转载)
    SSM日常报错
    Mybatis笔记二
  • 原文地址:https://www.cnblogs.com/chenyg32/p/3136700.html
Copyright © 2011-2022 走看看