codeforces 659D D. Bicycle Race(水题)
题目链接:
1 second
256 megabytes
standard input
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.
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.
Print a single integer — the number of dangerous turns on the track.
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
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(水题)的更多相关文章
- codeforces 577B B. Modulo Sum(水题)
题目链接: B. Modulo Sum time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- Codeforces Round #367 (Div. 2)---水题 | dp | 01字典树
A.Beru-taxi 水题:有一个人站在(sx,sy)的位置,有n辆出租车,正向这个人匀速赶来,每个出租车的位置是(xi, yi) 速度是 Vi;求人最少需要等的时间: 单间循环即可: #inclu ...
- codeforces 696A Lorenzo Von Matterhorn 水题
这题一眼看就是水题,map随便计 然后我之所以发这个题解,是因为我用了log2()这个函数判断在哪一层 我只能说我真是太傻逼了,这个函数以前听人说有精度问题,还慢,为了图快用的,没想到被坑惨了,以后尽 ...
- CodeForces 589I Lottery (暴力,水题)
题意:给定 n 和 k,然后是 n 个数,表示1-k的一个值,问你修改最少的数,使得所有的1-k的数目都等于n/k. 析:水题,只要用每个数减去n/k,然后取模,加起来除以2,就ok了. 代码如下: ...
- Codeforces Gym 100286G Giant Screen 水题
Problem G.Giant ScreenTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/con ...
- codeforces 710A A. King Moves(水题)
题目链接: A. King Moves 题意: 给出king的位置,问有几个可移动的位置; 思路: 水题,没有思路; AC代码: #include <iostream> #include ...
- codeforces 659A A. Round House(水题)
题目链接: A. Round House time limit per test 1 second memory limit per test 256 megabytes input standard ...
- CodeForces 489B BerSU Ball (水题 双指针)
B. BerSU Ball time limit per test 1 second memory limit per test 256 megabytes input standard input ...
- codeforces 702A A. Maximum Increase(水题)
题目链接: A. Maximum Increase time limit per test 1 second memory limit per test 256 megabytes input sta ...
随机推荐
- vs调试,监控变量
- java中各种时间格式的转化
http://www.chinaitpower.com/A/2005-01-14/104881.html 使用java.util.Calendar返回间隔天数 static int g ...
- 命令行运行java
运行TestLinuxCommand.java 代码 import java.io.BufferedReader; import java.io.BufferedWriter; import ...
- php程序执行过程--非宏观和微观而是写的程序一行一行的路径----利用xdebug了解一段程序的执行过程----覆盖率
1.xdebug_start_code_coverage();//在需要开始跟踪程序执行路径时使用 2.var_dump(xdebug_get_code_coverage());//在结尾使用打印程序 ...
- erlang中字符编码转换(转)
转自:http://www.thinksaas.cn/group/topic/244329/ 功能说明: erlang中对各种语言的编码支持不足,此代码是使用erlang驱动了著名的iconv编码库来 ...
- Java Enum的使用
最近为了便于对状态码的描述信息进行解析,学习了一下Enum的使用,发现还挺好使的. 首先,定义一个Enum的类Status,有两个属性statusValue状态码 以及 statusDesc状态描述 ...
- redis客户端连接,最大连接数查询与设置
##redis客户端连接数 redis通过监听一个TCP端口或socket的方式接收来自客户端的连接, 当与客户端建立连接后,redis内部会进行如下操作:()客户端socket会被设置为非阻塞模式, ...
- 如何创建虚拟硬盘 + os 读取硬盘参数代码
[0]README 0.1) 本文旨在演示如何利用 bximage 创建虚拟硬盘: 0.2) 利用 os 读取硬盘参数, source code from orange's implemention ...
- Javascript文件加载:LABjs和RequireJS
传统上,加载Javascript文件都是使用<script>标签. 就像下面这样: <script type="text/javascript" src=&quo ...
- kindeditor浏览器兼容性问题
1.kindeditor在IE下出现异常“对象不支持“attachEvent”属性或方法” 通过开发人员工具会发现: 这时问题就很明了,也就是IE11版本不支持“attachEvent”; 解决方案: ...