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
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.
解题报告:
几何公式:
因为人从最左下角走起,那么他有危险的方式只有如图所示的四种方式
#include <bits/stdc++.h> #define N 1010
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ll long long
#define INF 1000000007 using namespace std; int n; struct point{
int x,y;
}a[N]; void d(int &x) ///变化量,这里只考虑正负
{
if(x==) x=;
if(x>) x=;
if(x<) x=-;
} bool fun(point p0,point p1,point p2)
{
int x1=p1.x-p0.x;
int x2=p2.x-p1.x;
int y1=p1.y-p0.y;
int y2=p2.y-p1.y;
d(x1),d(x2),d(y1),d(y2);
if (y1 == && x2 == - ) return true;
if (x1 == && y2 == ) return true;
if (y1 == - && x2 == ) return true;
if (x1 == - && y2 == - ) return true; return false ;
} int main()
{
scanf("%d", &n);
for (int i = ; i <= n; i++)
scanf("%d%d", &a[i].x, &a[i].y);
a[n + ] = a[];
a[] = a[n];
int tot = ;
for (int i = ; i <= n; ++ i)
if (fun(a[i - ], a[i], a[i + ]))
tot++;
cout << tot ;
return ;
}
方法二:
我是没有搞懂。不过真是碉堡了。
cout<<(n-4)/2;
http://codeforces.com/blog/entry/44093
D. Bicycle Race_几何的更多相关文章
- codeforces 659D . Bicycle Race 几何
题目链接 对相邻的三个点叉积判断一下就好. #include <iostream> #include <vector> #include <cstdio> #inc ...
- 关于Three.js基本几何形状之SphereGeometry球体学习
一.有关球体SphereGeometry构造函数参数说明 <1>.SphereGeometry(radius, widthSegments, heightSegments, phiStar ...
- 几何服务,cut功能测试
关于几何服务 几何服务用于辅助应用程序执行各种几何计算,如缓冲区.简化.面积和长度计算以及投影.在 ArcGIS Server 管理器中启动几何服务之后,您才能够在应用程序开发过程中使用该服务. 问题 ...
- 几何服务,cut功能,输入要素target(修改后)内容。
几何服务,cut功能测试,输入要素target(修改后)内容. {"displayFieldName":"","fieldAliases": ...
- 几何服务,cut功能,输入要素target(修改前)内容。
几何服务,cut功能测试,输入要素target(修改前)内容. {"geometryType":"esriGeometryPolyline","geo ...
- 如何让你的UWP应用程序无缝调用几何作图
有时候需要编辑一些几何图形,如三角形,圆锥曲线等,在UWP应用中加入这些几何作图功能是件费时间又很难做好的事.其实Windows 10 应用商店中已有一些专业的几何作图工具了,那么能借来一用吗?答案是 ...
- poj 2031Building a Space Station(几何判断+Kruskal最小生成树)
/* 最小生成树 + 几何判断 Kruskal 球心之间的距离 - 两个球的半径 < 0 则说明是覆盖的!此时的距离按照0计算 */ #include<iostream> #incl ...
- NOIP2002矩形覆盖[几何DFS]
题目描述 在平面上有 n 个点(n <= 50),每个点用一对整数坐标表示.例如:当 n=4 时,4个点的坐标分另为:p1(1,1),p2(2,2),p3(3,6),P4(0,7),见图一. 这 ...
- DOM 元素节点几何量与滚动几何量
当在 Web 浏览器中查看 HTML 文档时,DOM 节点被解析,并被渲染成盒模型(如下图),有时我们需要知道一些信息,比如盒模型的大小,盒模型在浏览器中的位置等等,本文我们就来详细了解下元素节点的几 ...
随机推荐
- Asp.net获取系统信息
[DllImport("kernel32")] public static extern void GlobalMemoryStatus(ref MEMORY_INF ...
- 4-----Scrapy框架中选择器的用法
Scrapy提取数据有自己的一套机制,被称作选择器(selectors),通过特定的Xpath或者CSS表达式来选择HTML文件的某个部分Xpath是专门在XML文件中选择节点的语言,也可以用在HTM ...
- js学习笔记 -- 函数
js函数有类似javaMethod用法 Math.max.apply( Math.max.call( Array map,reduce,filter,sort , , , , , , , , ]; v ...
- c语言字符函数
函数名: stpcpy 功 能: 拷贝一个字符串到另一个 用 法: char *stpcpy(char *destin, char *source); 程序例: #include <stdi ...
- drop_caches控制page cache
drop_caches Writing to this will cause the kernel to drop clean caches, as well as reclaimable slab ...
- Murano Weekly Meeting 2015.08.04
Meeting time: 2015.August.4th 1:00~2:00 Chairperson: Serg Melikyan, PTL from Mirantis Meeting summa ...
- Apache Beam的特点
不多说,直接上干货! Apache Beam 有两大特点: 1.统一了数据批处理(batch)和流处理(stream)编程范式: 2.能在任何执行引擎上运行. 它不仅为模型设计.更为执行一系列数据导向 ...
- @enable跟@import注解
参考文章: 讲@import的相关内容:https://blog.csdn.net/u012437781/article/details/78626134 讲为什么registrar没有注入:http ...
- JavaScript Date 学习心得
1.要创建一个日期对象,使用new 操作符和Date构造函数即可: var date=new Date() 在调用Date构造函数而不传递参数的情况下,新创建的对象可以自动获得当前日期和时间.必须传入 ...
- c# 远程连接sql server 2008问题
http://hi.baidu.com/lzghxjt/item/d42bd8f7066a3ad86325d280 远程连接不上可以在防火墙新建入站规则