POJ 2318 TOYS 几何题 基础
2015-09-05 22:28
337 查看
题意:给你一个矩形,并给你一些线分割这个矩形。有一些玩具,给出玩具坐标。求每个区域有多少个玩具。
方法:利用叉积判断玩具的位置。
方法:利用叉积判断玩具的位置。
#include <iostream> #include <stdio.h> #include <string.h> #include <algorithm> #include <math.h> using namespace std; const int N=5005; struct node{ int x,y; node(int _x=0,int _y=0):x(_x),y(_y){} node operator - (node B){ return node(x-B.x,y-B.y); } int operator * (node B){ return x*B.y-y*B.x; } }a ,b ,A,B,C; int n,m; int X1,X2,Y1,Y2; int ans ; void solve(){ for(int i=0;i<n;i++){ if((a[i]-b[i])*(C-b[i])>0){ ans[i]++; return; } } ans ++; } void work(){ while(~scanf("%d",&n)&&n){ scanf("%d%d%d%d%d",&m,&X1,&Y1,&X2,&Y2); A.y=Y1;B.y=Y2; for(int i=0;i<n;i++){ scanf("%d%d",&A.x,&B.x); a[i]=A;b[i]=B; } memset(ans,0,sizeof(ans)); for(int i=0;i<m;i++){ scanf("%d%d",&C.x,&C.y); solve(); } for(int i=0;i<=n;i++) printf("%d: %d\n",i,ans[i]); printf("\n"); } } int main(){ //freopen("data.txt","r",stdin); work(); return 0; }
相关文章推荐
- 1025. PAT Ranking (25)
- 继承后基类、派生类的访问属性
- hdu1540(线段树区间合并)
- C++ 内存划分与虚函数表在内存中的位置
- 手环方案
- hdu 5279 Reflect phi 欧拉函数
- 贪心算法简介
- 项羽过江
- 王力:怎样学习古代汉语(zz)
- shell
- JQuery之编写弹窗
- 华为机试测试- 字符串最长的数字串
- for_each_process
- 2015-09-05
- 鸡汤乱入
- 组合模式(Composite Pattern)
- HDU 1542 Atlantis
- 使用switch语句键盘录入一个月份,判断季节
- Canvas制作排序算法演示动画
- IOS工作笔记1年,收集整理,常用方法