最小代码

问题链接: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;


}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值