CodeForces 659D Bicycle Race (判断点是否为危险点)
Time Limit:1000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u
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
题意:一个多边形围成的湖,一个人绕着走。如果在某个位置不转弯直走的话会掉入湖里,
则认为这个弯是危险的。问有多少个这样的弯。
题解:第一种解法:从题目中的加粗字体可知人是从左下角往上走的,即顺时针走,画顺时针走的图可知向量b在向量a的逆时针方向,
即叉积大于0。注意千万不能看做逆时针走,一定要注意方向,否则结果会是n-ans。
第二种解法:可以发现,在内角为270°的地方才有可能掉到水里,设这样的地方有x个,
则内角和 180 * (n - 2) = 270 * x + (n - x) * 90,得到 x=(n-4)/2 。
代码一:
#include <iostream>
using namespace std;
int main()
{
int n;
while(cin>>n)
{
int i,ans=;
int a[],b[];
for(i=;i<=n;i++)
cin>>a[i]>>b[i];
for(i=;i<=n;i++)
if(((a[i-]-a[i-])*(b[i]-b[i-])-(a[i]-a[i-])*(b[i-]-b[i-]))>)
ans++;
cout<<ans<<endl;
}
return ;
}
代码二:
#include <cstdio>
using namespace std;
int main(){
int n;
scanf("%d",&n);
printf("%d\n",(n - )/);
return ;
}
CodeForces 659D Bicycle Race (判断点是否为危险点)的更多相关文章
- Codeforces 659D Bicycle Race【计算几何】
题目链接: http://codeforces.com/contest/659/problem/D 题意: 若干条直线围城的湖,给定直线的端点,判断多少个转点会有危险?(危险是指直走的的话会掉进水里) ...
- codeforces 659D . Bicycle Race 几何
题目链接 对相邻的三个点叉积判断一下就好. #include <iostream> #include <vector> #include <cstdio> #inc ...
- [ An Ac a Day ^_^ ] CodeForces 659D Bicycle Race 计算几何 叉积
问有多少个点在多边形内 求一遍叉积 小于零计数就好了~ #include<stdio.h> #include<iostream> #include<algorithm&g ...
- codeforces 659D D. Bicycle Race(水题)
题目链接: D. Bicycle Race time limit per test 1 second memory limit per test 256 megabytes input standar ...
- 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 ...
- 2016NEFU集训第n+3场 D - Bicycle Race
Description Maria participates in a bicycle race. The speedway takes place on the shores of Lake Luc ...
- CodeForces 8D Two Friends 判断三个圆相交
题意: 有两个人\(Alan\)和\(Bob\),他们现在都在\(A\)点,现在\(Bob\)想去\(B\)点,\(Alan\)想先到\(C\)点再去\(B\)点. \(Alan\)所走的总路程不能超 ...
随机推荐
- C语言字符篇(二)字符串处理函数
字符串处理函数 1. 拷贝 strcpy 2. 追加 strcat #include <string.h> char *strcpy(char *dest, const char ...
- Android Url相关工具 通用类UrlUtil
1.整体分析 1.1.源代码查看,可以直接Copy. public class UrlUtil { public static boolean isUrlPrefix(String url) { re ...
- sql查询作业答案
sql查询作业答案 阅读目录 一 题目 二 答案 一 题目 1.查询所有的课程的名称以及对应的任课老师姓名 2.查询学生表中男女生各有多少人 3.查询物理成绩等于100的学生的姓名 4.查询平均成 ...
- 4034: [HAOI2015]树上操作
4034: [HAOI2015]树上操作 链接 思路: 树链剖分.操作:单点修改,路径查询,子树修改. 代码: #include<cstdio> #include<algorithm ...
- Pycharm的使用一
一.编辑器的选择 Python 的学习过程少不了集成开发环境(IDE)或者代码编辑器,这些 Python 开发工具帮助开发者加快使用 Python 开发的速度,提高效率. 高效的代码编辑器或者 IDE ...
- Android学习记录(4)—在java中学习多线程下载的基本原理和基本用法①
多线程下载在我们生活中非常常见,比如迅雷就是我们常用的多线程的下载工具,当然还有断点续传,断点续传我们在下一节来讲,android手机端下载文件时也可以用多线程下载,我们这里是在java中写一个测试, ...
- leetcode 【 Remove Duplicates from Sorted List 】 python 实现
题目: Given a sorted linked list, delete all duplicates such that each element appear only once. For e ...
- Windows10使用pip安装python包时报错-UnicodeDecodeError: 'ascii' codec c
本人是Windows10,用的方法2解决的 原文链接http://blog.csdn.net/all_over_servlet/article/details/45112221 先交待下开发环境: 操 ...
- Canvas 给图形绘制阴影
/** * 图形绘制阴影 */ function initDemo6() { var canvas = document.getElementById("demo6"); if ( ...
- Oracle数据库存量数据抽取使用spool控制命令
spool是oracle sqlplus提供的一个控制命令.可以利用spool和select语句的组合动态生成一些失去了脚本或者一些数据. 1.spool作用: 在sqlplus中用来保存或打印查询 ...