D. Bicycle Race

题目连接:

http://www.codeforces.com/contest/659/problem/D

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

Sample Output

1

Hint

题意

一个图,给你一个多边形,然后有一个人在上面按照顺时针去走

问你有多少条线段,如果他一直走,就会走到这个多边形的内部去。

题解:

这个人在顺时针走,如果连着的两条线段,是逆时针的,显然这个人就走到多边形内部去了

这个就用个叉积去判一判就好了。

代码

#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e3+7;
pair<int,int>p[maxn];
bool check(pair<int,int> A,pair<int,int> B,pair<int,int> C)
{return (B.first-A.first)*(C.second-B.second)-(C.first-B.first)*(B.second-A.second)>0;
}
int main()
{int n,ans=0;scanf("%d",&n);n++;for(int i=1;i<=n;i++)scanf("%d%d",&p[i].first,&p[i].second);for(int i=3;i<=n;i++)if(check(p[i-2],p[i-1],p[i]))ans++;cout<<ans<<endl;
}

转载于:https://www.cnblogs.com/qscqesze/p/5342027.html

Codeforces Round #346 (Div. 2) D. Bicycle Race 叉积相关推荐

  1. Codeforces Round #346 (Div. 2)

    A - Round House 题意:长度为n个环.起始位置是a,然后给出b,b是正数代表顺时针跑b个单位.b是负数代表逆时针跑b个单位. 思路:基础数学题目吧. PS:对于C++和G++编译器而言 ...

  2. Codeforces Round #506 (Div. 3)

    Codeforces Round #506 (Div. 3) 实习期间事不多,对div3 面向题解和数据编程了一波 A. Many Equal Substrings 题目链接 A题就是找后缀和前缀重合 ...

  3. Codeforces Round #563 (Div. 2)/CF1174

    Codeforces Round #563 (Div. 2)/CF1174 CF1174A Ehab Fails to Be Thanos 其实就是要\(\sum\limits_{i=1}^n a_i ...

  4. 构造 Codeforces Round #302 (Div. 2) B Sea and Islands

    题目传送门 1 /* 2 题意:在n^n的海洋里是否有k块陆地 3 构造算法:按奇偶性来判断,k小于等于所有点数的一半,交叉输出L/S 4 输出完k个L后,之后全部输出S:) 5 5 10 的例子可以 ...

  5. Codeforces Round #696 (Div. 2) (A ~ E)超高质量题解(每日训练 Day.16 )

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 Codeforces Round #696 (Div. 2) (A ~ E)超高质量题解 比赛链接:h ...

  6. Codeforces Round #712 Div.2(A ~ F) 超高质量题解(每日训练 Day.15 )

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 Codeforces Round #712 Div.2(A ~ F) 题解 比赛链接:https:// ...

  7. Codeforces Round #701 (Div. 2) A ~ F ,6题全,超高质量良心题解【每日亿题】2021/2/13

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 目录 A - Add and Divide B - Replace and Keep Sorted C ...

  8. Codeforces Round #700 (Div. 2) D2 Painting the Array II(最通俗易懂的贪心策略讲解)看不懂来打我 ~

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 整场比赛的A ~ E 6题全,全部题目超高质量题解链接: Codeforces Round #700 ...

  9. Codeforces Round #699 (Div. 2) F - AB Tree(贪心、树上DP)超级清晰,良心题解,看不懂来打我 ~

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 Codeforces Round #699 (Div. 2) F - AB Tree Problem ...

最新文章

  1. 最新Pycharm开发工具安装步骤,四大步骤就能学会
  2. 在代码段中安排自己定义的栈空间
  3. OWASP出品:Xenotix XSS漏洞测试框架及简单使用
  4. Spring Boot中使用Redis数据库
  5. [Android Pro] listView和GridView的item设置的高度和宽度不起作用
  6. 如何理解皮尔逊相关系数(Pearson Correlation Coefficient)?
  7. java对象与内存控制
  8. 我可以隐藏HTML5号码输入的旋转框吗?
  9. 修改一行代码,将图像匹配效果提升14%
  10. SAP官网学习教程(3) HANA数据库开发
  11. Axure的使用---原型图
  12. 毕业季音乐计算机简谱,毕业季简谱(歌词)-贺敬轩演唱-桃李醉春风记谱
  13. RocketMQ 源码分析 14 事务消息02
  14. 用python根据最新的汇率,假设你要出国留学要换外币,输入一定数量的人民币,比如1000元人民币, 按照中国银行的现钞卖出价,输出可换到对应的加元和澳元分别是多少。
  15. 计算机找不管理员,Win7系统鼠标右键找不到“管理员获取所有权”选项怎么办...
  16. 经典图书介绍:广义相对论--1972讲稿
  17. 遥感卫星不同光谱带介绍(Band 1 - Band 13)
  18. 腾讯又签下一工作室,游戏建模未来发展无法想象,你还不抓紧时间?
  19. 解决 C# GetPixel 和 SetPixel 效率问题
  20. [Redis实战]单文件夹启动多实例,redis哨兵+主从复制完整demo样例[windows环境]

热门文章

  1. 截取屏幕并保存为BMP文件
  2. 匹配yyyy-mm-dd日期格式的的正则表达式
  3. 征稿通知!ICCV 2021 第一届面向意图表达的手绘草图研讨会
  4. 谷歌大脑:探索权重无关神经网络
  5. 视频编辑利器,不喜欢就框除!开源视频物体移除软件video object removal
  6. CVPR 2019 | 旷视提出新型目标检测损失函数:定位更精准
  7. Python 实现简单的爬虫
  8. 5行Python 代码就能让你的电脑永不息屏
  9. 你想入门Python,还是得看这篇文章
  10. PyTorch + NumPy这么做会降低模型准确率?