D - Bicycle Race

Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u

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

题意:一个多边形围成的湖,一个人绕着走。如果在某个位置不转弯直走的话会掉入湖里,

   则认为这个弯是危险的。问有多少个这样的弯。

题解:第一种解法:从题目中的加粗字体可知人是从左下角往上走的,即顺时针走,画顺时针走的图可知向量b在向量a的逆时针方向,

   即叉积大于0。注意千万不能看做逆时针走,一定要注意方向,否则结果会是n-ans。

   第二种解法:可以发现,在内角为270°的地方才有可能掉到水里,设这样的地方有x个,

   则内角和 180 * (n - 2) = 270 * x + (n - x) * 90,得到 x=(n-4)/2 。

代码一:

#include <iostream>
using namespace std;
int main()
{
int n;
while(cin>>n)
{
int i,ans=;
int a[],b[];
for(i=;i<=n;i++)
cin>>a[i]>>b[i];
for(i=;i<=n;i++)
if(((a[i-]-a[i-])*(b[i]-b[i-])-(a[i]-a[i-])*(b[i-]-b[i-]))>)
ans++;
cout<<ans<<endl;
}
return ;
}

代码二:

#include <cstdio>
using namespace std;
int main(){
int n;
scanf("%d",&n);
printf("%d\n",(n - )/);
return ;
}

CodeForces 659D Bicycle Race (判断点是否为危险点)的更多相关文章

  1. Codeforces 659D Bicycle Race【计算几何】

    题目链接: http://codeforces.com/contest/659/problem/D 题意: 若干条直线围城的湖,给定直线的端点,判断多少个转点会有危险?(危险是指直走的的话会掉进水里) ...

  2. codeforces 659D . Bicycle Race 几何

    题目链接 对相邻的三个点叉积判断一下就好. #include <iostream> #include <vector> #include <cstdio> #inc ...

  3. [ An Ac a Day ^_^ ] CodeForces 659D Bicycle Race 计算几何 叉积

    问有多少个点在多边形内 求一遍叉积 小于零计数就好了~ #include<stdio.h> #include<iostream> #include<algorithm&g ...

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

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

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

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

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

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

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

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

  8. 2016NEFU集训第n+3场 D - Bicycle Race

    Description Maria participates in a bicycle race. The speedway takes place on the shores of Lake Luc ...

  9. CodeForces 8D Two Friends 判断三个圆相交

    题意: 有两个人\(Alan\)和\(Bob\),他们现在都在\(A\)点,现在\(Bob\)想去\(B\)点,\(Alan\)想先到\(C\)点再去\(B\)点. \(Alan\)所走的总路程不能超 ...

随机推荐

  1. 华为ensp工具栏丢失解决方法

    电脑是win8系统 不知道什么原因,华为模拟器的工具栏神奇的消失了,感觉很郁闷,每次要写字的时候都找不到在哪里(菜单里也没有),于是在官方论坛里面找了一下终于找出原因了. 关闭ensp,点击属性,进入 ...

  2. 使用postMan测试insert或者update接口

    URL : http://localhost:8099/orderVoice/updateAgentLogin?access_token=7f10e803-f886-47df-b3dc-9ed307d ...

  3. JS中调用android和ios系统手机打开相机并可选择相册功能

    编写不易,如有转载,请声明出处: 梦回河口:http://blog.csdn.net/zxc514257857/article/details/57626154 实现android手机打开相机选择相册 ...

  4. 1008: [HNOI2008]越狱(计数问题)

    1008: [HNOI2008]越狱 Time Limit: 1 Sec  Memory Limit: 162 MBSubmit: 11361  Solved: 4914[Submit][Status ...

  5. 缓存(CDN缓存,浏览器(客户端)缓存)

    1.什么是缓存? 缓存是一种数据结构,用于快速查找以及执行的操作结果.因此,如果一个操作执行起来很慢,对于常用的输入数据就可以将操作的结果缓存,并在下次调用该操作时使用缓存的数据. 缓存是一个到处都存 ...

  6. python语法root=Tkinter.Tk()

    1. Tkinter 是一个python模块,是一个调用Tcl/Tk的接口,它是一个跨平台的脚本图形界面接口.Tkinter不是唯一的python图形编程接口,但是是 其中比较流行的一个.最大的特点是 ...

  7. 关于代码通过API操作阿里云RDS的巨坑

    由于项目原因,要通过API操作阿里云的数据库,于是简单研究了一下阿里云提供的相关文档,发现官方提供了.NET的SDK,而且还提供了github开源代码,这个要为阿里点赞! 于是到github上弄了一份 ...

  8. Win10安装bash慢的解决方案

    电脑的Win10系统经过最近一年大量软件的装装删删,感觉已经有问题了,而且也存在大量无法清理的垃圾,占用着宝贵的SSD空间... 重新做系统的想法已经有一段时间了,正好赶上Win10的大更新 Crea ...

  9. DOS程序员手册(八)

    备,就可以从程序中访问驱动程序.可以用句柄功能调用来     打开设备(见列表12.9)         列表12.9           /*example.C               List ...

  10. 【Power of Two】cpp

    题目: Given an integer, write a function to determine if it is a power of two. 代码: class Solution { pu ...