UVa 10611 - The Playboy Chimp
来源:互联网 发布:python控制机器人 编辑:程序博客网 时间:2024/05/21 08:04
题目:一只公猩猩有一个母猩猩的身高序列(非递减),找到比他矮的中最高的以及比他高的中最矮的。
分析:分治,二分查找。直接二分寻找即可,查找前判断是否成立。
说明:╮(╯▽╰)╭好久天没刷题了。
#include <iostream>#include <cstdlib>#include <cstdio>using namespace std;int Chimps[50005];int H[25005];int bs1( int r, int h ){long long l = 1,mid;while ( l < r ) {mid = l+(r-l+1)/2;if ( Chimps[mid] >= h )r = mid-1;else l = mid;}return l;}int bs2( int r, int h ){long long l = 1,mid;while ( l < r ) {mid = l+(r-l)/2;if ( Chimps[mid] <= h )l = mid+1;else r = mid;}return r;}int main(){int N,Q;scanf("%d",&N);for ( int i = 1 ; i <= N ; ++ i )scanf("%d",&Chimps[i]);scanf("%d",&Q);for ( int i = 1 ; i <= Q ; ++ i )scanf("%d",&H[i]);for ( int i = 1 ; i <= Q ; ++ i ) {if ( Chimps[1] < H[i] )printf("%d ",Chimps[bs1( N, H[i] )]);else printf("X "); if ( Chimps[N] > H[i] )printf("%d\n",Chimps[bs2( N=, H[i] )]);else printf("X\n");}//system("pause");return 0;}
0 0
- UVa 10611 - The Playboy Chimp
- UVa10611 - The Playboy Chimp
- HDU 2416 Treasure of the Chimp Island
- Treasure of the Chimp Island hdu bfs
- Treasure of the Chimp Island (BFS
- HDU 2416 Treasure of the Chimp Island bfs 最短路
- hdu(2416) Treasure of the Chimp Island
- HDU 2416 Treasure of the Chimp Island (BFS)
- HDU2416 Treasure of the Chimp Island ,bfs+优先队列
- HDOJ 2416 Treasure of the Chimp Island (BFS)
- Mail Chimp
- HDU 2416 POJ 3346 Treasure of the Chimp Island(最短路)
- hdu 2416 Treasure of the Chimp Island(bfs求最短路)
- POJ 3346 Treasure of the Chimp Island 和CCF考试题比较像
- POJ 3346 && HDU 2416 Treasure of the Chimp Island(bfs)
- [转]Playboy 與影像處理...
- UVa 10137 The Trip
- UVa 10137 The trip
- 【ci框架】config.php配置文件解读
- 仿圆形图片的实现原理,例RoundedImageView
- js for 循环
- C# 操作摄像头
- 黑马程序员_java基础篇之IO流
- UVa 10611 - The Playboy Chimp
- iPhone SDK 包含哪些东西?
- lucene中文分词
- 夏华 与“神”交流
- 2014北大软工夏令营机试 B:Number Steps
- atitit.提升开发效率---MDA 软件开发方式的革命(5)----列表查询建模
- JNI编程中关于二维数组编程
- 媒体为什么不多关注下“超强台风'威马逊'”重创海南岛???
- Windows batch脚本总结