zoukankan      html  css  js  c++  java
  • 训练赛(28)—— 计蒜客 45725 Fujiyama Thursday

    题目链接https://vjudge.net/contest/386543#problem/D

    题目大意是有C辆车,每辆车可坐4个人,要带4 * C个人去吃饭。给出C辆车到达饭店的时间和每个人吃饭花费的时间。

    等所有人都吃完饭,大家才会离开,问至少需要多少时间。只需把车辆到达时间按照升序排列,吃饭花费时间按照降序

    排列。吃饭时间长的人,就乘坐先到达的车。因为吃饭时间是按照降序排列的,所以第0,4,8,12...个人,就是第0,

    1,2,3辆车上吃饭最慢的,将每组的到达时间和最长吃饭时间相加,最大值组即为答案。

    ac代码:

     1 #include <iostream>
     2 #include <algorithm>
     3 #include <cstdlib>
     4 #include <cstring>
     5 #include <string>
     6 #include <cmath>
     7 #include <vector>
     8 #include <queue>
     9 #include <map>
    10 using namespace std;
    11 typedef long long ll;
    12 
    13 int ct[55]; // 车辆到达时间
    14 int et[205]; // 每个人吃饭花费时间
    15 
    16 int main()
    17 {
    18     int t;
    19     cin >> t;
    20     for (int Case = 1; Case <= t; Case++)
    21     {
    22         memset(ct, 0, sizeof(ct));
    23         memset(et, 0, sizeof(et));
    24         int c;
    25         cin >> c;
    26         for (int i = 0; i < c; i++)
    27         {
    28             cin >> ct[i];
    29         }
    30         for (int i = 0; i < 4 * c; i++)
    31         {
    32             cin >> et[i];
    33         }
    34         sort(ct, ct + c);
    35         sort(et, et + (4 * c), greater<int>());
    36         int max = 0;
    37         for (int i = 0, j = 0; i < c && j < 4 * c; i++, j += 4)
    38         {
    39             int ans = ct[i] + et[j]; // 车辆到达时间 + 该车乘客中吃饭花费的最长时间
    40             if (ans > max) max = ans;
    41         }
    42         cout << "Trip #" << Case << ": ";
    43         cout << max << endl;
    44     }
    45     return 0;
    46 }
  • 相关阅读:
    Swift 网络请求数据与解析
    第三方-Swift2.0后Alamofire的使用方法
    java异常处理机制throws
    eclipse导入不到嵌套的项目
    java异常处理机制Exception
    在eclipse中查找指定文件
    mysql查询count
    【待解决】An internal error occurred during: "Launching baiduTest1". java.lang.NullPointerException
    TestNG升级
    eclipse安装TestNG插件
  • 原文地址:https://www.cnblogs.com/zny0222/p/13418714.html
Copyright © 2011-2022 走看看