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
  • 相关阅读:
    asp.net的decimal保留两位小数
    由于管理员设置的策略,该磁盘处于脱机状态-Win 2008 R2
    论大公司的通病和缺点
    sql server删除数据后空间无变化处理方法
    sql server压缩数据库和日志文件
    SQL千万级数据设计和优化
    SQL Server索引怎么用
    在电脑上测试手机网站
    asp.net实现GZip压缩和GZip解压
    WebService教程和分析
  • 原文地址:https://www.cnblogs.com/chenyg32/p/3136700.html
Copyright © 2011-2022 走看看