九度OJ 题目1097:取中值
2013-02-05 18:19
253 查看
/********************************* * 日期:2013-2-5 * 作者:SJF0115 * 题号: 九度OJ 题目1097:取中值 * 来源:http://ac.jobdu.com/problem.php?pid=1097 * 结果:AC * 来源:2009年上海交通大学计算机研究生机试真题 * 总结:本题求的是中间值不是中位数,不用排序。 **********************************/ #include<stdio.h> #include<stdlib.h> #include<string.h> int arrayA[1000001]; int arrayB[1000001]; int arrayC[2000002]; int main() { int n,i,j,m,index,lena,lenb; int a,b,c,d; //freopen("C:\\Users\\SJF\\Desktop\\acm.txt","r",stdin); while(scanf("%d",&n)!=EOF) { for(i = 0;i < n;i++){ //数组长度 scanf("%d %d",&lena,&lenb); //第一个数组 for(j = 0;j < lena;j++){ scanf("%d",&arrayA[j]); } //第二个数组 for(j = 0;j < lenb;j++){ scanf("%d",&arrayB[j]); } scanf("%d %d %d %d",&a,&b,&c,&d); //合并数组 index = 0; //第一个数组第a个数到第b个数 for(j = a-1;j < b;j++){ arrayC[index++] = arrayA[j]; } //第二个数组的第c个数到第d个数 for(j = c-1;j < d;j++){ arrayC[index++] = arrayB[j]; } //中间值 printf("%d\n",arrayC[(index-1)/2]); } } return 0; }
/********************************* * 日期:2013-2-5 * 作者:SJF0115 * 题号: 九度OJ 题目1097:取中值 * 来源:http://ac.jobdu.com/problem.php?pid=1097 * 结果:AC * 来源:2009年上海交通大学计算机研究生机试真题 * 总结:本题求的是中间值不是中位数,不用排序。 **********************************/ #include<stdio.h> #include<stdlib.h> #include<string.h> int arrayA[1000001]; int arrayB[1000001]; int main() { int n,i,j,m,index,lena,lenb; int a,b,c,d; //freopen("C:\\Users\\SJF\\Desktop\\acm.txt","r",stdin); while(scanf("%d",&n)!=EOF) { for(i = 0;i < n;i++){ //数组长度 scanf("%d %d",&lena,&lenb); //第一个数组 for(j = 0;j < lena;j++){ scanf("%d",&arrayA[j]); } //第二个数组 for(j = 0;j < lenb;j++){ scanf("%d",&arrayB[j]); } scanf("%d %d %d %d",&a,&b,&c,&d); int n1 = (b - a + 1); int n2 = (d - c + 1); int index = (n1 + n2 - 1) / 2; //在[a b]区间 if(index < n1){ index = index + a - 1; printf("%d\n",arrayA[index]); } //在[c d]区间 else{ index = index - n1 + c - 1; printf("%d\n",arrayB[index]); } } } return 0; }
相关文章推荐
- 九度OJ 1097 取中值
- 九度OJ 1097 取中值
- 九度题目1097:取中值
- 九度OJ 题目1059:abc
- 九度OJ题目1013:开门人和关门人解题报告
- 九度OJ题目1075:斐波那契数列
- 九度OJ 题目1085:求root(N, k)
- 九度 OJ 题目1153:括号匹配问题
- 【九度OJ】题目1111:单词替换
- 九度OJ 题目1482:玛雅人的密码
- <九度 OJ>题目1098:字母统计
- 题目1024:畅通工程 九度OJ
- 九度OJ 题目1080:进制转换
- 九度oj 题目1019:简单计算器 【ZJU2006考研机试题5】
- 【学习笔记】〖九度OJ〗题目1156:谁是你的潜在朋友
- 九度oj 题目1031:xxx定律 【ZJU2009考研机试题1】
- 九度oj 题目1008:最短路径问题 【ZJU2010考研机试题4】【dij+dfs】
- 九度oj 题目1004:Median 【ZJU2011考研机试题3】
- 九度OJ,题目1009-二叉搜索树
- 九度 oj 题目1480:最大上升子序列和