码迷,mamicode.com
首页 > 其他好文 > 详细

九度OJ 1097 取中值

时间:2014-12-29 01:20:26      阅读:164      评论:0      收藏:0      [点我收藏+]

标签:九度oj   1097   

题目1097:取中值

时间限制:1 秒

内存限制:32 兆

特殊判题:

提交:4379

解决:1188

题目描述:

     存在两组数组,和4个数字a,b,c,d,要求做如下操作,将第一个数组第a个数到第b个数,第二个数组的第c个数到第d个数放到一个数组中,求出合并后数组的中间值,如果有两个中间值,取下标较小的那个。

输入:

    第一行一个整数t表示有t个测试数据
    第二行两个整数,表示两个数组的长度,
    接下来两行表示两个数字的值,

    最后一行有四个整数a,b,c,d。

    数组长度不会超过1000000。

输出:

    每行一个整数,对应合并数组的下标在中间的那个值。

样例输入:
1
5 4
1 2 3 4 5
6 7 8 9
1 2
1 3
样例输出:
6
#include<stdio.h>
int t;
int len1,len2;
int a,b,c,d;
int array1[1000000];
int array2[1000000];
int array3[2000000];
int l1,l2;
int main(int argc, char *argv[])
{
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d%d",&len1,&len2);
        for(int i=0;i<len1;++i)
            scanf("%d",&array1[i]);
        for(int i=0;i<len2;++i)
            scanf("%d",&array2[i]);
        scanf("%d%d%d%d",&a,&b,&c,&d);
        int j=0;
        for(int i=a-1;i<b;++i)
            array3[j++]=array1[i];
        for(int i=c-1;i<d;++i)
            array3[j++]=array2[i];
        printf("%d\n",array3[(j-1)/2]);
    }
    return 0;
}
 
/**************************************************************
    Problem: 1097
    User: kirchhoff
    Language: C
    Result: Accepted
    Time:50 ms
    Memory:16540 kb
****************************************************************/



九度OJ 1097 取中值

标签:九度oj   1097   

原文地址:http://blog.csdn.net/wdkirchhoff/article/details/42219105

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!