题意是判断多边形是否相交

主要的思路就是判断每一个点是否在另外的多变形内

判断一个点是否在另一个多边形内主要思路是:

判断的那个点向左边做射线,如果射线与多边形的交点为奇数个则在多边形内,偶数个则不在,其中有特殊情况:

1.如果判断的点与所要判断的边在平行且在所要判断的边上,则在多边形上

2.如果向左做射线恰好在某一点上,不特殊处理会计算两次,因为在两条边上,判断射线与多变形的交点数目,所以要在一个情况下忽略

3.就是判断点是否在多边形的左边了

but:WA了好久因为一个多边形可能包涵另一个多边形所以要全部遍历^!!!

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <map>
#include <cmath>
#include <cstring>
#include <string>
#include <queue>
#include <stack>
#include <cctype>
#include <set>
#define ALL(x) x.begin(),x.end()
#define INS(x) inserter(x,x.begin())
const int maxn = ;
typedef long long LL;
struct Point{
double x,y;
};
using namespace std;
Point point[][];
int t[];
bool flag[][]; //参数:
// POINT p 指定的某个点
// LPPOINT ptPolygon 多边形的各个顶点坐标(首末点可以不一致)
// int nCount 多边形定点的个数
bool PtInPolygon (Point p, int num)
{
int nCross = ;
for(int i = ; i < t[num]; i++){
Point p1 = point[num][i];
int tt = (i+) % t[num];
Point p2 = point[num][tt];
double x1 = min(p1.x,p2.x);
double x2 = max(p1.x,p2.x);
double y1 = min(p1.y,p2.y);
double y2 = max(p1.y,p2.y);
if((p.y-p1.y)*(p.x-p2.x) == (p.y-p2.y) * (p.x - p1.x)){
if(p.x >= x1 && p.x <= x2 && p.y >= y1 && p.y <= y2)
return true;
continue;
}
if(p.y < y1)
continue;
if(p.y > y2 || abs(p.y-y2) < 10e-)
continue;
double x = (p.y - p1.y) * (p2.x - p1.x) / (p2.y - p1.y) + p1.x;
if ( x > p.x )
nCross++;
}
return (nCross % == );
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("in.in","r",stdin);
#endif
int tt;
cin >> tt;
for(int cas = ;cas <= tt;cas++){
int n;
cin >> n;
memset(flag,,sizeof(flag));
for(int i = ;i < n;i++){
cin >> t[i];
for(int j = ;j < t[i];j++){
int tmp1,tmp2;
char ch;
cin >> tmp1 >> ch >> tmp2;
point[i][j].x = tmp1;
point[i][j].y = tmp2;
}
}
for(int i = ;i < n;i++){
for(int j = ;j < n;j++){
if(i != j){
bool mark = ;
for(int k = ;k < t[i];k++){
if(PtInPolygon(point[i][k],j)){
mark = ;
break;
}
}
if(mark){
flag[i][j] = flag[j][i] = ;
}
}
}
}
bool aflag = ;
cout << "Data Set #" << cas << endl;
for(int i = ;i < n;i++){
for(int j = ;j < n;j++){
if(flag[i][j]){
flag[i][j] = flag[j][i] = ;
aflag = ;
cout << i+ << " " << j+<< endl;
}
}
}
if(aflag)
cout << "no collisions" << endl;
}
return ;
}

Code

测试用例:


 , , , ,
, , , , , , ,
, , ,
, , , , ,
, , , , , , , , , ,
, , ,
, , , , , ,
, , , , , , ,
, , , ,
, , , ,
, , , ,
, , , , , , , ,
, , , , , , , ,
, , , , , , , ,
, , , , , , , ,
, , ,
, , , , , , , , , ,
, , , , , , , , , ,
, , ,
, , , , , , , ,
, , , , ,
, , , , , , , ,
, , , , , , , ,
, , , , , , , ,
, , , , , , , ,
, , , , , , , , , , , , , , , , , , , , , , , ,
, , , ,

ans:

Data Set #
no collisions
Data Set # Data Set #
no collisions
Data Set # Data Set #
no collisions
Data Set # Data Set #
no collisions
Data Set # Data Set # Data Set # Data Set # Data Set # Data Set # Data Set #
no collisions

