浙江省赛2015 _ G - Lunch Time -> ZOJ - 3875

2023-05-16

水题
这道题比赛当时没有做出来。原因是 ends ,C++对ends的处理是在缓冲区插入 ‘\0’ 然后刷新,而不是空格,能输出空格是因为Windows对 ‘\0’ 默认的处理方式是输出一个空格,而linux下则不会有什么输出。即windows和linux对’\0’的处理方式不同,而本次测评OS为Linux,所以WA。以后 注意用 ” ” 。
题目:ZOJ 3878

The 999th Zhejiang Provincial Collegiate Programming Contest will be held in Marjar University. The canteen of Marjar University is making preparations for this grand competition. The canteen provides a lunch set of three types: appetizer, main course and dessert. Each type has several dishes with different prices for choosing.
Edward is the headmaster of Marjar University. One day, to inspect the quality of dishes, he go to the canteen and decides to choose a median set for his lunch. That means he must choose one dish from each of appetizers, main courses and desserts. Each chosen dish should at the median price among all dishes of the same type.
For example, if there are five dessert dishes selling at the price of 2, 3, 5, 10, 30, Edward should choose the dish with price 5 as his dessert since its price is located at the median place of the dessert type. If the number of dishes of a type is even, Edward will choose the dish which is more expensive among the two medians.
You are given the list of all dishes, please write a program to help Edward decide which dishes he should choose.
Input
There are multiple test cases. The first line of input contains an integer T indicating the number of test cases. For each test case:
The first line contains three integers S, M and D (1 <= S, M, D <= 100), which means that there are S dishes of appetizer, M dishes of main course and D dishes of dessert.
Then followed by three parts. The first part contains S lines, the second and the last part contains M and D lines respectively. In each line of the three parts, there is a string and an integer indicating the name and the price of a dish. The name of dishes will only consist of non-whitespace characters with no more than 50 characters. The price of dishes are non-negative integers less than or equal to 1000. All dish names will be distinct.
Output
For each test case, output the total price of the median set, together with the names of appetizer, main course and dessert, separated by a single space.
Sample Input
2
1 3 2
Fresh_Cucumber 4
Chow_Mein 5
Rice_Served_with_Duck_Leg 12
Fried_Vermicelli 7
Steamed_Dumpling 3
Steamed_Stuffed_Bun 4
2 3 1
Stir-fried_Loofah_with_Dried_Bamboo_Shoot 33
West_Lake_Water_Shield_Soup 36
DongPo’s_Braised_Pork 54
West_Lake_Fish_in_Vinegar 48
Longjing_Shrimp 188
DongPo’s_Crisp 18

Sample Output
15 Fresh_Cucumber Fried_Vermicelli Steamed_Stuffed_Bun
108 West_Lake_Water_Shield_Soup DongPo’s_Braised_Pork DongPo’s_Crisp

思路:选择给定的早中晚饭的价格,奇数个就选中间的,偶数个就选中间两个较大的即可。

代码实现:

#include<bits/stdc++.h>
using namespace std;

int main(int argc, char const *argv[])
{
    int t;
    cin>>t;
    while(t--){
        pair<int ,string > dis[3][200]; 
        int smd[3];
        for(int i=0;i<3;i++)
            cin>>smd[i];
        for(int i=0;i<3;i++){
            for(int j=0;j<smd[i];j++)
                cin>>dis[i][j].second>>dis[i][j].first;
            sort(dis[i],dis[i]+smd[i]);
        }
        int ans = 0;
        string str[3];
        for(int i=0;i<3;i++){
            int tmp = smd[i]/2;
            ans += dis[i][tmp].first;
            str[i] = dis[i][tmp].second;
        }
        cout<<ans<<" ";
        for(int i=0;i<3;i++){
            cout<<str[i];
            if(i!=2) cout<<" ";
        }
        cout<<endl;
    }
    return 0;
}

小结:这题很伤,Debug很长时间,对C++ 的本质理解不够深入,一直以为ends就是C++ 里的空格,不想被一直用的Windows坑了,以后要增加对Linux系统的了解。感谢:https://www.cnblogs.com/MrLJC/p/3749782.html

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

浙江省赛2015 _ G - Lunch Time -> ZOJ - 3875 的相关文章

  • dotNet(或 C#)中是否考虑了闰秒?

    DateTime 结构会处理这个问题吗 还有其他类 结构吗 更新 我现在读到闰秒只提前 6 个月宣布 因为地球的自转不是那么可预测的 由于在未来的日期中不可能实现这一点 我可以想象他们只是省略了它们 据我所知 NET 的 DateTime
  • 如何测量 Spark 上查询的执行时间

    我需要测量 Apache Spark Bluemix 上查询的执行时间 我尝试过的 import time startTimeQuery time clock df sqlContext sql query df show endTimeQ
  • 如何在 UML 中指定“一次一个”?

    我正在制作一个类图Classroom and a Course class 我怎样才能表明Classroom只能有一个Course一次在其中吗 我知道我可以使用多重性来指定教室可以只开设一门课程 但这并不能完全指定在不同时间可以有除该一门课
  • 如何在 Python 中将日期时间转换为 UTC 时间戳?

    From http docs python org library time html http docs python org library time html 时间 mktime t 这是 localtime 的反函数 它的论据是 s
  • 我在Excel中有3个时间段 - 我需要知道最长连续时间段的持续时间

    请帮忙 理想情况下 我真的很想仅使用公式来解决这个问题 而不是 VBA 或任何我认为 花哨 的东西 我所工作的项目为持续参与提供奖金 我们有三个 有时更多 参与时间段 这些时间段可能会重叠和 或可能有没有参与的空间 神奇的数字是 84 天的
  • 限制 PHP 函数或命令的执行时间[重复]

    这个问题在这里已经有答案了 您好 是否可以仅对命令或函数设置时间限制 例如 function doSomething code here function1 some code here 我只想为 function1 设置时间限制 存在 s
  • 如何将CUDA时钟周期转换为毫秒?

    我想用一些代码来测量时间within我的内核需要 我已经关注了这个问题 https stackoverflow com questions 11209228 timing different sections in cuda kernel连
  • 使用 print in 循环会减慢循环速度

    Using print in a loop slows down the loop Printing something I tried with Hello 100 times take 2 sec without it it takes
  • 如何在C中将UTC时间转换为本地时间?

    这是一个简单的问题 但解决方案似乎远非简单 我想知道如何从 UTC 转换为本地时间 我正在寻找一种标准的 C 解决方案 并且或多或少保证可以在任何位置的任何计算机上工作 我已仔细阅读以下链接 但在那里找不到解决方案 在C中将包含本地时间的字
  • 如何计算连续行的时间差

    原始数据如下所示 我想按访问者和时间对其进行排序 以计算行中的时间差 然后将其保存到新文件中 visitor v time payment items 1 Jack 1 2 2018 16 07 35 3 2 Jack 1 2 2018 1
  • 如何降级旧版 Android 中的 java.time 代码?

    我有这个简洁的代码 它生成两个日期之间的天数列表 然后是当天的日期 以及它在列表中的位置 最重要的是 所有日期都采用相同的格式 这使得很容易比较它们 Create list of days String s 2018 08 28 Strin
  • 在 JavaScript/Node.js 中将 Youtube Data API V3 视频持续时间格式转换为秒

    我正在尝试将 ISO 8601 字符串转换为 JS Node 中的秒 我能想到的最好的办法是 function convert time duration var a duration match d g var duration 0 if
  • 在 JavaScript 中,如何让函数在特定时间运行?

    我有一个托管仪表板的网站 我可以编辑页面上的 JavaScript 目前每五秒刷新一次 我现在正在尝试获得window print 每天早上8点跑步 我怎么能这样做呢 JavaScript 是not用于此目的的工具 如果您希望某些东西在每天
  • 如何在 Microsoft Excel 中获取两个日期之间的分钟差?

    我正在 Excel 中做一些工作 遇到了一些问题 我正在使用的仪器保存测量的日期和时间 我可以使用以下格式将此数据读入 Excel A B 1 Date Time 2 12 11 12 2 36 25 3 12 12 12 1 46 14
  • 同步通过 LAN 电缆连接的两台 Windows 7 计算机之间的时间

    我有许多笔记本电脑 它们运行我们的应用程序 同时通过以太网电缆成对连接 但未连接到任何外部网络或互联网 时间 我需要连接对来同步其系统时间 但由于每台计算机都需要能够与任何其他计算机同步 因此我无法将一台计算机定义为时间服务器 而另一台计算
  • PHP 日期/时间格式,需要一些帮助

    你能帮我使用 PHP 格式化以下日期吗 变量 start 包含以下日期 这个日期 Wed Feb 01 2012 05 00 00 GMT 080 应该成为 2012 02 01T13 00 00 我知道如何使用基本的 PHP 日期 时间格
  • Bash:从给定时间减去 10 分钟

    在 bash 脚本中 如果我有一个代表时间的数字 格式为 hhmmss 或 hmmss 那么减去 10 分钟的最佳方法是什么 即 90000 gt 85000 这有点棘手 日期可以进行一般操作 即您可以执行以下操作 date date 10
  • 将秒整数转换为 HH:MM,iPhone

    我正在为此苦苦挣扎 我想以 HH MM 格式在标签中显示一个以秒为单位的值 我在互联网上搜索了很长时间并找到了一些答案 但要么没有完全理解它们 要么它们看起来像是一种奇怪的做我想做的事情的方式 如果有人能帮助我解决这个问题 那就太好了 请记
  • 如何用C语言测量时间?

    我想知道某个代码块执行了多长时间 大约 像这样的事情 startStopwatch do some calculations stopStopwatch printf lf timeMesuredInSeconds How 您可以使用clo
  • Rails 和 Mysql 的毫秒数

    使用 Rails Mysql 时存储时间 以毫秒为单位 的最佳方式是什么 我将使用小数和composed of 以便能够将该值作为Ruby 时间进行操作 有人有更好的主意吗 自从提出这个问题以来 已经过去了好几年了 这是更新的解决方案 ht

随机推荐