D. Bicycle Race
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

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.

Examples
input
6
0 0
0 1
1 1
1 2
2 2
2 0
0 0
output
1
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 <bits/stdc++.h>

#define N 1010
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ll long long
#define INF 1000000007 using namespace std; int n; struct point{
int x,y;
}a[N]; void d(int &x) ///变化量,这里只考虑正负
{
if(x==) x=;
if(x>) x=;
if(x<) x=-;
} bool fun(point p0,point p1,point p2)
{
int x1=p1.x-p0.x;
int x2=p2.x-p1.x;
int y1=p1.y-p0.y;
int y2=p2.y-p1.y;
d(x1),d(x2),d(y1),d(y2);
if (y1 == && x2 == - ) return true;
if (x1 == && y2 == ) return true;
if (y1 == - && x2 == ) return true;
if (x1 == - && y2 == - ) return true; return false ;
} int main()
{
scanf("%d", &n);
for (int i = ; i <= n; i++)
scanf("%d%d", &a[i].x, &a[i].y);
a[n + ] = a[];
a[] = a[n];
int tot = ;
for (int i = ; i <= n; ++ i)
if (fun(a[i - ], a[i], a[i + ]))
tot++;
cout << tot ;
return ;
}

方法二:

我是没有搞懂。不过真是碉堡了。

cout<<(n-4)/2;
http://codeforces.com/blog/entry/44093

D. Bicycle Race_几何的更多相关文章

  1. codeforces 659D . Bicycle Race 几何

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

  2. 关于Three.js基本几何形状之SphereGeometry球体学习

    一.有关球体SphereGeometry构造函数参数说明 <1>.SphereGeometry(radius, widthSegments, heightSegments, phiStar ...

  3. 几何服务,cut功能测试

    关于几何服务 几何服务用于辅助应用程序执行各种几何计算,如缓冲区.简化.面积和长度计算以及投影.在 ArcGIS Server 管理器中启动几何服务之后,您才能够在应用程序开发过程中使用该服务. 问题 ...

  4. 几何服务,cut功能,输入要素target(修改后)内容。

    几何服务,cut功能测试,输入要素target(修改后)内容. {"displayFieldName":"","fieldAliases": ...

  5. 几何服务,cut功能,输入要素target(修改前)内容。

    几何服务,cut功能测试,输入要素target(修改前)内容. {"geometryType":"esriGeometryPolyline","geo ...

  6. 如何让你的UWP应用程序无缝调用几何作图

    有时候需要编辑一些几何图形,如三角形,圆锥曲线等,在UWP应用中加入这些几何作图功能是件费时间又很难做好的事.其实Windows 10 应用商店中已有一些专业的几何作图工具了,那么能借来一用吗?答案是 ...

  7. poj 2031Building a Space Station(几何判断+Kruskal最小生成树)

    /* 最小生成树 + 几何判断 Kruskal 球心之间的距离 - 两个球的半径 < 0 则说明是覆盖的!此时的距离按照0计算 */ #include<iostream> #incl ...

  8. NOIP2002矩形覆盖[几何DFS]

    题目描述 在平面上有 n 个点(n <= 50),每个点用一对整数坐标表示.例如:当 n=4 时,4个点的坐标分另为:p1(1,1),p2(2,2),p3(3,6),P4(0,7),见图一. 这 ...

  9. DOM 元素节点几何量与滚动几何量

    当在 Web 浏览器中查看 HTML 文档时,DOM 节点被解析,并被渲染成盒模型(如下图),有时我们需要知道一些信息,比如盒模型的大小,盒模型在浏览器中的位置等等,本文我们就来详细了解下元素节点的几 ...

随机推荐

  1. Sublime Text 3 3126 安装+注册码

    首先,到官网下载且安装,个人是安装版本的 https://www.sublimetext.com/3 接着,写入注册码.2016/11/26 亲测有效 —– BEGIN LICENSE —– Mich ...

  2. my01_Mysql router 安装

    Mysql router 主要用途是读写分离,主主故障自动切换,负载均衡,连接池等.安装如下 下载地址:https://dev.mysql.com/downloads/router/ tar -zxv ...

  3. 转 python trace walk DEMO

    https://blog.csdn.net/steadfast123/article/details/46965125 #quote from 'introduction to computation ...

  4. 性能测试工具LoadRunner23-LR之Analysis 性能分析

    一.图表分析 1.Average Transaction Response Time(事务平均响应时间) “事务平均响应时间”显示的是测试场景运行期间的每一秒内事务执行所用的平均时间,通过它可以分析测 ...

  5. (转)rsync数据备份方案

    rsync数据备份方案 原文:http://blog.51cto.com/irow10/1826458 最近整理了下公司的数据备份情况.以下是部分操作的过程 1.rsync数据备份,具体备份过程就不详 ...

  6. MATLAB矩阵求值和稀疏矩阵

    方阵的行列式: det(A) 矩阵线性无关的行数或列数,称为矩阵的秩. rank(A) 求3~20阶魔方矩阵的秩 for n=3:20 rank(magic(n)) end 矩阵的迹等于矩阵的对角线元 ...

  7. http三次握手四次挥手

    最近一直忙于看前端vue相关内容,后端相关内容没有跟进,文章停了3周,,,哎,还是懒吧!子曰生命在于运动,该学习还是要学的,文章嘛也还是要整理滴,不扯了--- 参考: https://blog.csd ...

  8. redis数据类型及常用命令使用

    redis干啥的,一般人都知道,但很多人只知道是个缓存数据库,其它的就不知道了,本猿无能亦是如此,然知耻而后勇,我们该理一理这里边的一些逻辑,看看redis究竟是怎么一回事儿,能干啥,怎么做的,这样才 ...

  9. ASP.NET WebForm 之 Ajax 请求后端处理

    概述 ASP.NET MVC中的异步用途非常广泛,操作起来也非常简单.前台请求异步请求 Controller下的Action 方法,后端返回ActionResult 即可.但是在ASP.NET Web ...

  10. 让GIt忽略SSL证书错误的方法

    当你通过HTTPS访问Git远程仓库,如果服务器的SSL证书未经过第三方机构签署,那么Git就会报错.这是十分合理的设计,毕竟未知的没有签署过的证书意味着很大安全风险.但是,如果你正好在架设Git服务 ...