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 ...
随机推荐
- MY $MYVIMRC
set nocompatiblesource $VIMRUNTIME/vimrc_example.vim"source $VIMRUNTIME/mswin.vim"behave m ...
- php bz2扩展安装
php bz2扩展安装 2017年09月22日 14:14:36 Cookie_1030 阅读数:1781 版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn ...
- 自己封装一个readline函数实现服务器客户端回射
实现的功能:一次只能读取一行,客户端输入之后,一回车,马上字符串传到服务器端并显示在终端,然后服务器端将字符串又传回给客户端. 服务器端可以接收多个客户端的连接请求,并fork一个子进程来进行服务. ...
- Unexpected Exception caught setting 'username' on 'class com.bj186.crm.web.action.UserAction: Error setting expression 'username' with value ['艾格尼丝', ]
问题场景: 在使用表单向Action传递数据的时候, 遇到了这个问题, 导致了空指针异常. 问题描述: 10:14:56.622 [http-nio-8080-exec-45] ERROR com.o ...
- python爬虫---从零开始(四)BeautifulSoup库
BeautifulSoup是什么? BeautifulSoup是一个网页解析库,相比urllib.Requests要更加灵活和方便,处理高校,支持多种解析器. 利用它不用编写正则表达式即可方便地实现网 ...
- In line copy and paste to system clipboard
On the Wiki Wiki Activity Random page Videos Photos Chat Community portal To do Contribute Watch ...
- HNOI2006 花仙子的魔法
题目描述 题解: 考试的时候手画打表,然后半个小时磨了个式子:$$f[i][j]=f[i-1][j-1]+f[i][j-1]$$ 交上去$A$的时候都蒙了. 考后才知道原因. 考虑$n$维空间内原来有 ...
- spring踩坑
org.springframework.web.util.NestedServletException: Request processing failed; nested exception is ...
- Release Python Program as exe
py2exe 可以用来将python program 以exe的形式发布. 安装py2exe 对于python 3.x pip install py2exe 可以直接安装 对于python 2.7, ...
- 性能优化 java 24 次阅读 · 读完需要 15 分钟 0
摘要: 技术传播的价值,不仅仅体现在通过商业化产品和开源项目来缩短我们构建应用的路径,加速业务的上线速率,也会体现在优秀程序员在工作效率提升.产品性能优化和用户体验改善等小技巧方面的分享,以提高我们的 ...