标签:
题目大意:给你一个矩形的左上角和右下角的坐标,然后这个矩形有 N 个隔板分割成 N+1 个区域,下面有 M 组坐标,求出来每个区域包含的坐标数。
#include<stdio.h> #include<math.h> using namespace std; const int MAXN = 5e3+7; const double PI = acos(-1.0); struct point { double x, y; point(int x=0, int y=0):x(x), y(y){} }; struct Vector { point a, b; void InIt(point t1, point t2){a=t1, b=t2;} double operator * (const point &p) const { return (p.x-b.x)*(a.y-b.y) - (p.y-b.y)*(a.x-b.x); } }; Vector line[MAXN]; int Find(int N, point a) { int L=0, R=N; while(L <= R) { int Mid = (L+R) >> 1; if(line[Mid] * a < 0) R = Mid - 1; else L = Mid + 1; } return R; } int main() { int M, N; double x1, x2, y1, y2, ui, li; while(scanf("%d", &N) != EOF && N) { scanf("%d%lf%lf%lf%lf", &M, &x1, &y1, &x2, &y2); int ans[MAXN]={0}; line[0].InIt(point(x1, y1), point(x1, y2)); for(int i=1; i<=N; i++) { scanf("%lf%lf", &ui, &li); line[i].InIt(point(ui, y1), point(li, y2)); } while(M--) { scanf("%lf%lf", &ui, &li); int i = Find(N, point(ui, li)); ans[i] += 1; } for(int i=0; i<=N; i++) printf("%d: %d\n", i, ans[i]); printf("\n"); } return 0; }
标签:
原文地址:http://www.cnblogs.com/liuxin13/p/4783452.html