铂金第二期第一题

题目:著名出题人小Q每次比赛后都会写一份《赛题分析》,包含比赛概况、每题的参考算法以及一些统计数值。

对于一道题来说,小Q会统计最短的验题人代码长度(Shortest judge solution)以及赛内参赛队伍最短的AC代码长度(Shortest team solution)。

统计验题人代码长度比较容易,因为验题人最多也不会超过2020个。但是统计选手代码长度就不容易了,因为大赛区动辄三四百支队伍。

请写一个程序,帮助小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了该题的队伍数量。

第二行包含nn个正整数a1,a2,…,an(50≤ai≤65536)a1,a2,…,an(50≤ai≤65536),依次表示每个验题人的代码字节数。

第三行包含mm个正整数b1,b2,…,bn(50≤bi≤65536)b1,b2,…,bn(50≤bi≤65536),依次表示每支AC队伍的代码字节数。若m=0m=0则该行为空行。
Output
对于第i(1≤i≤T)i(1≤i≤T)道题,输出三行,第一行输出Problem xx:,其中x=i+1000x=i+1000。

第二行输出Shortest judge solution: yy bytes.,其中yy表示最短的验题人代码字节数。

第三行输出Shortest team solution: zz bytes.,其中zz表示最短的选手代码字节数,若不存在请输出N/A。

注意:间隔都是一个空格。
题解:输入题数建立循环,在循环中输入验题人和AC选手数,在循环中输入每个验题人和选手数代码长度,用函数对代码长度排序,再判断选手数是否为0,最后输出

#include <iostream>
using namespace std;
void swap(int a[],int c)
{
	int t;
	for (int i = 1; i < c; i++)
	{
		for (int j = 0; j < c-1; j++)
		{
			if (a[j] > a[j + 1])
			{
				t = a[j];
				a[j] = a[j + 1];
				a[j + 1] = t;
			}
		}
	}
	cout << "Shortest judge solution: " << a[0] << " bytes."<<endl;
}
void sort(int a[], int c)
{
	int t;
	for (int i = 1; i < c; i++)
	{
		for (int j = 0; j < c - 1; j++)
		{
			if (a[j] > a[j + 1])
			{
				t = a[j];
				a[j] = a[j + 1];
				a[j + 1] = t;
			}
		}
	}
	cout << "Shortest team solution: " << a[0] << " bytes." << endl;
}
int main()
{
	int t, m, n,a=1001,x[20],y[500];
	cin >> t ;
	while (t--)
	{
		cin >> n >> m;
		for (int i = 0; i < n; i++)
		{
			cin >> x[i];
		}
		for (int i = 0; i < m; i++)
		{
			cin >> y[i];
		}
		cout << "Problem " << a << ":" << endl;
		swap(x, n);
		if (m == 0) cout << "Shortest team solution: N/A bytes." << endl;
		else sort(y, m);
		a++;
	}
}

猜你喜欢

转载自blog.csdn.net/weixin_43981315/article/details/84979453
今日推荐