二分法应用--light oj1088 Points in Segments
来源:互联网 发布:庞培法布拉大学知乎 编辑:程序博客网 时间:2024/05/16 12:45
#include<stdio.h>#include<string.h>#include<algorithm>using namespace std;int a[666666];int twofen(int *a,int k,int high){ if(k>a[high-1]) return high;else{ int low=0;high--; while(low<=high) { int mid=(low+high)/2; if(a[mid]<k) { low=mid+1; } else high=mid-1; }return low;}}int twofen2(int *a,int k,int high){ if(k>a[high-1]) return high;else{ int low=0;high--; while(low<=high) { int mid=(low+high)/2; if(a[mid]<=k) { low=mid+1; } else high=mid-1; }return low;}}int main(){ int n,q,w,i,k,start,endd,flag=1; scanf("%d",&n); while(n--) { ;int cal,low,high; printf("Case %d:\n",flag);flag++; scanf("%d%d",&q,&w); for(i=0;i<q;i++) scanf("%d",&a[i]); while(w--){ scanf("%d%d",&start,&endd); low=twofen(a,start,q);//printf("%d\n",low); high=twofen2(a,endd,q);// printf("%d\n",high); printf("%d\n",high-low); } }}
用二分法找出一个数组里,从A到B的范围一共多少个数,练习二分法,第二个调用函数包括相等的情况。
0 0
- 二分法应用--light oj1088 Points in Segments
- c++二分法简单应用(Points in Segments)
- Light OJ 1088 Points in Segments-二分(水)
- LOJ 1088 Points in Segments
- LightOJ - 1088 Points in Segments
- LightOJ--1089 - Points in Segments (II)
- lighoj 1088 Points in Segments | 二分
- Lightoj 1088 - Points in Segments 【二分】
- Points in Segments (II)(线段树)
- LightOJ 1088 - Points in Segments (二分)
- Light OJ 1266 - Points in Rectangle
- [线段树+离散化]LightOJ 1089 - Points in Segments (II)
- LightOJ 1089 Points in Segments (II) 离散化 标记
- Codeforces Points and Segments (easy)
- Codeforces 430A Points and Segments (easy)
- Codeforces 430 A. Points and Segments (easy)
- Codeforces 430A Points and Segments (easy)
- CodeForces 430A Points and Segments
- opencv学习系列(六)--- 光流跟踪
- arcgis软件集合
- 执行make menuconfig 有许多错误
- linux quota命令参数及用法详解---linux磁盘配额限制设置和查看命令
- 0xcc,vc初始化堆栈的时候使用的数据
- 二分法应用--light oj1088 Points in Segments
- odoo更新方法
- 【JSP开发】通过response的writer流输出数据的问题
- 数据库笔记(二)
- 安卓颜色变换矩阵
- arcgis地图数据集合
- NSOperation vs. GCD
- Data truncation: Out of range value
- codeforces288 E. Arthur and Brackets