Lightoj 1088-points in segments "two points"

Source: Internet
Author: User

Title Link: http://www.lightoj.com/volume_showproblem.php?problem=1088

Test instructions: There is a one-dimensional n-point and Q-bar segment. Ask how many points are on each line segment;

Idea: Look for the upper and lower bounds of each line in these points.

Code:

#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;intN, Q;inta[100010];intx, y;intOkintQueryintTint&ok) {OK =0;intleft =1;intright = N;intMid while(left <= right) {intMid = (left + right)/2;if(A[mid] >= t) {if(A[mid] = = t) OK =1; right = mid-1; }ElseLeft = mid +1; }returnLeft;}intMain () {intTscanf("%d", &t);intCases =1; while(t--) {scanf("%d%d", &n,&q); for(inti =1; I <= N; i++)scanf("%d", &a[i]);printf("Case%d:\n", cases++); while(q--) {scanf("%d%d", &x, &y);intOk1 =0, Ok2 =0, TMP =0;intT1 = query (X,OK1);intT2 = query (Y,OK2);if(OK2) TMP =1;//printf ("%d%d\n", t1,t2);            printf("%d\n", T2-T1 + tmp); }    }return 0; }

Copyright NOTICE: Reprint please indicate the source.

Lightoj 1088-points in segments "two minutes"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.