题意:一个图,给你一个多边形,然后有一个人在上面按照顺时针去走,问你有多少条线段,如果他一直走,就会走到这个多边形的内部去。
思路:这个人在顺时针走,如果连着的两条线段,是逆时针的,显然这个人就走到多边形内部去了,用叉积去判一判就好了。
#include <cstdio>
#include <queue>
#include <cstring>
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <string>
#include <set>
#include <ctime>
#include <cmath>
#include <cctype>
using namespace std;
#define LL long long
int cas=1,T;
const int maxn = 1e3+10;
pair<int,int>p[maxn];
bool check(pair<int,int>a,pair<int,int>b,pair<int,int>c)
{
return (b.first-a.first)*(c.second-b.second)-(c.first-b.first)*(b.second-a.second)>0;
}
int main()
{
int n,ans=0;
scanf("%d",&n);
n++;
for (int i = 1;i<=n;i++)
scanf("%d%d",&p[i].first,&p[i].second);
for (int i = 3;i<=n;i++)
if (check(p[i-2],p[i-1],p[i]))
ans++;
printf("%d\n",ans);
//freopen("in","r",stdin);
//scanf("%d",&T);
//printf("time=%.3lf",(double)clock()/CLOCKS_PER_SEC);
return 0;
}