由于博客显示原因原题显示有异常
原题链接(https://vjudge.net/contest/274223#problem/G)
著名出题人小Q每次比赛后都会写一份《赛题分析》,包含比赛概况、每题的参考算法以及一些统计数值。
对于一道题来说,小Q会统计最短的验题人代码长度(Shortest judge solution)以及赛内参赛队伍最短的AC代码长度(Shortest team solution)。
统计验题人代码长度比较容易,因为验题人最多也不会超过
20
20
个。但是统计选手代码长度就不容易了,因为大赛区动辄三四百支队伍。
请写一个程序,帮助小Q统计最短代码长度。
Input
第一行包含一个正整数
T(1≤T≤13)
T(1≤T≤13)
,表示赛题数量。
每道题第一行包含两个整数
n,m(2≤n≤20,0≤m≤500)
n,m(2≤n≤20,0≤m≤500)
,分别表示验题人数量以及AC了该题的队伍数量。
第二行包含
n
n
个正整数
a
1
,
a
2
,...,
a
n
(50≤
a
i
≤65536)
a1,a2,...,an(50≤ai≤65536)
,依次表示每个验题人的代码字节数。
第三行包含
m
m
个正整数
b
1
,
b
2
,...,
b
n
(50≤
b
i
≤65536)
b1,b2,...,bn(50≤bi≤65536)
,依次表示每支AC队伍的代码字节数。若
m=0
m=0
则该行为空行。
Output
对于第
i(1≤i≤T)
i(1≤i≤T)
道题,输出三行,第一行输出Problem
x
x
:,其中
x=i+1000
x=i+1000
。
第二行输出Shortest judge solution:
y
y
bytes.,其中
y
y
表示最短的验题人代码字节数。
第三行输出Shortest team solution:
z
z
bytes.,其中
z
z
表示最短的选手代码字节数,若不存在请输出N/A。
注意:间隔都是一个空格。
Sample Input
2
3 2
3627 1460 5288
2365 2671
2 0
5510 7682
Sample Output
Problem 1001:
Shortest judge solution: 1460 bytes.
Shortest team solution: 2365 bytes.
Problem 1002:
Shortest judge solution: 5510 bytes.
Shortest team solution: N/A bytes.
问题简述:输入队伍数T,验题人数量n,AC了的队伍数量m,第二行输入n个每个验题人的代码字节数。第三行输入m个AC队伍的代码字节数。输出格式为第一行为problem x(x=i+1000);第二行为输出最短的验题人代码字节数。第三行输出最短选手代码字节数。如果无AC队伍则输出N/A。
问题分析;实际上主要问题是将最短的验题人代码字节数和最短选手代码字节数求出来。我们定义两个数组用来存储输入的字节,通过冒泡排序将最小的元素找出来,还有一个需要注意的是题目对输出格式的要求。
ACc++代码如下
#include<iostream>
using namespace std;
void bubble(int *a,const int n)
{
for (int lunci = 1; lunci <= n-1; lunci++)
{
for (int i = 0; i < n - 1; i++)
{
if (a[i] > a[i + 1])
{
int t = a[i];
a[i] = a[i+1];
a[i+1] = t;
}
}
}
}
void shuchu(int count,int* a, int y, int z,int num)
{
cout << "Problem " << count + 1000 <<":"<< endl;
cout << "Shortest judge solution: " << y<< " bytes." << endl;
if(num!=0) cout << "Shortest team solution: " << z << " bytes." << endl;
else cout << "Shortest team solution: " <<"N/A" << " bytes." << endl;
}
int main()
{
int T;
int a[25];
int b[550];
int num[2];
cin >> T;
int count = 1;
for (int i = 0; i < T; i++)
{
cin >> num[0] >> num[1];
for (int j = 0; j < num[0]; j++)
{
cin >> a[j];
}
for (int j = 0; j < num[1]; j++)
{
cin >> b[j];
}
bubble(a, num[0]);
bubble(b, num[1]);
int y = a[0];
int z = b[0];
shuchu(count, a, y, z, num[1]);
count++;
}
}