Lightoj 1088 - Points in Segments 【二分】
来源:互联网 发布:领导力的文书 知乎 编辑:程序博客网 时间:2024/06/05 21:11
题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1088
题意: 有一维的n个点和q条线段。询问每条线段上的点有多少个;
思路:寻找这些点中对于每条线段的上下界即可。
代码:
#include <stdio.h>#include <ctime>#include <math.h>#include <limits.h>#include <complex>#include <string>#include <functional>#include <iterator>#include <algorithm>#include <vector>#include <stack>#include <queue>#include <set>#include <map>#include <list>#include <bitset>#include <sstream>#include <iomanip>#include <fstream>#include <iostream>#include <ctime>#include <cmath>#include <cstring>#include <cstdio>#include <time.h>#include <ctype.h>#include <string.h>#include <assert.h>using namespace std;int n, q;int a[100010];int x, y;int ok;int query(int t,int &ok){ ok = 0; int left = 1; int right = n; int mid; while (left <= right) { int mid = (left + right) / 2; if (a[mid] >= t) { if (a[mid] == t) ok = 1; right = mid - 1; } else left = mid + 1; } return left;}int main(){ int t; scanf("%d",&t); int cases = 1; while (t--) { scanf("%d%d",&n,&q); for (int i = 1; i <= n; i++) scanf("%d",&a[i]); printf("Case %d:\n", cases++); while (q--) { scanf("%d%d", &x, &y); int ok1 = 0, ok2 = 0, tmp = 0; int t1 = query(x,ok1); int t2 = query(y,ok2); if (ok2) tmp = 1; //printf(" %d %d\n",t1,t2); printf("%d\n", t2 - t1 + tmp); } } return 0; }
0 0
- Lightoj 1088 - Points in Segments 【二分】
- LightOJ 1088 - Points in Segments (二分)
- LightOJ - 1088 Points in Segments
- lighoj 1088 Points in Segments | 二分
- LightOJ--1089 - Points in Segments (II)
- Light OJ 1088 Points in Segments-二分(水)
- LOJ 1088 Points in Segments
- [线段树+离散化]LightOJ 1089 - Points in Segments (II)
- LightOJ 1089 Points in Segments (II) 离散化 标记
- 二分法应用--light oj1088 Points in Segments
- Points in Segments (II)(线段树)
- [树状数组]LightOJ 1266 - Points in Rectangle
- c++二分法简单应用(Points in Segments)
- LightOJ 1112 Curious Robin Hood && LightOJ 1266 Points in Rectangle(树状数组)
- Codeforces Points and Segments (easy)
- XK Segments(二分)
- cfB. XK Segments(二分)
- Codeforces 430A Points and Segments (easy)
- Jetson TK1
- 红枣银耳莲子汤
- 第二章(变量,数据类型和变量名,数据输入)
- BZOJ 1090 [SCOI2003]字符串折叠 区间DP
- 七月二十二日 Linux操作系统c语言学习笔记
- Lightoj 1088 - Points in Segments 【二分】
- Tempter of the Bone(DFS+剪枝)
- 如何编译得到64bit version的opencv2.2.0(opencv2.1)
- hibernate 4.2.5 properties
- struts 拦截器入门&执行流程
- Scala语言中基于Actor的并发编程的机制初步
- AudioRecord工作流程(蓝牙a2dp的状态下)
- mysql部分总结
- 南阳oj Triangular Sums 语言入门