poj 3082多边形相交 'Roid Rage的更多相关文章

  1. Inheritance - SGU 129(线段与多边形相交的长度)

    题目大意:给一个凸多边形(点不是按顺序给的),然后计算给出的线段在这个凸多边形里面的长度,如果在边界不计算. 分析:WA2..WA3...WA4..WA11...WA的无话可说,总之细节一定考虑清楚, ...

  2. Geometric Shapes (poj3449多边形相交)

    题意:给你一些多边形的点,判断每个多边形和那些多边形相交,编号按照字典序输出 思路:枚举每个多边形的每条边看是否相交,这里的相交是包括端点的,关键是给你正方形不相邻两个点求另外两个点怎么求,长方形给你 ...

  3. hdu 5130(2014广州 圆与多边形相交模板)

    题意:一个很多个点p构成的多边形,pb <= pa * k时p所占区域与多边形相交面积 设p(x,y),       (x - xb)^2+(y - yb)^2 / (x - xa)^2+(y ...

  4. dtIntersectSegmentPoly2D 2D上的线段与多边形相交计算 产生结果:是否相交,线段跨越的开始和结束百分比,相交的边

    dtIntersectSegmentPoly2D(startPos, endPos, verts, nv, tmin, tmax, segMin, segMax): http://geomalgori ...

  5. Geometric Shapes - POJ 3449(多边形相交)

    题目大意:给一些几何图形的编号,求出来这些图形都和那些相交.   分析:输入的正方形对角线上的两个点,所以需要求出来另外两个点,公式是: x2:=(x1+x3+y3-y1)/2; y2:=(y1+y3 ...

  6. POJ 3449 Geometric Shapes 判断多边形相交

    题意不难理解,给出多个多边形,输出多边形间的相交情况(嵌套不算相交),思路也很容易想到.枚举每一个图形再枚举每一条边 恶心在输入输出,不过还好有sscanf(),不懂可以查看cplusplus网站 根 ...

  7. poj 1410 线段相交判断

    http://poj.org/problem?id=1410 Intersection Time Limit: 1000MS   Memory Limit: 10000K Total Submissi ...

  8. poj 1066 线段相交

    链接:http://poj.org/problem?id=1066 Treasure Hunt Time Limit: 1000MS   Memory Limit: 10000K Total Subm ...

  9. hdu3060Area2(任意多边形相交面积)

    链接 多边形的面积求解是通过选取一个点(通常为原点或者多边形的第一个点)和其它边组成的三角形的有向面积. 对于两个多边形的相交面积就可以通过把多边形分解为三角形,求出三角形的有向面积递加.三角形为凸多 ...

随机推荐

  1. Java -- WeakHashMap

    一.引言 Java中的引用类型由四种情况,强引用.软引用.弱引用.虚引用.关于这些的介绍可以参见鄙人另外一篇博文.                                           ...

  2. Altera FPGA中的pin简介

    第一步要看的肯定是pin planner ,这个是黑金四代EP4CE15F17C8的视图 先就是发现他们pin有不同的颜色区域,分别对应不同的bank,应该是有的设计里面要求pin在同一个bank吧( ...

  3. Python基础2:反射、装饰器、JSON,接口

    一.反射 最近接触到python的反射机制,遂记录下来已巩固.但是,笔者也是粗略的使用了__import__, getattr()函数而已.目前,笔者的理解是,反射可以使用户通过自定义输入来导入响应的 ...

  4. 言未及之而言,谓之躁;言及之而不言,谓之隐;未见颜色而言,谓之瞽(gǔ)

    前言 一个高效的团队离不开leader和组员之前,组员和组员之前的通力合作.而合作的基础便是彼此之间的商讨与协调,意见的统一,进而在达成共识的前提下行动.那么如何才能和组员达成共识呢? 和组员之间的沟 ...

  5. 从java main方法说开去(转)

    刚刚接触java语言时,接触的便为一个java main方法.我们知道这样程序就可以运行了,但是程序是怎么运行起来的我们却不知道. 众所周知,当执行一个java程序时,首先会启动一个JVM虚拟机进程, ...

  6. js 中实现sleep函数

    除了Narrative JS,jwacs(Javascript With Advanced Continuation Support)也致力于通过扩展JavaScript语法来避免编写让人头痛的异步调 ...

  7. 2014 International Conference on Robotics and Computer Vision (ICRVC 2014)

    2014机器人与计算机视觉国际会议ICRVC 与会地点:北京 与会时间:2014.10.24-26 截稿日期:2014-07-10 关于征稿: 语言:英文 主题: • Evolutionary Rob ...

  8. OCP-1Z0-051-题目解析-第25题

    25. You need to create a table with the following column specifications:  1. Employee ID (numeric da ...

  9. Python 第九篇:队列Queue、生产者消费者模型、(IO/异步IP/Select/Poll/Epool)、Mysql操作

    Mysql操作: grant select,insert,update,delete on *.* to root@"%" Identified by "123456&q ...

  10. SDK Hello world(直接使用SDK封装)

    前言 将代码拆分了一下, 如果处理更多的消息也不怕看的眼花 SDK编程就是对各种Windows消息的处理 实验工程 /// @file exam_1.cpp /// @brief 查阅本地MSDN,  ...