• UVa 11729 突击战


    https://vjudge.net/problem/UVA-11729

    题意:
    有n个部下,每个部下需要完成一项任务。第i个部下需要你话B分钟交代任务,然后立刻执行J分钟完成任务。安排交代任务顺序并计算出所有任务完成的最少时间。

    思路:
    贪心。

    把执行任务长的先交代了。

    每个任务都有各自的开始执行时间,也就是当这个任务交代完时,它就开始执行任务。接下来计算出完成任务时的时间,每次更新最晚的任务完成时间即可。

     1 #include<iostream> 
     2 #include<algorithm>
     3 using namespace std;
     4 
     5 const int maxn = 1000 + 5;
     6 int n;
     7 
     8 struct node
     9 {
    10     int b, j;
    11 }a[maxn];
    12 
    13 bool cmp(node x, node y)
    14 {
    15     return x.j > y.j;
    16 }
    17 
    18 int main()
    19 {
    20     //freopen("D:\txt.txt", "r", stdin);
    21     int kase = 0;
    22     while (cin >> n && n)
    23     {
    24         for (int i = 0; i < n; i++)
    25             cin >> a[i].b >> a[i].j;
    26         sort(a, a + n, cmp);
    27         int s = 0;
    28         int ans = 0;
    29         for (int i = 0; i < n; i++)
    30         {
    31             s += a[i].b;                   //第i个任务的开始执行时间
    32             ans = max(ans, s + a[i].j);     //第j个任务的结束时间
    33         }
    34         cout << "Case "<< ++kase <<": " <<ans << endl;
    35     }
    36 }
  • 相关阅读:
    机械奥妙
    双向可控硅
    开关电源
    阻容降压电路
    手机充电电源的电路原理
    运算放大电路
    剃须刀电路
    d039: 点的位置
    d029: 求出2-100之间的所有质数(素数)
    d023: 各位数字之和
  • 原文地址:https://www.cnblogs.com/zyb993963526/p/6501370.html
Copyright © 2020-2023  润新知