题目链接:

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【计算几何】的更多相关文章

  1. [ An Ac a Day ^_^ ] CodeForces 659D Bicycle Race 计算几何 叉积

    问有多少个点在多边形内 求一遍叉积 小于零计数就好了~ #include<stdio.h> #include<iostream> #include<algorithm&g ...

  2. CodeForces 659D Bicycle Race (判断点是否为危险点)

    D - Bicycle Race Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u S ...

  3. codeforces 659D . Bicycle Race 几何

    题目链接 对相邻的三个点叉积判断一下就好. #include <iostream> #include <vector> #include <cstdio> #inc ...

  4. codeforces 659D D. Bicycle Race(水题)

    题目链接: D. Bicycle Race time limit per test 1 second memory limit per test 256 megabytes input standar ...

  5. (求凹包) Bicycle Race (CF 659D) 简单题

    http://codeforces.com/contest/659/problem/D     Maria participates in a bicycle race. The speedway t ...

  6. Codeforces Round #346 (Div. 2) D Bicycle Race

    D. Bicycle Race 题目链接http://codeforces.com/contest/659/problem/D Description Maria participates in a ...

  7. Codeforces Round #346 (Div. 2) D. Bicycle Race 叉积

    D. Bicycle Race 题目连接: http://www.codeforces.com/contest/659/problem/D Description Maria participates ...

  8. 2016NEFU集训第n+3场 D - Bicycle Race

    Description Maria participates in a bicycle race. The speedway takes place on the shores of Lake Luc ...

  9. Codeforces 528E Triangles 3000 - 计算几何

    题目传送门 传送点I 传送点II 传送点III 题目大意 给定$n$的平面上的直线,保证没有三条直线共点,两条直线平行.问随机选出3条直线交成的三角形面积的期望. 显然$S=\frac{1}{2}ah ...

随机推荐

  1. 自定义 TypeHandler

    自定义TypeHandler分为三个步骤: 1.编写自定义TypeHandler,并继承自抽象类BaseTypeHandler<T>,实现抽象方法 2.在mybatis-config.xm ...

  2. FPGA开发中的脚本语言

    多数FPGA开发者都习惯图形化界面(GUI).GUI方式简单易学,为小项目提供了一键式流程.然而,随着FPGA项目越来越复杂,在很多情况下GUI工具就阻碍了工作效率.因为GUI工具不能对整个开发过程提 ...

  3. 洛谷 P2153 [SDOI2009]晨跑

    题目描述 Elaxia最近迷恋上了空手道,他为自己设定了一套健身计划,比如俯卧撑.仰卧起坐等 等,不过到目前为止,他坚持下来的只有晨跑. 现在给出一张学校附近的地图,这张地图中包含N个十字路口和M条街 ...

  4. python基础一 day7 复习文件操作

    read()原样输出 读取出来的是字符串类型 readline()输出一行 读取出来的是字符串类型 readlines()把每行文本作为一个字符串存入列表,并返回列表 打开方式: b以bytes类型打 ...

  5. 搜索 || BFS || POJ 2157 Maze

    走迷宫拿宝藏,拿到所有对应的钥匙才能开门 *解法:从起点bfs,遇到门时先放入队列中,取出的时候看钥匙够不够决定开不开门,如果不够就把它再放回队列继续往下走,当队列里只有几个门循环的时候就可以退出,所 ...

  6. django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module

    pip3 install mysqlclient try again python manage.py makemigrations python manage.py migrate

  7. sleep 和wait的差别

    基本的差别 1.sleep 是Thread 类的方法,wait 是Object类中定义的方法 2.sleep()方法可以在任何地方使用 3.wait()方法只能在synchronized方法中使用,或 ...

  8. hdu3404 Switch lights

    题目描述 题解: 首先,由$SG$定理得SG(x,y)=mex(SG(x',y)^SG(x,y')^SG(x',y'))(x'<x,y'<y) 这里的$SG(x,y)$叫$Nim$积. $ ...

  9. ubuntu mysql配置方案

    Ubuntu常用服务器环境搭建--MySQL篇 MySQL 1.安装MySQL apt-get update apt-get install mysql-server 2.配置MySQL vi /et ...

  10. react-native打包apk常见错误收集

    react-native 0.59打包报错,信息如下,根据错误信息是因为react-native-cookies的sdk版本问题导致的 ./gradlew assembleRelease > C ...