2016NEFU集训第n+3场 D - Bicycle Race
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
1
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
6 //想明白后就回发现这是一道水题,只怪自己英语不好,读题太费劲
//题意:一个数n,然后给出n+1个点,围成一个水池,每次都是只能往东南西北走,并且刚开始的方向一定是往北面走。其中有一些点若是不拐弯就一定会
//掉入水池,问有几个这样的点。选择比赛赛道的最南端为起始位置(如果有多个这样的点,选择最西的)
//有了以上的限定条件,可以知道左拐的点若一直走就会调入水中,所以看有几个左拐点就可以
#include <iostream> using namespace std; struct node
{
int x,y;
}data[]; int main()
{
int n,ans;
while(cin>>n)
{
ans=;
for(int i=;i<=n;i++)
cin>>data[i].x>>data[i].y;
for(int i=;i<=n;i++)
{
int fx,fy,xx,yy;
fx=data[i-].x-data[i-].x;
fy=data[i-].y-data[i-].y;
xx=data[i].x-data[i-].x;
yy=data[i].y-data[i-].y;
if(fx==&&fy>&&xx<&&yy==)
ans++;
else if(fx<&&fy==&&xx==&&yy<)
ans++;
else if(fx>&&fy==&&xx==&&yy>)
ans++;
else if(fx==&&fy<&&yy==&&xx>)
ans++;
}
cout<<ans<<endl;
}
return ;
}
2016NEFU集训第n+3场 D - Bicycle Race的更多相关文章
- 2016NEFU集训第n+5场 A - Chinese Girls' Amusement
Description You must have heard that the Chinese culture is quite different from that of Europ ...
- 2016NEFU集训第n+3场 E - New Reform
Description Berland has n cities connected by m bidirectional roads. No road connects a city to itse ...
- 2016NEFU集训第n+3场 G - Tanya and Toys
Description In Berland recently a new collection of toys went on sale. This collection consists of 1 ...
- Codeforces Round #346 (Div. 2) D Bicycle Race
D. Bicycle Race 题目链接http://codeforces.com/contest/659/problem/D Description Maria participates in a ...
- (求凹包) Bicycle Race (CF 659D) 简单题
http://codeforces.com/contest/659/problem/D Maria participates in a bicycle race. The speedway t ...
- Codeforces Round #346 (Div. 2) D. Bicycle Race 叉积
D. Bicycle Race 题目连接: http://www.codeforces.com/contest/659/problem/D Description Maria participates ...
- CodeForces 659D Bicycle Race (判断点是否为危险点)
D - Bicycle Race Time Limit:1000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u S ...
- codeforces 659D D. Bicycle Race(水题)
题目链接: D. Bicycle Race time limit per test 1 second memory limit per test 256 megabytes input standar ...
- Contest1692 - 2019寒假集训第三十一场 UPC 11075 Problem D 小P的国际象棋
非常简单的单点修改+区间加+区间查询.我用的是最近刚学的区间修改版本树状数组. 直接维护即可,注意修改后的单点值已经不是a[i],或者b[i],要通过区间查询求单点.不然是错的. 区间修改版本树状数 ...
随机推荐
- 形象化理解nice值越高优先级越低
当我们说起某个人很nice的时候,通常指的是那个人心地善良,很好说话,很容易相处.(相反,aggressive的人很可能是不nice的,因为老想抢夺别人的东西,尤其是在资源有限的情况下,恨不得一个蛋糕 ...
- FaceBook页面加载技术
1. 技术背景 FaceBook页面加载技术 试想这样一个场景,一个经常访问的网站,每次打开它的页面都要要花费6 秒:同时另外一个网站提供了相似的服务,但响应时间只需3 秒,那么你会如何选择呢?数据表 ...
- ecstore在MySQL5.7下维护报错WARNING:512 @ ALTER IGNORE TABLE
ecstore在MySQL5.7下维护报错WARNING:512 @ ALTER IGNORE TABLE 打开 /app/base/lib/application/dbtable.php , 替换A ...
- js onblur 和 onkeyup 事件用法
1. onblur 表示失去焦点时触发 2. onkeyup 表示键盘每输完一个字符之后触发,就是键盘上的按键被放开时. 例子如下: <!DOCTYPE HTML PUBLIC "-/ ...
- [DP之计数DP]
其实说实在 我在写这篇博客的时候 才刚刚草了一道这样类型的题 之前几乎没有接触过 接触过也是平时比赛的 没有系统的做过 可以说0基础 我所理解的计数dp就是想办法去达到它要的目的 而且一定要非常劲非常 ...
- javabean+servlet+jsp实现分页
前端实现用ligerUI实现分页,感觉用框架确实简单,闲着无聊,模拟着liger的分页界面实现了一遍(只要是功能,样式什么无视) 这里用基础的三层架构+servlet+jsp实现,思路很简单,把所有分 ...
- Math.round(),Math.ceil(),Math.floor()的区别
1.Math.round():根据"round"的字面意思"附近.周围",可以猜测该函数是求一个附近的整数,看下面几个例子就明白. 小数点后第一位<5 正 ...
- ng-Directive
伪代码: var myModule = angular.module(...); myModule.directive('namespaceDirectiveName', function facto ...
- apache 修改连接数(转)
1.先要修改最大连接数,必须了解Apache的MPM(Multi -Processing Modules,多道处理模块)Apache2.0中MPM分为3种(perfork.worker.event). ...
- Yii2 基于RESTful架构的 advanced版API接口开发 配置、实现、测试【转】
环境配置: 开启服务器伪静态 本处以apache为例,查看apache的conf目录下httpd.conf,找到下面的代码 LoadModule rewrite_module modules/mod_ ...