您的位置:首页 > 其它

2016NEFU集训第n+3场 D - Bicycle Race

2016-06-05 19:42 411 查看
Description

Mariaparticipatesinabicyclerace.

ThespeedwaytakesplaceontheshoresofLakeLucerne,justrepeatingitscontour.Asyouknow,thelakeshoreconsistsonlyofstraightsections,directedtothenorth,south,eastorwest.

Let'sintroduceasystemofcoordinates,directingtheOxaxisfromwesttoeast,andtheOyaxisfromsouthtonorth.Asastartingpositionoftheracethesouthernmostpointofthetrackisselected(andifthereareseveralsuchpoints,themostwesternamongthem).Theparticipantsstarttherace,movingtothenorth.Atallstraightsectionsofthetrack,theparticipantstravelinoneofthefourdirections(north,south,eastorwest)andchangethedirectionofmovementonlyinbendsbetweenthestraightsections.Theparticipants,ofcourse,neverturnback,thatis,theydonotchangethedirectionofmovementfromnorthtosouthorfromeasttowest(orviceversa).

Mariaisstillyoung,soshedoesnotfeelconfidentatsometurns.Namely,Mariafeelsinsecureifatafailedoruntimelyturn,shegetsintothewater.Inotherwords,Mariaconsiderstheturndangerousifsheimmediatelygetsintothewaterifitisignored.

HelpMariagetreadyforthecompetition—determinethenumberofdangerousturnsonthetrack.

Input

Thefirstlineoftheinputcontainsanintegern(4 ≤ n ≤ 1000)—thenumberofstraightsectionsofthetrack.

Thefollowing(n + 1)-thlinecontainspairsofintegers(xi, yi)( - 10 000 ≤ xi, yi ≤ 10 000).Thefirstofthesepointsisthestartingposition.Thei-thstraightsectionofthetrackbeginsatthepoint(xi, yi)andendsatthepoint(xi + 1, yi + 1).

Itisguaranteedthat:

thefirststraightsectionisdirectedtothenorth;

thesouthernmost(andifthereareseveral,thenthemostwesternofamongthem)pointofthetrackisthefirstpoint;

thelastpointcoincideswiththefirstone(i.e.,thestartposition);

anypairofstraightsectionsofthetrackhasnosharedpoints(exceptfortheneighboringones,theyshareexactlyonepoint);

nopairofpoints(exceptforthefirstandlastone)isthesame;

notwoadjacentstraightsectionsaredirectedinthesamedirectionorinoppositedirections.

Output

Printasingleinteger—thenumberofdangerousturnsonthetrack.

SampleInput

Input
6
00
01
11
12
22
20
00


Output
1


Input
16
11
15
35
37
27
29
69
67
57
53
43
44
34
32
52
51
11


Output
6

//想明白后就回发现这是一道水题,只怪自己英语不好,读题太费劲
//题意:一个数n,然后给出n+1个点,围成一个水池,每次都是只能往东南西北走,并且刚开始的方向一定是往北面走。其中有一些点若是不拐弯就一定会
//掉入水池,问有几个这样的点。选择比赛赛道的最南端为起始位置(如果有多个这样的点,选择最西的)
//有了以上的限定条件,可以知道左拐的点若一直走就会调入水中,所以看有几个左拐点就可以


#include<iostream>

usingnamespacestd;

structnode
{
intx,y;
}data[1005];

intmain()
{
intn,ans;
while(cin>>n)
{
ans=0;
for(inti=0;i<=n;i++)
cin>>data[i].x>>data[i].y;
for(inti=2;i<=n;i++)
{
intfx,fy,xx,yy;
fx=data[i-1].x-data[i-2].x;
fy=data[i-1].y-data[i-2].y;
xx=data[i].x-data[i-1].x;
yy=data[i].y-data[i-1].y;
if(fx==0&&fy>0&&xx<0&&yy==0)
ans++;
elseif(fx<0&&fy==0&&xx==0&&yy<0)
ans++;
elseif(fx>0&&fy==0&&xx==0&&yy>0)
ans++;
elseif(fx==0&&fy<0&&yy==0&&xx>0)
ans++;
}
cout<<ans<<endl;
}
return0;
}



                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: