月饼是久负盛名的中国传统糕点之一,自唐朝以来,已经发展出几百品种。
若想评比出一种“最好吃”的月饼,那势必在吃货界引发一场腥风血雨…… 在这里我们用数字说话,给出全国各地各种月饼的销量,要求你从中找出销量冠军,认定为最好吃的月饼。
输入格式:
输入首先给出两个正整数 N(≤1000)和 M(≤100),分别为月饼的种类数(于是默认月饼种类从 1 到 N 编号)和参与统计的城市数量。
接下来 M 行,每行给出 N 个非负整数(均不超过 1 百万),其中第 i 个整数为第 i 种月饼的销量(块)。数字间以空格分隔。
输出格式:
在第一行中输出最大销量,第二行输出销量最大的月饼的种类编号。如果冠军不唯一,则按编号递增顺序输出并列冠军。数字间以 1 个空格分隔,行首尾不得有多余空格。
输入样例:
5 3
1001 992 0 233 6
8 0 2018 0 2008
36 18 0 1024 4
输出样例:
2018
3 5
解题思路:
遇到了很神奇的事情:
就是这段代码,有时候样例不过,多重复提交几次就过了,而且大样例在oj上过不去,但是在编译器上却没有什么问题
附上我写的代码:
#include <bits/stdc++.h>
using namespace std;
int main()
{
multimap<int,int> res;
int x,y;
cin >> x >> y;
int sum[x];
memset(sum,0,sizeof(sum));
while(y--)
{
for(int i = 0;i < x;++i)
{
int n;
cin >> n;
sum[i] += n;
}
}
for(int i = x;i >= 0;--i)
{
res.insert({sum[i],i+1});
}
int max = (--res.end())->first;
cout << max << endl;
auto t = --res.end();
cout << t->second;
--t;
while(t->first == max)
{
cout << " " << t->second;
--t;
}
}
后来感觉是multimap的问题,换掉试一下,结果就过了,应该是c++的版本不够
通过的代码如下:
#include <bits/stdc++.h>
using namespace std;
int main()
{
int max = 0;
set<int> res;
int x,y;
cin >> x >> y;
int sum[x];
memset(sum,0,sizeof(sum));
while(y--)
{
for(int i = 0;i < x;++i)
{
int n;
cin >> n;
sum[i] += n;
if(sum[i] > max) max = sum[i];
}
}
for(int i = 0;i < x;++i)
{
if(sum[i] == max)
{
res.insert(i+1);
}
}
cout << max << endl;
for(auto &elem : res)
{
if(elem != *res.begin()) cout << " ";
cout << elem;
}
}