1004_Median
2024-05-09 14:04:07
// 1004_Median.cpp : 定义控制台应用程序的入口点。
//题目1004:Median
//时间限制:1 秒内存限制:32 兆特殊判题:否提交:18367解决:5087
//题目描述:
// Given an increasing sequence S of N integers, the median is the number at the middle position. For example, the median of S1={11, 12, 13, 14} is 12, and the median of S2={9, 10, 15, 16, 17} is 15. The median of two sequences is defined to be the median of the non-decreasing sequence which contains all the elements of both sequences. For example, the median of S1 and S2 is 13.
// Given two increasing sequences of integers, you are asked to find their median.
//输入:
// Each input file may contain more than one test case.
// Each case occupies 2 lines, each gives the information of a sequence. For each sequence, the first positive integer N (≤1000000) is the size of that sequence. Then N integers follow, separated by a space.
// It is guaranteed that all the integers are in the range of long int.
//输出:
// For each test case you should output the median of the two given sequences in a line.
//样例输入:
//4 11 12 13 14
//5 9 10 15 16 17
//样例输出:
//13
//来源:
//2011年浙江大学计算机及软件工程研究生机试真题#include "stdafx.h"
#include "stdio.h"#define MAX 1000002long int a[MAX];
long int b[MAX];int main()
{int i,j,count,median; int n,m;while(scanf("%d",&n)!=EOF){int k=n;int flag = 0;while(k>0)scanf("%ld",&a[n-(k--)]);scanf("%d",&m);k=m;while(k>0)scanf("%ld",&b[m-(k--)]);i=j=count=0;median=(m+n+1)/2;if(!median);else{doif(a[i]>b[j]){j++;count++;if(count == median){printf("%ld\n",b[j-1]);break;}if (j == m){flag = 1;break;} }else{i++;count++;if(count == median){printf("%ld\n",a[i-1]);break;}if (i == n){flag = 2;break;} }}while(1);if(flag ==1){printf("%ld\n",a[i+median-count]);}else if(flag == 2)printf("%ld\n",b[j+median-count]);}}return 0;
}
1004_Median相关推荐
最新文章
- ceph-kvstore-tool 工具使用详解
- Ajax之同步请求和异步请求的区别
- 中国发展研究基金会联合百度发布智能经济白皮书:新基建是助燃剂,其势已成...
- 【设计模式】装饰者模式
- VMware虚拟机安装红帽系统无法上网解决办法(转)
- vs debug 模式生成的exe 另一台电脑_C++利用spdlog生成日志
- python 自然语言处理(三)获取词性
- 17、document的全量替换,document的强制创建,document的删除(来源网络课程中的学习笔记)
- 第五章 常用Lua开发库1-redis、mysql、http客户端
- 关于cocos creator换装功能的实践与思考
- 实战演习-用wse上传下载文件
- 【STM32】HAL库 STM32CubeMX教程六----定时器中断
- iOS Swift 绘制PDF,超长字符串分页绘制
- 机械臂动力学建模(2)- Kane凯恩算法
- ASP.NET MVC Liu_Cabbage 个人博客
- win10商店打不开_win10商店打不开怎么办?
- 【机器学习】课程设计布置:某闯关类手游用户流失预测
- 串口编程 - ascii字符与16进制的相互转换
- Spring Boot将端口8080重定向到8443
- Java Web中的一些概念(JSP、Servlet以及过滤器等)
热门文章
- 软件项目开发中的百分之九十效应
- [xdm+ip]ubuntu下载数据慢或者不通
- 普通美国人的词汇量究竟有多少?
- ThinkPHP php 仿千图网源码_2018最新友价内核
- 第四十天 阿乐在其中—Android小游戏的飞机(四)加入敌人
- python colorbar字体大小_如何更改colorbar上基数和指数的字体大小?
- Mac Chrome浏览器快捷键大全
- Python、Pycharm、Django及各插件安装经验汇总
- android绘画板界面,手机绘画板(MediBang Paint Tablet)
- 浅谈Windows XP系统漏洞的封堵