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 ...
随机推荐
- ICEcoder显示汉字出现乱码的处理
在网上看到icecoder这个小东西,是一个基于web的编辑器,很不错.唯一的缺点是打开的文件中汉字会变成乱码. 经查看源代码,在lib/file-control.php中,第89行是: echo ' ...
- SQLyog连接MySQL时出现的2058错误解决方法
配置新连接报错:错误号码 2058,分析是 mysql 密码加密方法变了. 解决方法:windows 下cmd 登录 mysql -u root -p 登录你的 mysql 数据库,然后执行这条SQL ...
- Cognos报表验证(添加字段)
1.打开后台Cognos 链接远程后台Cognos 2.打开要验证的报表 3.给右边的sql语句加个空格或者换行点击验证 4.查看业务视图中是否已经添加该字段 双击维度或者度量(添加字段所在的分类) ...
- HYSBZ 1208 宠物收养所 (Splay树)
题意:一家宠物收养所负责处理领养者与遗弃宠物业务,有人来领宠物,则领一只最理想的.若没有宠物了,领养者们就得等到宠物来,宠物一来立刻送给其中一个等待者.如果有两个理想的选择,则选择那个值较小的.收养所 ...
- Architecture:架构 元素与关系
http://www.iso-architecture.org/42010/cm/ Systems have architectures. In the Standard, the architect ...
- Java文件编译与反编译:javac命令和javap命令
1.创建一个Test.java文件,并输入内容 public class Test{ private int m; public int inc(){ return m + 1; } } 2.使用ja ...
- ajax 请求json数据中json对象的构造获取问题
前端的界面中,我想通过ajax来调用写好的json数据,并调用add(data)方法进行解析,请求如下: json数据如下: { “type”:"qqq", "lat&q ...
- 【简●解】[ZJOI2005]午餐
[简●解][ZJOI2005]午餐 [关键词] \(DP\) 排序/贪心 [分析] 首先,一个很明显的贪心思路,就是吃的慢的人先打饭.所以把数据按吃饭时间从大到小排一遍序. 根据\(dp\)的尿性,比 ...
- js中表格的相关操作
tHead:表头 tBodies:表格正文 tFoot:表格尾 rows:行 cells:列 表格的应用: 1.获取 2.表格创建 3.隔行变色 4.删除一行 <!DOCTYPE html> ...
- UVALive - 6275 Joint Venture (二分)
题意: 给定一个整数w, 然后给定n个数, 问有没有两个数之和恰好为w 分析: 现将n个数数组a[]排序, 然后用两个变量i,j指向开头和末尾, 如果a[i] + a[j] > w, i++, ...