PAT (Advanced Level) 1029. Median (25)
scanf读入居然会超时...用了一下输入挂才AC...
#include<cstdio>
#include<cstring>
#include<cmath>
#include<string>
#include<queue>
#include<iostream>
#include<algorithm>
using namespace std; const int maxn=+;
int a[maxn],b[maxn];
int n1,n2; inline bool scan_d(int &num)
{
char in;bool IsN=false;
in=getchar();
if(in==EOF) return false;
while(in!='-'&&(in<''||in>'')) in=getchar();
if(in=='-'){ IsN=true;num=;}
else num=in-'';
while(in=getchar(),in>=''&&in<=''){
num*=,num+=in-'';
}
if(IsN) num=-num;
return true;
} int MIN(int a,int b)
{
if(a<b) return a;
return b;
} int main()
{
scanf("%d",&n1);
for(int i=;i<=n1;i++) scan_d(a[i]);
scanf("%d",&n2);
for(int i=;i<=n2;i++) scan_d(b[i]); int sz=; int p1=,p2=;
a[n1+]=,b[n2+]=; while(sz<n1+n2)
{
sz++;
int tmp1=a[p1],tmp2=b[p2];
if(tmp1<tmp2) p1++; else p2++;
if(sz==(n1+n2+)/)
{
printf("%d\n",MIN(tmp1,tmp2));
break;
}
}
return ;
}
PAT (Advanced Level) 1029. Median (25)的更多相关文章
- PAT (Advanced Level) 1078. Hashing (25)
二次探测法.表示第一次听说这东西... #include<cstdio> #include<cstring> #include<cmath> #include< ...
- PAT (Advanced Level) 1070. Mooncake (25)
简单贪心.先买性价比高的. #include<cstdio> #include<cstring> #include<cmath> #include<vecto ...
- PAT (Advanced Level) 1010. Radix (25)
撸完这题,感觉被掏空. 由于进制可能大的飞起..所以需要开longlong存,答案可以二分得到. 进制很大,导致转换成10进制的时候可能爆long long,在二分的时候,如果溢出了,那么上界=mid ...
- PAT (Advanced Level) 1003. Emergency (25)
最短路+dfs 先找出可能在最短路上的边,这些边会构成一个DAG,然后在这个DAG上dfs一次就可以得到两个答案了. 也可以对DAG进行拓扑排序,然后DP求解. #include<iostrea ...
- PAT (Advanced level) 1003. Emergency (25) Dijkstra
As an emergency rescue team leader of a city, you are given a special map of your country. The map s ...
- PAT (Advanced Level) 1032. Sharing (25)
简单题,不过数据中好像存在有环的链表...... #include<iostream> #include<cstring> #include<cmath> #inc ...
- 【PAT甲级】1029 Median (25 分)
题意: 输入一个正整数N(<=2e5),接着输入N个非递减序的长整数. 输入一个正整数N(<=2e5),接着输入N个非递减序的长整数.(重复一次) 输出两组数合并后的中位数.(200ms, ...
- PAT (Advanced Level) Practice 1006 Sign In and Sign Out (25 分) 凌宸1642
PAT (Advanced Level) Practice 1006 Sign In and Sign Out (25 分) 凌宸1642 题目描述: At the beginning of ever ...
- PAT (Advanced Level) Practice 1002 A+B for Polynomials (25 分) 凌宸1642
PAT (Advanced Level) Practice 1002 A+B for Polynomials (25 分) 凌宸1642 题目描述: This time, you are suppos ...
随机推荐
- 改变vim配色:安装colorscheme【转】
主要有两种方式安装colorscheme: 自行下载colorscheme安装,下载的文件扩展名通常为.vim. 通过安装相关vim的插件获取. 自行下载colorscheme安装 以mac为例,在系 ...
- c_select 调用参数说明
c_select 调用 1. select系统调用select系统调用是用来让我们的程序监视多个文件描述符的状态变化的.程序会停在select这里等待,直到被监视的文件描述符有某一个或多个发生了状态改 ...
- Inno Setup入门(十四)——替换安装程序和卸载程序的图标
通常Inno生成的安装文件的图标是一个光盘和显示器,如下图.同时,程序安装好之后,在安装目录下的卸载程序的图标也是一样的,其实我们也可以自己修改. 首先生成的安装文件图标.这个比较简单,只需要在Set ...
- ios 贝塞尔画图
CGContextRef context = UIGraphicsGetCurrentContext(); //写文字 CGContextSetRGBFillColor(context, 1, 0, ...
- iOS 判断数组不为空
if (array != nil && ![array isKindOfClass:[NSNull class]] && array.count != 0)
- Android中的对话框AlertDialog使用技巧合集-转载
Android中的对话框AlertDialog使用技巧合集 文章来自:http://blog.csdn.net/blue6626/article/details/6641105 今天我用自 ...
- 为Android增加硬件抽象层(HAL)模块访问Linux内核驱动程序
在Android硬件抽象层(HAL)概要介绍和学习计划一文中,我们简要介绍了在Android系统为为硬件编写驱动程序的方法.简单来说,硬件驱动程序一方面分布在Linux内核中,另一方面分布在用户空间的 ...
- sql 日结
--生成日结数据 ==================================== -- Author: <Author,,Name> -- Create date: <Cr ...
- Contest - 多校训练(985专场) Problem C: 985的方格难题
题目链接:http://acm.zzuli.edu.cn/zzuliacm/problem.php?cid=1157&pid=2 Description 985走入了一个n * n的方格地图, ...
- PAT1004
A family hierarchy is usually presented by a pedigree tree. 一个家族的层次结构经常用一个血缘树来呈现. Your job is to cou ...