HDU - 6292 找最短代码问题

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

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

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

请写一个程序,帮助小Q统计最短代码长度。
Input
第一行包含一个正整数T(1≤T≤13),表示赛题数量。

每道题第一行包含两个整数n,m(2≤n≤20,0≤m≤500),分别表示验题人数量以及AC了该题的队伍数量。

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

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

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

第三行输出Shortest team solution: z bytes.,其中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.

#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;
struct ti {
    int jud, tea;
    int *jude;
    int *team;
};
int findshort(int a[],int length) {
    int s = a[0];
    for (int i = 0; i < length; i++) {
        if (s > a[i]) s = a[i];
    }
    return s;
}
void output(ti b) {
    if (b.jud == 0)cout << "Shortest judge solution : N / A bytes."<<endl;
    else cout << "Shortest judge solution: " << findshort(b.jude, b.jud)<<' '<<"bytes."<<endl;
    if (b.tea == 0) cout<<"Shortest team solution: N/A bytes."<<endl;
    else cout << "Shortest team solution: " << findshort(b.team, b.tea) << ' ' << "bytes."<<endl;
}


int main()
{
    int t;
    cin >> t;
    ti *p = new ti[t];
    for (int i = 0; i < t; i++) {
        cin>>p[i].jud;
    if(p[i].jud!=0)
        p[i].jude = new int [p[i].jud];
        cin >> p[i].tea;
        if (p[i].tea != 0)
        p[i].team = new int [p[i].tea];

        if (p[i].jud != 0)
        for (int j = 0; j < p[i].jud; j++) {
         cin>>p[i].jude[j];
        }
        
        if (p[i].tea != 0)
        for (int j = 0; j < p[i].tea; j++) {
            cin >> p[i].team[j];
        }
    }
     //输出每道题的情况
    for (int i=0; i < t; i++) {
        cout << "Problem " << i + 1001<<':'<<endl;
        output(p[i]);
    }

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值