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
  • 相关阅读:
    iOS中SQLite知识点总结1
    iOS/mac开发的一些知名个人博客
    ReactiveCocoa框架学习2
    安装visual studio2017后 首次启动出现ActivityLog.xml异常解决方法
    《软工实践》第零次作业
    在Android Studio2.3中配置OpenCV4Android SDK
    【Try Kotlin】Kotlin Koans 代码笔记
    树-二叉搜索树-AVL树
    八种常见排序算法
    迷の衬衫()
  • 原文地址:https://www.cnblogs.com/chenyg32/p/3136700.html
Copyright © 2011-2022 走看看