#include <bits/stdc++.h>
using namespace std; /*
Problem description:
There is an array A, the length of array A is N.
You need to perform Q queries.
Each query, you get an integer X, and you need to find the smallest integer Y in array A, meet Y > X.
If there exist such integer, please print the value of the integer.
Otherwise, please print "There is no number bigger than X". If you finish the above problem, please try the following problem:
1. Find the biggest integer Y in array A, Y < X.
2. Validate if there is a integer Y in array A, meet Y equals to X. 最后写这些:(key 就是上文中每次输入的 X)
1. 对于不下降序列 a,求最小的 i,使得 a[i] = key
2. 对于不下降序列 a,求最大的 i,使得 a[i] = key
3. 对于不下降序列 a,求最小的 i,使得 a[i] > key
4. 对于不下降序列 a,求最大的 i,使得 a[i] < key
5. 对于不上升序列 a,求最小的 i,使得 a[i] = key
6. 对于不上升序列 a,求最大的 i,使得 a[i] = key
7. 对于不上升序列 a,求最小的 i,使得 a[i] < key
8. 对于不上升序列 a,求最大的 i,使得 a[i] > key */ const int maxn = 1e5 + 10;
int n, q;
long long a[maxn]; int main() {
scanf("%d", &n);
for(int i = 1; i <= n; i ++) {
scanf("%lld", &a[i]);
}
sort(a + 1, a + 1 + n); scanf("%d", &q);
while(q --) {
long long x;
scanf("%lld", &x);
int L = 1, R = n, pos = -1;
while(L <= R) {
int mid = (L + R) / 2;
if(a[mid] <= x) L = mid + 1;
else R = mid - 1, pos = mid;
}
if(pos == -1) printf("There is no number bigger than %lld", x);
else printf("%lld\n", a[pos]);
} return 0;
}

  

二分 by zzt的更多相关文章

  1. JZOJ 4737. 金色丝线将瞬间一分为二 二分答案

    4737. 金色丝线将瞬间一分为二 Time Limits: 1000 ms  Memory Limits: 262144 KB  Detailed Limits   Goto ProblemSet ...

  2. BZOJ1012: [JSOI2008]最大数maxnumber [线段树 | 单调栈+二分]

    1012: [JSOI2008]最大数maxnumber Time Limit: 3 Sec  Memory Limit: 162 MBSubmit: 8748  Solved: 3835[Submi ...

  3. BZOJ 2756: [SCOI2012]奇怪的游戏 [最大流 二分]

    2756: [SCOI2012]奇怪的游戏 Time Limit: 40 Sec  Memory Limit: 128 MBSubmit: 3352  Solved: 919[Submit][Stat ...

  4. 整体二分QAQ

    POJ 2104 K-th Number 时空隧道 题意: 给出一个序列,每次查询区间第k小 分析: 整体二分入门题? 代码: #include<algorithm> #include&l ...

  5. [bzoj2653][middle] (二分 + 主席树)

    Description 一个长度为n的序列a,设其排过序之后为b,其中位数定义为b[n/2],其中a,b从0开始标号,除法取下整. 给你一个长度为n的序列s. 回答Q个这样的询问:s的左端点在[a,b ...

  6. [LeetCode] Closest Binary Search Tree Value II 最近的二分搜索树的值之二

    Given a non-empty binary search tree and a target value, find k values in the BST that are closest t ...

  7. [LeetCode] Closest Binary Search Tree Value 最近的二分搜索树的值

    Given a non-empty binary search tree and a target value, find the value in the BST that is closest t ...

  8. jvascript 顺序查找和二分查找法

    第一种:顺序查找法 中心思想:和数组中的值逐个比对! /* * 参数说明: * array:传入数组 * findVal:传入需要查找的数 */ function Orderseach(array,f ...

  9. BZOJ 1305: [CQOI2009]dance跳舞 二分+最大流

    1305: [CQOI2009]dance跳舞 Description 一次舞会有n个男孩和n个女孩.每首曲子开始时,所有男孩和女孩恰好配成n对跳交谊舞.每个男孩都不会和同一个女孩跳两首(或更多)舞曲 ...

随机推荐

  1. IOS AppDelegate常用方法

    // 当应用程序启动完毕的时候就会调用(系统自动调用) - (BOOL)application:(UIApplication *)application didFinishLaunchingWithO ...

  2. UVA 1642 Magical GCD(gcd的性质,递推)

    分析:对于区间[i,j],枚举j. 固定j以后,剩下的要比较M_gcd(k,j) = gcd(ak,...,aj)*(j-k+1)的大小, i≤k≤j. 此时M_gcd(k,j)可以看成一个二元组(g ...

  3. DLM分布式锁的实现机制

    1.AST简介 DLM进程(LMON.LMD)之间的跨实例通信是使用高速互联上的IPC层实现的.为了传递锁资源的状态,DLM使用了异步陷阱(AST),它在操作系统处理程序例程中实现为中断.纯粹主义者可 ...

  4. cin对象的一些常用方法使用总结

    >> 最初定义的是右移,当但是出现在 cin >>中的时候这个符号被重载了,变成了一个流操作,在用户通过键盘输入信息的时候,所有内容都会先直接存储在一个叫输入缓冲区的的地方,c ...

  5. Bootstrap历练实例:响应式标签页

    <!DOCTYPE html><html><head><meta http-equiv="Content-Type" content=&q ...

  6. iOS开发——应用间跳转

    iOS开发过程中,我们经常碰到应用间跳转的情景: 1.使用第三方用户登录,跳转到需授权的App或跳转到分享app的对应页面 *需要用户授权,还需要"返回到调用的程序,同时返回授权的用户名.密 ...

  7. iOS 闭包传值 和 代理传值

    let vc = ViewController() let navc = UINavigationController(rootViewController: vc) window = UIWindo ...

  8. [vijos1066]弱弱的战壕

    描述 永恒和mx正在玩一个即时战略游戏,名字嘛~~~~~~恕本人记性不好,忘了-_-b. mx在他的基地附近建立了n个战壕,每个战壕都是一个独立的作战单位,射程可以达到无限(“mx不赢定了?!?”永恒 ...

  9. 笔试算法题(46):简介 - 二叉堆 & 二项树 & 二项堆 & 斐波那契堆

    二叉堆(Binary Heap) 二叉堆是完全二叉树(或者近似完全二叉树):其满足堆的特性:父节点的值>=(<=)任何一个子节点的键值,并且每个左子树或者右子树都是一 个二叉堆(最小堆或者 ...

  10. SpingBoot之多Profile文件

    1.我们在主配置文件编写的时候,文件名可以是 application-{profile}.properties/yml默认使用application.properties的配置: 在我们的项目开发.测 ...