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
Output
Input
Output
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; }
相关文章推荐
- Mysql 和Oracle rows 区别
- SpringMVC注入Interceptor失败
- Infinite Sequence
- Mysql 和Oracle rows 区别
- Mysql 和Oracle rows 区别
- list_head数据结构分析
- Opencv3.0-python: 视频处理时报错color.cpp:7456: error: (-215) scn == 3 || scn == 4 的解决办法
- 实习入职第十六天:seekBar自定义样式
- 不用加法实现加法
- mysql数据库相关基本术语和概念
- 小结SpringMVC(三)
- elementFormDefault="qualified"
- Android开发:最详细的 Toolbar 开发实践总结
- C++作业7
- elementFormDefault="qualified"
- linux 进度条的实现及makefile的简单应用
- 为什么要设置环境变量,环境变量有什么用?
- Django完整的开发一个博客系统
- Django完整的开发一个博客系统
- Presentation201606(The Sketchy Database-Learning to Retrieve Badly Drawn Bunnies)