题目链接:

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
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
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.

题意:

给这些转折点,问有多少个点在此点处不转弯就会立即掉湖里,注意是立即掉湖里,比赛时理解成后来掉湖里也算就写不出来,最后发现第二个样例才正确理解了;

思路:

因为有四个方向是的转弯点会立即掉湖里;

AC代码:

/*
2014300227 659D - 24 GNU C++11 Accepted 15 ms 2180 KB
*/
#include <bits/stdc++.h>
using namespace std;
const int N=1e5+;
int x[],y[];
int n;
int main()
{
scanf("%d",&n);
for(int i=;i<=n;i++)
{
scanf("%d%d",&x[i],&y[i]);
}
int ans=;
for(int i=;i<n;i++)
{
if(x[i-]==x[i])
{
if(y[i]>y[i-]){
if(x[i+]<x[i])
ans++;
}
else
{
if(x[i+]>x[i])ans++;
}
}
else
{
if(x[i-]<x[i])
{
if(y[i+]>y[i])ans++; }
else
{
if(y[i+]<y[i])ans++;
}
}
}
cout<<ans<<"\n";
return ;
}

codeforces 659D D. Bicycle Race(水题)的更多相关文章

  1. codeforces 577B B. Modulo Sum(水题)

    题目链接: B. Modulo Sum time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  2. Codeforces Round #367 (Div. 2)---水题 | dp | 01字典树

    A.Beru-taxi 水题:有一个人站在(sx,sy)的位置,有n辆出租车,正向这个人匀速赶来,每个出租车的位置是(xi, yi) 速度是 Vi;求人最少需要等的时间: 单间循环即可: #inclu ...

  3. codeforces 696A Lorenzo Von Matterhorn 水题

    这题一眼看就是水题,map随便计 然后我之所以发这个题解,是因为我用了log2()这个函数判断在哪一层 我只能说我真是太傻逼了,这个函数以前听人说有精度问题,还慢,为了图快用的,没想到被坑惨了,以后尽 ...

  4. CodeForces 589I Lottery (暴力,水题)

    题意:给定 n 和 k,然后是 n 个数,表示1-k的一个值,问你修改最少的数,使得所有的1-k的数目都等于n/k. 析:水题,只要用每个数减去n/k,然后取模,加起来除以2,就ok了. 代码如下: ...

  5. Codeforces Gym 100286G Giant Screen 水题

    Problem G.Giant ScreenTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/con ...

  6. codeforces 710A A. King Moves(水题)

    题目链接: A. King Moves 题意: 给出king的位置,问有几个可移动的位置; 思路: 水题,没有思路; AC代码: #include <iostream> #include ...

  7. codeforces 659A A. Round House(水题)

    题目链接: A. Round House time limit per test 1 second memory limit per test 256 megabytes input standard ...

  8. CodeForces 489B BerSU Ball (水题 双指针)

    B. BerSU Ball time limit per test 1 second memory limit per test 256 megabytes input standard input ...

  9. codeforces 702A A. Maximum Increase(水题)

    题目链接: A. Maximum Increase time limit per test 1 second memory limit per test 256 megabytes input sta ...

随机推荐

  1. 数据存储之Archiver、Unarchiver、偏好设置

    数组的归档 对象的归档 NSData多个对象的归档 NSArray多个对象的归档 偏好设置的存储 1.NSString.NSDictionary.NSArray.NSData.NSNumber等类型的 ...

  2. 【深入JAVA EE】Spring配置文件解析

    在阅读的过程中有不论什么问题,欢迎一起交流 邮箱:1494713801@qq.com    QQ:1494713801 一.Spring头信息 Spring配置文件的头部信息通常是固定不变的.但每个标 ...

  3. 怎样替换jar包的指定文件

    在做(或修改别人的)项目的时候,可能遇到要修改调用的的jar包内的类属性或方法的问题.在eclipse或是其他的IDE中是无法直接修改的,所以需要一个解压jar-->修改文件-->编译-- ...

  4. session 购物车

    package session; import java.io.IOException;import java.util.ArrayList;import java.util.List; import ...

  5. HDFS源码分析心跳汇报之周期性心跳

    HDFS源码分析心跳汇报之周期性心跳,近期推出!

  6. Mysql 5.7.18 利用 MySQL proxies_priv(模拟角色)实现类似用户组管理

    利用 MySQL proxies_priv(模拟角色)实现类似用户组管理 角色(Role)可以用来批量管理用户,同一个角色下的用户,拥有相同的权限. MySQL5.7.X以后可以模拟角色(Role)的 ...

  7. JavaScript系列问题

    JavaScript系列问题:  0.javascript 基础教程[温故而知新一] 1.通过JS变更页面字体的大小 2.图片压缩优化能有效提高网站浏览速度

  8. String代码示例

    package lianxi; public class lianxi0112 { public static void main(String[] args) { // TODO 自动生成的方法存根 ...

  9. mongo-connector导入数据到Es

    要求 基于mongo-connector同步数据,必须要求mongodb为复制集架构,原因是此插件是基于oplog操作记录进行数据同步的:而oplog可以说是Mongodb Replication的纽 ...

  10. android菜鸟学习笔记1----环境搭建

    Step1 JDK安装及配置: 1.下载并安装JDK: 根据自己系统情况,选择安装相应的JDK版本 当前系统:64位WIN8,内存8G 选择了Java SE 8u45 即JDK 1.8.0_45,可以 ...