问题链接:http://acm.hdu.edu.cn/showproblem.php?pid=6292
问题简述:著名出题人小Q每次比赛后都会写一份《赛题分析》,包含比赛概况、每题的参考算法以及一些统计数值。
对于一道题来说,小Q会统计最短的验题人代码长度(Shortest judge solution)以及赛内参赛队伍最短的AC代码长度(Shortest team solution)。
统计验题人代码长度比较容易,因为验题人最多也不会超过20个。但是统计选手代码长度就不容易了,因为大赛区动辄三四百支队伍。
请写一个程序,帮助小Q统计最短代码长度。
问题分析:1.声明两个动态数组用于存储输入的代码长度,先输入题目的数量,使用while循环输入验题的代码长度并排序,判断AC的队伍字节长度是不是等于0如果等于0,则不输入,如果不等于0,则输入AC队伍的代码长度并排序, 2.输出结果
代码:
#include <iostream>
#include<algorithm>
#include<cmath>
using namespace std;
int main()
{
int t,i,j,p=0,n,m,index1,index2;
long *a=new long[21],*b=new long[501];
cin>>t;
while(t--)
{
p++;
cin>>n>>m;
bool k=false;
if(m==0)
{
k=true;
}
for(i=0;i<n;i++)
{
cin>>a[i];
}
index1=0;
for(i=1;i<n;i++)
{
if(a[index1]>a[i])
{
index1=i;
}
}
if(!k)
{
for(i=0;i<m;i++)
{
cin>>b[i];
}
index2=0;
for(j=1;j<m;j++)
{
if(b[index2]>b[j])
{
index2=j;
}
}
}
else{
cout<<"Problem "<<p+1000<<":"<<endl;
cout<<"Shortest judge solution: "<<a[index1]<<" bytes."<<endl;
cout<<"Shortest team solution: N/A bytes."<<endl;
continue;}
cout<<"Problem "<<p+1000<<":"<<endl;
cout<<"Shortest judge solution: "<<a[index1]<<" bytes."<<endl;
cout<<"Shortest team solution: "<<b[index2]<<" bytes."<<endl;
}
delete []a;delete []b;
}