Codeforces Round #346 (Div. 2) D Bicycle Race (叉积)

Note

The first sample corresponds to the picture:

The picture shows that you can get in the water under unfortunate circumstances only at turn at the point (1, 1). Thus, the answer is 1.


题意:给出一个多边形的所有点坐标(按顺序给),某人求顺时针走一圈有多少条边使他走进多边形内。

分析:这个人在顺时针走,如果连着的两条线段,是逆时针的,显然这个人就走到多边形内部去了

这个就用个叉积去判一判就好了。

#include <cstdio>
#include <cstring>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;
const double eps = 1e-6;
const double pi = acos(-1.0);
const int INF = 0x3f3f3f3f;
const int MOD = 1000000007;
#define ll long long
#define CL(a,b) memset(a,b,sizeof(a))
#define lson (i<<1)
#define rson ((i<<1)|1)
#define MAXN 100010

struct node
{
    int x,y;
}s[1010];

int chaji(node A, node B, node C)
{
    return (A.x-B.x)*(C.y-B.y)-(C.x-B.x)*(A.y-B.y);
}

int main()
{
    int n;
    while(scanf("%d",&n)==1)
    {
        for(int i=0; i<=n; i++)
            cin>>s[i].x>>s[i].y;
        s[n+1].x = s[1].x;
        s[n+1].y = s[1].y;
        int ans = 0;
        for(int i=1; i<=n; i++)
        {
            if(chaji(s[i-1], s[i], s[i+1]) < 0)
                ans++;
        }
        cout<<ans<<endl;
    }
    return 0;
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值