poj2398(叉积计算点与直线的关系)

来源:互联网 发布:淘宝打假赚钱怎么赚钱 编辑:程序博客网 时间:2024/05/18 05:07

题目链接:   http://poj.org/problem?id=2398

    哈哈,又水一题(跟上道题一模一样, 不过还是有点收获的,上道题忘写了, poj不能用bits/stdc++.h - -)

#include <iostream>#include <algorithm>#include <fstream>#include <iomanip>#include <cstdio>#include <vector>#include <cstring>#include <cmath>#include <queue>#include <stack>#include <set>#include <map>using namespace std;struct point{int x, y;};struct line{point a, b;}l[5050];int mp[5050], mq[5050];double xmult(point p1, point p2, point p0){return (p1.x- p0.x)* (p2.y- p0.y)- (p2.x- p0.x)* (p1.y- p0.y);}int main(){int n, m, x1, x2, y1, y2; while(scanf("%d%d%d%d%d%d", &n, &m, &x1, &y1, &x2, &y2)== 6 && n){memset(mp, 0, sizeof(mp));memset(mq, 0, sizeof(mq));for(int i= 0; i< n; i++){int u, v; scanf("%d%d", &u, &v);point p, q;p.x= u; p.y= y1; q.x= v; q.y= y2;l[i].a= p; l[i].b= q;}for(int i= 0; i< m; i++){point p; scanf("%d%d", &p.x, &p.y);int ans= 0;for(int j= 0; j< n; j++)if(xmult(p, l[j].a, l[j].b)> 0) ans++;mq[mp[ans]]--;mp[ans]++;mq[mp[ans]]++;}printf("Box\n");for(int i= 0; i<= m; i++)if(mq[i]> 0) printf("%d: %d\n", i, mq[i]); }return 0;}



0 0
原创粉丝点击