PAT-A1029. Median (25)
2016-03-05 23:04
323 查看
水,注意下标从0开始,所以中间是,(m+n-1)/2。
从0开始中间为,中间为(m+n-1)/2 #include <iostream> #include <cstring> #include <cstdio> #include <cstdlib> using namespace std; #define MAX 10000000+10 long int a[MAX], b[MAX], c[2*MAX]; int cmp(const void *a, const void *b) { return *(int*)a - *(int*)b; } int main() { freopen("in.txt", "r", stdin); //freopen("out.txt", "w", stdout); int m = 0, n = 0; scanf("%d", &m); for (int i = 0; i < m; i++) scanf("%ld", &a[i]); scanf("%d", &n); for (int i = 0; i < n; i++) scanf("%ld", &b[i]); int i = 0, j = 0, k = 0; while (i < m && j < n) { if (a[i] == b[j]) { c[k++] = a[i++]; c[k++] = b[j++]; } else if (a[i] < b[j]) { c[k++] = a[i++]; } else { c[k++] = b[j++]; } } while (i < m) c[k++] = a[i++]; while (j < n) c[k++] = b[j++]; printf("%ld", c[(m+n-1)/2]); return 0; }
相关文章推荐
- 读《我是一只IT小小鸟》有感
- System Operations on AWS - Lab 2 - Configuring VPC
- 集合类学习之Hashmap机制研究
- CentOS 下编译安装PHP
- BZOJ2423/HAOI2010 最长公共子序列
- CSS中如何实现表格文字的换行
- GuideMap 登陆界面 详细文档(一)
- PAT-A1085. Perfect Sequence (25)
- 第二次作业
- CentOS 下编译安装MySQL
- 测试
- LeetCode 50 Pow(x, n)(Math、Binary Search)(*)
- Java关键字介绍之this与super
- CTeX使用Tips
- 蓝桥杯-剪格子(搜索)
- 业内大神浅谈MYSQL联合查询
- 巴尔干半岛
- 素材丰富,质量高---------图片资源收藏
- 局部更新 java web 的文件
- CSS设置字间距、行间距、首行缩进