zoukankan      html  css  js  c++  java
  • UVA 11389 The Bus Driver Problem 贪心水题

    题目链接:UVA - 11389

    题意描述:有n个司机,n个早班路线和n个晚班路线,给每个司机安排一个早班路线和一个晚班路线,使得每个早班路线和晚班路线只属于一个司机。如果一个司机早班和晚班总的驾驶时间超过d,那么超出的时间按每小时r元付给司机。求最小的费用。

    算法分析:一枚贪心的小水题。对早班路线的时间按照从大到小排序,对晚班路线的时间按照从小到大排序,然后就可以了。

     1 #include<iostream>
     2 #include<cstdio>
     3 #include<cstring>
     4 #include<cstdlib>
     5 #include<cmath>
     6 #include<algorithm>
     7 #define inf 0x7fffffff
     8 using namespace std;
     9 const int maxn=100+10;
    10 
    11 int n,d,r,an[maxn],bn[maxn];
    12 
    13 int cmp(int i,int j) {return i>j; }
    14 
    15 int main()
    16 {
    17     while (scanf("%d%d%d",&n,&d,&r)!=EOF)
    18     {
    19         if (n==0 && d==0 && r==0) break;
    20         for (int i=0 ;i<n ;i++) scanf("%d",&an[i]);
    21         for (int i=0 ;i<n ;i++) scanf("%d",&bn[i]);
    22         int ans=0;
    23         sort(an,an+n);
    24         sort(bn,bn+n,cmp);
    25         for (int i=0 ;i<n ;i++) if (an[i]+bn[i]>d) ans+=(an[i]+bn[i]-d)*r;
    26         printf("%d
    ",ans);
    27     }
    28     return 0;
    29 }
  • 相关阅读:
    AIX系统/var/adm/wtmp大文件处理
    script & scriptreplay
    Ubuntu/Debianpxe/isopreseed
    Ubuntu12.04安装gimp-2.8
    Ubuntu 3D特效一览
    Unix history图览
    Undelete Files on Linux Systems
    开源界有趣的循环缩写和LOGO
    Ubuntu上的dock
    linux下歌曲、视频、文件等乱码
  • 原文地址:https://www.cnblogs.com/huangxf/p/4404923.html
Copyright © 2011-2022 走看看