Codeforces 659D Bicycle Race【计算几何】
题目链接:
http://codeforces.com/contest/659/problem/D
题意:
若干条直线围城的湖,给定直线的端点,判断多少个转点会有危险?(危险是指直走的的话会掉进水里)
分析:
- 观察法:减去竖直水平的四条边,剩下的每两条边的交点就是答案。
- 求叉积:看两个向量夹角,如果夹角小于90度,则直走的话会掉进水里。
代码:
#include<cstdio>
#define sa(m) scanf("%d",&m)
int main (void)
{
int n;sa(n);
int a, b;
for(int i = 0; i <= n; i++){
sa(a);sa(b);
}
printf("%d\n", (n - 4)/2);
}
#include<cstdio>
const int maxn = 1000 +5;
int x[maxn], y[maxn];
#define sa(m) scanf("%d",&m)
int judge(int x1, int y1, int x2, int y2, int x3, int y3)
{
return (x2 - x1) * (y3 - y2) - (y2 - y1) * (x3 - x2) > 0;
}
int main (void)
{
int n;sa(n);
int a, b;
for(int i = 0; i <= n; i++){
sa(x[i]);sa(y[i]);
}
int res = 0;
for(int i = 1; i < n; i++){
res += judge(x[i - 1], y[i - 1], x[i], y[i], x[i + 1], y[i + 1]);
}
printf("%d\n", res);
return 0;
}
Codeforces 659D Bicycle Race【计算几何】的更多相关文章
- [ An Ac a Day ^_^ ] CodeForces 659D Bicycle Race 计算几何 叉积
问有多少个点在多边形内 求一遍叉积 小于零计数就好了~ #include<stdio.h> #include<iostream> #include<algorithm&g ...
- CodeForces 659D Bicycle Race (判断点是否为危险点)
D - Bicycle Race Time Limit:1000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u S ...
- codeforces 659D . Bicycle Race 几何
题目链接 对相邻的三个点叉积判断一下就好. #include <iostream> #include <vector> #include <cstdio> #inc ...
- codeforces 659D D. Bicycle Race(水题)
题目链接: D. Bicycle Race time limit per test 1 second memory limit per test 256 megabytes input standar ...
- (求凹包) 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://codeforces.com/contest/659/problem/D Description Maria participates in a ...
- 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 528E Triangles 3000 - 计算几何
题目传送门 传送点I 传送点II 传送点III 题目大意 给定$n$的平面上的直线,保证没有三条直线共点,两条直线平行.问随机选出3条直线交成的三角形面积的期望. 显然$S=\frac{1}{2}ah ...
随机推荐
- 重新部署mysql遇到的问题
Windows 2008 Server R2 MySql: 5.7 下载Mysql. 配置mysql环境变量 注册mysql服务.(mysqld install) 移除注册,sc delete mys ...
- web页面调用IOS的事件
/** * js 调用ios的方法 * @param callback */ function connectWebViewJavascriptBridge(callback) { if (windo ...
- CSS 循环动画效果。
@-moz-keyframes revolving{ 0{ -moz-transform: rotate(0deg); -webkit-transform: rotate(0deg); } 25%{ ...
- Mysql数据库表的迁移和表的复制
同一台服务器上的,数据库之间的表的迁移: create table db.tablename as select * from db2.tablename; 此sql使用于mysql,从一台服务器上的 ...
- nodejs,python,sublime和Eclipse的包管理器
Python的包管理器叫pip. 首先安装Python运行环境Python 3.7.0:https://www.python.org/downloads/release/python-370/ Pyt ...
- Postman 安装及使用入门教程 | 前后台 写接口的 徐工给的
https://www.cnblogs.com/mafly/p/postman.html
- PHP15 Smarty模板
学习目标 Smarty基本概念 Smarty安装和配置 Smarty模板设计 Smarty流程控制 Smarty基本概念 一种模板引擎,在系统中进行预处理和过滤数据.是主流的PHP模板引擎,此外PHP ...
- Java ArrayList中去掉相同的元素并保留相同元素中的最后一个
实现思路:将list对象循环两次,拿外层数据和里面的数据对比,一样的删除外层(外层元素肯定比内存的靠前),如果一样的话,删除外层数据,这样最后输出外层数据的list,结果就能保证唯一性,并且保留了后面 ...
- C# 如何正确删除List中的item
参考博客 https://blog.csdn.net/Le_Sam/article/details/75633737 https://www.cnblogs.com/hedianzhan/p/9130 ...
- js检测对象是否是数组
js检测对象是否是数组 可以通过instanceof 方法一. var arr=[] arr instanceof Array //true var obj={} obj instanceof A ...