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
  • 相关阅读:
    Java分享笔记:关于Java反射机制
    Java分享笔记:自定义枚举类 & 使用enum关键字定义枚举类
    Java分享笔记:RandomAccessFile流 & 在文件指定位置插入内容
    Spark-源码-SparkContext的初始化
    Spark-源码-Spark-StartAll Master Worler启动流程
    Spark-源码-Spark-Submit 任务提交
    Hadoop2学习路程-HDFS
    JavaSE 第二次学习随笔(五)
    JavaSE 第二次学习随笔(四)
    JavaSE 第二次学习随笔(三)
  • 原文地址:https://www.cnblogs.com/chenyg32/p/3136700.html
Copyright © 2011-2022 走看看