D. Bicycle Race

题目链接http://codeforces.com/contest/659/problem/D

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

6

0 0

0 1

1 1

1 2

2 2

2 0

0 0

题意:

给你n个点。这些点连成一个不规则环。环中间是湖,问在转向时有多少种可能冲进水里。

题解:

湖是顺时针,所以只要找出相邻两条边构成逆时针即可。

代码:

#include<bits/stdc++.h>
using namespace std;
const int maxn = 1123456789;
struct node {int x,y;};
node s[1010];
int n;
int main()
{
scanf("%d",&n);
int zx,zy,xx,yy,x,y;
scanf("%d %d",&xx,&yy);
zx = xx;zy = yy;
for (int i = 2; i<= n;i++){
scanf("%d %d",&x,&y);
s[i-1].x = x-xx;
s[i-1].y = y-yy;
xx = x;
yy = y;
}
s[n].x = zx - xx;s[n].y = zy - yy;
int c = 0;
for (int i = 1;i < n;i++){
if ((s[i].x<0&&s[i+1].y<0)||(s[i].y<0&&s[i+1].x>0)||(s[i].x>0&&s[i+1].y>0)||(s[i].y>0&&s[i+1].x<0))
c++;
}
cout<<c<<endl;
return 0;
}

Codeforces Round #346 (Div. 2) D Bicycle Race的更多相关文章

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

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

  2. Codeforces Round #346 (Div. 2)---E. New Reform--- 并查集(或连通图)

    Codeforces Round #346 (Div. 2)---E. New Reform E. New Reform time limit per test 1 second memory lim ...

  3. Codeforces Round #346 (Div. 2)

    前三题水 A #include <bits/stdc++.h> typedef long long ll; const int N = 1e5 + 5; int main() { int ...

  4. Codeforces Round #131 (Div. 2) E. Relay Race dp

    题目链接: http://codeforces.com/problemset/problem/214/E Relay Race time limit per test4 secondsmemory l ...

  5. Codeforces Round #346 (Div. 2) A Round-House

    A. Round House 题目链接http://codeforces.com/contest/659/problem/A Description Vasya lives in a round bu ...

  6. Codeforces Round #346 (Div. 2) A. Round House 水题

    A. Round House 题目连接: http://www.codeforces.com/contest/659/problem/A Description Vasya lives in a ro ...

  7. Codeforces Round #346 (Div. 2) C Tanya and Toys

    C. Tanya and Toys 题目链接http://codeforces.com/contest/659/problem/C Description In Berland recently a ...

  8. Codeforces Round #346 (Div. 2) B Qualifying Contest

    B. Qualifying Contest 题目链接http://codeforces.com/contest/659/problem/B Description Very soon Berland ...

  9. Codeforces Round #346 (Div. 2) G. Fence Divercity dp

    G. Fence Divercity 题目连接: http://www.codeforces.com/contest/659/problem/G Description Long ago, Vasil ...

随机推荐

  1. 在C中判断变量存储类型(字符常量/数组/动态变量)

    在C中判断变量存储类型(字符常量/数组/动态变量) 在chinaunix论坛上有人问到关于变量存府类型的问题,我觉得可以写个测试代码加深大家对内存使用和布局的理解.下面我把原问题及处理办法贴出来,限供 ...

  2. MongoDB自学笔记1----1.1 NoSQL是什么?

    第一章 走进MongoDB 1.1NoSQL是什么?       1.1.1NoSQL简介        对于不了解NoSQL的人都会认为NoSQL为No SQL,即不是SQL.但是这种理解是错误的, ...

  3. 写一些脚本的心得总结系列第4篇-------从数据库同步到redis

    5.从数据库同步到redis的. redis把数据放内存里,读取都非常方便,也提供了远超memcache的丰富数据结构.下面我举2个例子,比如1)把数据从数据库写入到redis: <?php $ ...

  4. 结构-行为-样式-angularJs ngAnimate(Js实现)

    声明 页面 Js 注意事项 官方链接 一.声明 注意animate的版本要与Angular的一致. <script src="jquery.1.9.1.min.js"> ...

  5. knn分类算法学习

    K最近邻(k-Nearest Neighbor,KNN)分类算法,是一个理论上比较成熟的方法,也是最简单的机器学习算法之一.该方法的思路是:如果一个样本在特征空间中的k个最相似(即特征空间中最邻近)的 ...

  6. Windows 8 卡在正在检查更新

    原文地址:https://answers.microsoft.com/en-us/windows/forum/windows_8-update/windows-update-not-updating- ...

  7. scrapy在ubuntu上安装总结

    此文档是本人学习时使用的,采用一个实例作为引导进行安装测试. 实例下载地址如下: https://github.com/sans-serif/scrapy-german-news#introducti ...

  8. jQuery.cssHooks

    概述 直接向 jQuery 中添加钩子,用于覆盖设置或获取特定 CSS 属性时的方法,目的是为了标准化 CSS 属性名或创建自定义属性. $.cssHooks 对象提供了一种通过定义函数来获取或设置特 ...

  9. C语言:json库使用学习

    Json基础 一.Json的概念 Json(Javascript Object Notation)全称为JavaScript对象表示法,是一种轻量级的数据交换格式,采用完全独立于语言的文本格式.JSO ...

  10. 【NOIP2014】DAY2题解+代码

    T1 傻逼题……不想写贴昨年代码了. 总之随便怎么搞都能过. 15年的DAY2T1怎么那么毒瘤真是越活越倒退] #include <iostream> #include <fstre ...