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. 多数据源 + Configuration中bean依赖注入顺序问题

    为什么要调用方法,而不是直接autowire? 官方文档 https://docs.spring.io/spring-boot/docs/current/reference/html/howto-da ...

  2. 关于box-shadow、border-radius不兼容ie8的解决办法

    本来从css3兼容ie9+挺好的,可是总有一些共识要求ie8+,于是就有了我们的苦逼的找解决办法.之前在网上查到一些说用 PIE.htc. But 我就是按照他说的写的没有管用.请教了一下别人才会写了 ...

  3. C# Linq 查询数据库(DataSet)生成 Tree

    效果图如下 cs代码 using System; using System.Collections.Generic; using System.ComponentModel; using System ...

  4. public class 与 class 的区别

    public class 与 class 的区别 1.一个类前面的public是可有可无的 2.如果一个类使用 public 修饰,则文件名必须与类名一致 3.如果一个类前面没有使用public修饰, ...

  5. C# List(T).Reverse 方法 顺序反转

    using System; using System.Collections.Generic; public class Example { public static void Main() { L ...

  6. DRF之注册响应分页组件

    注册器 注册器的作用就是以后我们不用自己手动的一条条的敲路径了,它可以帮助哦们直接去找对应的路由,不用传参了,知道这一点就可以了,不多说还是,上代码实例 第一步:导入模块from django.url ...

  7. OpenStack Weekly Rank 2015.08.10

    Module Reviews Drafted Blueprints Completed Blueprints Filed Bugs Resolved Bugs Cinder 5 1 1 6 12 Sw ...

  8. HTML5中video标签与canvas绘图的使用

    video标签的使用 video标签定义视频, 它是html5中的新标签, 它的属性如下(参考自文档): domo01 <!DOCTYPE html> <html lang=&quo ...

  9. LeetCode 167.两数之和(C++)

    给定一个已按照升序排列 的有序数组,找到两个数使得它们相加之和等于目标数. 函数应该返回这两个下标值 index1 和 index2,其中 index1 必须小于 index2. 说明: 返回的下标值 ...

  10. css实现高度垂直居中

    1:单行文字垂直居中: 如果一个容器中只有一行文字的话,定义height(高度)和 line-height(行高)相等即可. 如:<div style="height:25px;lin ...