D. Bicycle Race

题目连接:

http://www.codeforces.com/contest/659/problem/D

Description

Maria participates in a bicycle race.

The speedway takes place on the shores of Lake Lucerne, just repeating its contour. As you know, the lake shore consists only of straight sections, directed to the north, south, east or west.

Let's introduce a system of coordinates, directing the Ox axis from west to east, and the Oy axis from south to north. As a starting position of the race the southernmost point of the track is selected (and if there are several such points, the most western among them). The participants start the race, moving to the north. At all straight sections of the track, the participants travel in one of the four directions (north, south, east or west) and change the direction of movement only in bends between the straight sections. The participants, of course, never turn back, that is, they do not change the direction of movement from north to south or from east to west (or vice versa).

Maria is still young, so she does not feel confident at some turns. Namely, Maria feels insecure if at a failed or untimely turn, she gets into the water. In other words, Maria considers the turn dangerous if she immediately gets into the water if it is ignored.

Help Maria get ready for the competition — determine the number of dangerous turns on the track.

Input

The first line of the input contains an integer n (4 ≤ n ≤ 1000) — the number of straight sections of the track.

The following (n + 1)-th line contains pairs of integers (xi, yi) ( - 10 000 ≤ xi, yi ≤ 10 000). The first of these points is the starting position. The i-th straight section of the track begins at the point (xi, yi) and ends at the point (xi + 1, yi + 1).

It is guaranteed that:

the first straight section is directed to the north;

the southernmost (and if there are several, then the most western of among them) point of the track is the first point;

the last point coincides with the first one (i.e., the start position);

any pair of straight sections of the track has no shared points (except for the neighboring ones, they share exactly one point);

no pair of points (except for the first and last one) is the same;

no two adjacent straight sections are directed in the same direction or in opposite directions.

Output

Print a single integer — the number of dangerous turns on the track.

Sample Input

6

0 0

0 1

1 1

1 2

2 2

2 0

0 0

Sample Output

1

Hint

题意

一个图,给你一个多边形,然后有一个人在上面按照顺时针去走

问你有多少条线段,如果他一直走,就会走到这个多边形的内部去。

题解:

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

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

代码

#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e3+7;
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++;
cout<<ans<<endl;
}

Codeforces Round #346 (Div. 2) D. Bicycle Race 叉积的更多相关文章

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

    D. Bicycle Race 题目链接http://codeforces.com/contest/659/problem/D Description Maria participates in a ...

  2. Codeforces Round #346 (Div. 2)---E. New Reform--- 并查集(或连通图)

    Codeforces Round #346 (Div. 2)---E. New Reform E. New Reform time limit per test 1 second memory lim ...

  3. Codeforces Round #346 (Div. 2)

    前三题水 A #include <bits/stdc++.h> typedef long long ll; const int N = 1e5 + 5; int main() { int ...

  4. Codeforces Round #131 (Div. 2) E. Relay Race dp

    题目链接: http://codeforces.com/problemset/problem/214/E Relay Race time limit per test4 secondsmemory l ...

  5. Codeforces Round #346 (Div. 2) A Round-House

    A. Round House 题目链接http://codeforces.com/contest/659/problem/A Description Vasya lives in a round bu ...

  6. Codeforces Round #346 (Div. 2) A. Round House 水题

    A. Round House 题目连接: http://www.codeforces.com/contest/659/problem/A Description Vasya lives in a ro ...

  7. Codeforces Round #346 (Div. 2) C Tanya and Toys

    C. Tanya and Toys 题目链接http://codeforces.com/contest/659/problem/C Description In Berland recently a ...

  8. Codeforces Round #346 (Div. 2) B Qualifying Contest

    B. Qualifying Contest 题目链接http://codeforces.com/contest/659/problem/B Description Very soon Berland ...

  9. Codeforces Round #346 (Div. 2) G. Fence Divercity dp

    G. Fence Divercity 题目连接: http://www.codeforces.com/contest/659/problem/G Description Long ago, Vasil ...

随机推荐

  1. nesC编程入门

    1.接口 NesC程序主要由各式组件(component)构成,组件和组件之间通过特定的接口(interface)互相沟通.一个接口内声明了提供相关服务的方法(C语言函数).例如数据读取接口(Read ...

  2. windows和linux修改python的pip源

    python的pip安装包非常方便,然而其默认的镜像源在国外,下载的速度非常慢,推荐改成国内的镜像源. window平台修改pip源 找到系统盘下C:\C:\Users\用户名\AppData\Roa ...

  3. sicily 1193. Up the Stairs

    Time Limit: 1sec    Memory Limit:32MB  Description John is moving to the penthouse of a tall sky-scr ...

  4. HDU 3746 Cyclic Nacklace(KMP找循环节)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2087 题目大意:给你一个字符串,求出将字符串的最少出现两次循环节需要添加的字符数. 解题思路: 这题需 ...

  5. 20165301 预备作业三:Linux安装及命令入门

    预备作业三:Linux安装及命令入门 VirtualBox虚拟机的安装 在进行安装之前,原本以为有了娄老师的安装教程会是一件很容易的事情.万万没想到,在自己实际动手操作中,还是遇到了许多困难.通过与同 ...

  6. webStorage,离线缓存

    一.webStorage 1.目标 1.了解cookie的不足之处,引入webstorage的概念    2.学习并且掌握webstorage有哪两种    3.学习并且掌握sessionStorag ...

  7. css3 box-sizing属性值详解

    box-sizing属性可以为三个值之一:content-box(default),border-box,padding-box. content-box,border和padding不计算入widt ...

  8. python collections模块详解

    参考老顽童博客,他写的很详细,例子也很容易操作和理解. 1.模块简介 collections包含了一些特殊的容器,针对Python内置的容器,例如list.dict.set和tuple,提供了另一种选 ...

  9. Java String class methods

    Java String class methods 现在不推荐使用 StringTokenizer 类.建议使用 String 类的 split()方法或 regex(正则表达式). String c ...

  10. 初识 Fuzzing 工具 WinAFL

    转:https://paper.seebug.org/323/ 初识 Fuzzing 工具 WinAFL 作者:xd0ol1(知道创宇404实验室) 0 引子 本文前两节将简要讨论 fuzzing 的 ...