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

Input
6
0 0
0 1
1 1
1 2
2 2
2 0
0 0
Output
1
Input
16
1 1
1 5
3 5
3 7
2 7
2 9
6 9
6 7
5 7
5 3
4 3
4 4
3 4
3 2
5 2
5 1
1 1
Output
6

//想明白后就回发现这是一道水题,只怪自己英语不好,读题太费劲
//题意:一个数n,然后给出n+1个点,围成一个水池,每次都是只能往东南西北走,并且刚开始的方向一定是往北面走。其中有一些点若是不拐弯就一定会
//掉入水池,问有几个这样的点。选择比赛赛道的最南端为起始位置(如果有多个这样的点,选择最西的)
//有了以上的限定条件,可以知道左拐的点若一直走就会调入水中,所以看有几个左拐点就可以
#include <iostream>

using namespace std;

struct node
{
int x,y;
}data[]; int main()
{
int n,ans;
while(cin>>n)
{
ans=;
for(int i=;i<=n;i++)
cin>>data[i].x>>data[i].y;
for(int i=;i<=n;i++)
{
int fx,fy,xx,yy;
fx=data[i-].x-data[i-].x;
fy=data[i-].y-data[i-].y;
xx=data[i].x-data[i-].x;
yy=data[i].y-data[i-].y;
if(fx==&&fy>&&xx<&&yy==)
ans++;
else if(fx<&&fy==&&xx==&&yy<)
ans++;
else if(fx>&&fy==&&xx==&&yy>)
ans++;
else if(fx==&&fy<&&yy==&&xx>)
ans++;
}
cout<<ans<<endl;
}
return ;
}
 

2016NEFU集训第n+3场 D - Bicycle Race的更多相关文章

  1. 2016NEFU集训第n+5场 A - Chinese Girls' Amusement

    Description       You must have heard that the Chinese culture is quite different from that of Europ ...

  2. 2016NEFU集训第n+3场 E - New Reform

    Description Berland has n cities connected by m bidirectional roads. No road connects a city to itse ...

  3. 2016NEFU集训第n+3场 G - Tanya and Toys

    Description In Berland recently a new collection of toys went on sale. This collection consists of 1 ...

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

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

  5. (求凹包) Bicycle Race (CF 659D) 简单题

    http://codeforces.com/contest/659/problem/D     Maria participates in a bicycle race. The speedway t ...

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

    D. Bicycle Race 题目连接: http://www.codeforces.com/contest/659/problem/D Description Maria participates ...

  7. CodeForces 659D Bicycle Race (判断点是否为危险点)

    D - Bicycle Race Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u S ...

  8. codeforces 659D D. Bicycle Race(水题)

    题目链接: D. Bicycle Race time limit per test 1 second memory limit per test 256 megabytes input standar ...

  9. Contest1692 - 2019寒假集训第三十一场 UPC 11075 Problem D 小P的国际象棋

    非常简单的单点修改+区间加+区间查询.我用的是最近刚学的区间修改版本树状数组.  直接维护即可,注意修改后的单点值已经不是a[i],或者b[i],要通过区间查询求单点.不然是错的. 区间修改版本树状数 ...

随机推荐

  1. memcahced缓存特点

    1.key-value数据结构 2.所有数据保存在内存中 3.可以分布式集群 4.处理并发的机制是libevent事件机制 5.当内容容量达到指定值后,就基于LRU(Least Recently Us ...

  2. xml动态修改 dom4j修改

    xml的动态修改需要传入的参数 xml的位置(tomcat中的发布位置).修改后的xml需要保存的位置(因为动态修改,所以建议和xml未修改前的位置相同).添加的节点的信息.或者修改的节点的信息 SA ...

  3. C#编程之“串口通讯多次接收”

    摘要: 主要记录了再C#的串口开发时遇到的问题,以便后续遇到相同问题再重复砍树造轮子. 1.问题场景 板卡和PC间通过UART进行数据通讯,由PC给板卡发送控制命令,板卡返回相应的数据. 2.遇到的问 ...

  4. table表头thead固定

    <html> <head> <meta charset="utf-8"/> <script type="text/javascr ...

  5. Kruskal算法的简单实现

    嘛嘛嘛,好像大家在实现Kruskal算法是都是用的边集数组,判断图的连通性咱不会,o(╯□╰)o(为什么咱这么菜诶) Kruskal算法: 规则: (1)对每一条边按照从小到大进行排序 (2)加入边的 ...

  6. OOP in JS - Inheritance

    Summary You cause a class to inherit using ChildClassName.prototype = new ParentClass();. You need t ...

  7. Mac下MySQL的安装与配置

    之前一直用的是阿里云的服务器,在服务器上装了一个MySQL,但是今天发现到期了,而且续费时发现之前的大学生优惠不能用了,可是明明到6月份,大学生才毕业啊,shit!!!所以没办法只能在自己电脑上装一个 ...

  8. ubuntu14.04 下安装mysql5.6

    1.sudo apt-get install mysql-server-5.6 2.测试是否安装成功 ps aux |grep mysql mysql -u root -p 3.允许远程访问设置 su ...

  9. NSCondition用法

    NSCondition用法 使用NSCondition,实现多线程同步...举个列子 消费者跟生产者... 现在传言6s要出了.. 消费者想买6s.现在还没有6s.消费者等待6s生产. 生产了一个产品 ...

  10. Linux之top

    简介 top命令是Linux下常用的性能分析工具,能够实时显示系统中各个进程的资源占用状况,类似于Windows的任务管理器. top显示系统当前的进程和其他状况,是一个动态显示过程,即可以通过用户按 ...