题目描述
输入:
10
-691.73,88.01,49.79,-385.15,-875.39,582.77,-881.35,-161.08,142.74,-127.58,729.19,694.82,30.03,-248.93,-246.78,346.60,-625.40,-482.68,893.79,-448.39
5
-109.96,12.34,-25.01,-356.86,-39.88,574.36,661.71,-336.38,346.50,94.99
输出:
(-109.96,12.34) (-25.01,-356.86)
C++代码
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;
typedef struct point{
float x;
float y;
}POINT;
POINT LPPOINT[100];
bool PtInPolygon(POINT p, vector<POINT> &ptPolygon, int nCount)
{
// 交点个数
int nCross = 0;
for (int i = 0; i < nCount; i++)
{
POINT p1 = ptPolygon[i];
POINT p2 = ptPolygon[(i + 1) % nCount];// 最后一个点与第一个点连线
if (p1.y == p2.y)
continue;
if (p.y < min(p1.y, p2.y))
continue;
if (p.y >= max(p1.y, p2.y)