[Codeforces 32E] Hide-and-Seek
Brief Intro:
给两个人的坐标,一堵墙和一面镜子,询问两人能否看见对方
Solution:
一道以分类讨论为主的计算几何题,
分别讨论两人坐标连线是否经过墙/镜子即可,
难点在于如何求出点x关于线段[A,B]的对称点:
- point sym(point x,point A,point B){return *dot(A,B)/dot(B,B)*B-A+x;}
以上给出一种方法:将线段[x,A]延长一倍,求出线段[x,x']的向量,再行加减即可
Code:
- #include <bits/stdc++.h>
- using namespace std;
- typedef complex<double> point;
- point a,b,w1,w2,m1,m2;
- point read(){double x,y;cin>>x>>y;return point(x,y);}
- double det(point a,point b){return imag(a*conj(b));}
- double dot(point a,point b){return real(a*conj(b));}
- bool on_seg(point x,point L,point R){return det(L-x,R-x)== && dot(L-x,R-x)<=;}
- bool seg_cross(point a,point b,point c,point d)
- {
- double s1=det(c-a,b-a)*det(b-a,d-a);
- double s2=det(a-c,d-c)*det(d-c,b-c);
- if(s1< || s2<) return false;
- if(s1== && s2==) return on_seg(c,a,b) || on_seg(d,a,b);
- return true;
- }
- point sym(point x,point A,point B){return *dot(A,B)/dot(B,B)*B-A+x;}
- bool check()
- {
- if(seg_cross(a,b,m1,m2))
- return !seg_cross(a,b,w1,w2) && det(b-a,m2-m1)==;
- else if(seg_cross(a,b,w1,w2))
- {
- point A=sym(m1,a-m1,m2-m1),B=sym(m1,b-m1,m2-m1);
- return (seg_cross(a,B,m1,m2) && !seg_cross(a,B,w1,w2) && !seg_cross(A,b,w1,w2));
- }
- return true;
- }
- int main()
- {
- a=read();b=read();w1=read();w2=read();m1=read();m2=read();
- cout << (check()?"YES":"NO");
- return ;
- }
Review:
1、求两线段是否有重合部分:
先判相交,再判叉积是否为0
2、判断一点是否在线段上:
先用叉积判是否在直线上,再用点积判线段两端是否在其两侧
[Codeforces 32E] Hide-and-Seek的更多相关文章
- 【BZOJ-1941】Hide and Seek KD-Tree
1941: [Sdoi2010]Hide and Seek Time Limit: 16 Sec Memory Limit: 162 MBSubmit: 830 Solved: 455[Submi ...
- [BZOJ1941][Sdoi2010]Hide and Seek
[BZOJ1941][Sdoi2010]Hide and Seek 试题描述 小猪iPig在PKU刚上完了无聊的猪性代数课,天资聪慧的iPig被这门对他来说无比简单的课弄得非常寂寞,为了消除寂寞感,他 ...
- BZOJ3402: [Usaco2009 Open]Hide and Seek 捉迷藏
3402: [Usaco2009 Open]Hide and Seek 捉迷藏 Time Limit: 3 Sec Memory Limit: 128 MBSubmit: 51 Solved: 4 ...
- BZOJ 3402: [Usaco2009 Open]Hide and Seek 捉迷藏
题目 3402: [Usaco2009 Open]Hide and Seek 捉迷藏 Time Limit: 3 Sec Memory Limit: 128 MB Description 贝 ...
- 3402: [Usaco2009 Open]Hide and Seek 捉迷藏
3402: [Usaco2009 Open]Hide and Seek 捉迷藏 Time Limit: 3 Sec Memory Limit: 128 MBSubmit: 78 Solved: 6 ...
- bzoj:1941: [Sdoi2010]Hide and Seek
1941: [Sdoi2010]Hide and Seek Time Limit: 16 Sec Memory Limit: 162 MBSubmit: 531 Solved: 295[Submi ...
- 【BZOJ】【1941】【SDOI2010】Hide and Seek
KD-Tree 一开始看错题了
- 洛谷 P2951 [USACO09OPEN]捉迷藏Hide and Seek
题目戳 题目描述 Bessie is playing hide and seek (a game in which a number of players hide and a single play ...
- 【BZOJ1941】Hide and Seek(KD-Tree)
[BZOJ1941]Hide and Seek(KD-Tree) 题面 BZOJ 洛谷 题解 \(KD-Tree\)对于每个点搜一下最近点和最远点就好了 #include<iostream> ...
- 【BZOJ1941】[Sdoi2010]Hide and Seek KDtree
[BZOJ1941][Sdoi2010]Hide and Seek Description 小猪iPig在PKU刚上完了无聊的猪性代数课,天资聪慧的iPig被这门对他来说无比简单的课弄得非常寂寞,为了 ...
随机推荐
- bzoj2002: [Hnoi2010]Bounce 弹飞绵羊 分块
这个题体现了分块不只是最大值最小值众数次数,而是一种清真的思想. 我们把整个序列分块,在每个块里处理每个位置跳出这个块的次数和跳出的位置,那么每次修改n0.5,每次查询也是,那么O(m* n0.5)的 ...
- bzoj2424 [HAOI2010]订货 dp+单调性
[HAOI2010]订货 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 1311 Solved: 884[Submit][Status][Discu ...
- kafka.common.ConsumerRebalanceFailedException异常解决
kafka.common.ConsumerRebalanceFailedException: group_dd-1446432618163-2746a209 can't rebalance after ...
- python监控服务器
import paramikoimport threadingimport reimport timeimport stringfrom sendmail import send_maildef ss ...
- 设计模式开篇综述(Java)
设计原则是规范,设计模式是技巧.如果在项目中能够灵活运用这些基础知识,那么我相信一定会得到意想不到的收获. 接下来的时间里,我将继续学习设计模式,将对每一个设计模式从以下几点进行分析和学习,如有不妥当 ...
- webpack3基础知识
## 本地化安装webpack ## 1. npm init //npm初始化生成package.json文件 2. npm install --save-dev webpack //安装webpac ...
- HDU2544最短路---(Dijkstra)
Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission( ...
- 优化IDEA启动速度,快了好多。后面有什么优化点,会继续往里面添加
1.优化启动 修改bin/idea.exe.vmoptions文件如下: -Xms256m 初始堆大小-Xmx384m 最大堆大小 -XX:+UseParNewGC 使用并行收集算法 2. ...
- bzoj1575 [Usaco2009 Jan]气象牛Baric
传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=1575 [题解] 动态规划,令f[i,j]表示前i个选了j个,且第i个必选的最小值. 转移就枚 ...
- 51nod 1060 最复杂的数
把一个数的约数个数定义为该数的复杂程度,给出一个n,求1-n中复杂程度最高的那个数. 例如:12的约数为:1 2 3 4 6 12,共6个数,所以12的复杂程度是6.如果有多个数复杂度相等,输出最 ...