主题链接:点击打开链接

必须指出的是,反射镜和2个人共线是不是障碍,但根据该壁其他情况

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<string.h>
#include<math.h>
using namespace std;
#define point Point
const double eps = 1e-8;
const double PI = acos(-1.0);
double ABS(double x){return x>0?x:-x;}
int sgn(double x){
if(fabs(x) < eps)return 0;
if(x < 0)return -1;
else return 1;
}
struct Point
{
double x,y;
void put(){printf("(%.0lf,%.0lf)\n",x,y);}
Point(){}
Point(double _x,double _y){
x = _x;y = _y;
}
Point operator -(const Point &b)const{
return Point(x - b.x,y - b.y);
}
//叉积
double operator ^(const Point &b)const{
return x*b.y - y*b.x;
}
//点积
double operator *(const Point &b)const{
return x*b.x + y*b.y;
}
//绕原点旋转角度B(弧度值),后x,y的变化
void transXY(double B){
double tx = x,ty = y;
x = tx*cos(B) - ty*sin(B);
y = tx*sin(B) + ty*cos(B);
}
};
struct Line
{
Point s,e;
void put(){s.put();e.put();}
Line(){}
Line(Point _s,Point _e)
{
s = _s;e = _e;
}
//两直线相交求交点
//第一个值为0表示直线重合,为1表示平行,为0表示相交,为2是相交
//仅仅有第一个值为2时,交点才有意义
pair<int,Point> operator &(const Line &b)const{
Point res = s;
if(sgn((s-e)^(b.s-b.e)) == 0)
{
if(sgn((s-b.e)^(b.s-b.e)) == 0)
return make_pair(0,res);//重合
else return make_pair(1,res);//平行
}
double t = ((s-b.s)^(b.s-b.e))/((s-e)^(b.s-b.e));
res.x += (e.x-s.x)*t;
res.y += (e.y-s.y)*t;
return make_pair(2,res);
}
};
double dist(Point a,Point b){return sqrt((a-b)*(a-b));}
//*推断线段相交
bool inter(Line l1,Line l2)
{
return
max(l1.s.x,l1.e.x) >= min(l2.s.x,l2.e.x) &&
max(l2.s.x,l2.e.x) >= min(l1.s.x,l1.e.x) &&
max(l1.s.y,l1.e.y) >= min(l2.s.y,l2.e.y) &&
max(l2.s.y,l2.e.y) >= min(l1.s.y,l1.e.y) &&
sgn((l2.s-l1.e)^(l1.s-l1.e))*sgn((l2.e-l1.e)^(l1.s-l1.e)) <= 0 &&
sgn((l1.s-l2.e)^(l2.s-l2.e))*sgn((l1.e-l2.e)^(l2.s-l2.e)) <= 0;
}
point symmetric_point(point p1, point l1, point l2)
{
point ret;
if(ABS(l1.x-l2.x)<eps){
ret.y = p1.y;
ret.x = 2*l1.x - p1.x;
return ret;
}
if(ABS(l1.y-l2.y)<eps) {
ret.x = p1.x;
ret.y = 2*l1.y - p1.y;
return ret;
}
if (l1.x > l2.x - eps && l1.x < l2.x + eps)
{
ret.x = (2 * l1.x - p1.x);
ret.y = p1.y;
}
else
{
double k = (l1.y - l2.y ) / (l1.x - l2.x);
ret.x = (2*k*k*l1.x + 2*k*p1.y - 2*k*l1.y - k*k*p1.x + p1.x) / (1 + k*k);
ret.y = p1.y - (ret.x - p1.x ) / k;
}
return ret;
}
bool gongxian(Point a, Point b, Point c){
return ABS((a.y-b.y)*(a.x-c.x) - (a.y-c.y)*(a.x-b.x))<eps;
}
Point a,b;
Line peo, wal, mir;
bool work(){
// peo.put(); wal.put();
if((gongxian(a,mir.s,mir.e)&&gongxian(b,mir.s,mir.e))) {
// a.put(); b.put(); mir.put(); puts("共线了");
return !inter(wal,peo);
}
else if(inter(mir,peo))return false;
if(!inter(wal, peo)) return true;
// puts("GEGE");
if(inter(wal,mir))return false;
Point c = symmetric_point(b,mir.s,mir.e);
Point d = symmetric_point(a,mir.s,mir.e);
// c.put(); d.put();
Line ac, bd;
ac.s = a, ac.e = c;
bd.s = b, bd.e = d;
if(!inter(ac,mir))return false;
if(!inter(bd,mir))return false;
if(inter(ac,wal))return false;
if(inter(bd,wal))return false;
return true;
}
int main(){
while(~scanf("%lf %lf",&a.x,&a.y)){
scanf("%lf %lf",&b.x,&b.y);
scanf("%lf %lf %lf %lf", &wal.s.x, &wal.s.y, &wal.e.x, &wal.e.y);
scanf("%lf %lf %lf %lf", &mir.s.x, &mir.s.y, &mir.e.x, &mir.e.y);
peo.s = a, peo.e = b;
work()? puts("YES"):puts("NO");
}
return 0;
}

版权声明:本文博主原创文章,博客,未经同意不得转载。

Codeforces 32E Hide-and-Seek 乞讨2关于镜面反射点 计算几何的更多相关文章

  1. 【BZOJ-1941】Hide and Seek KD-Tree

    1941: [Sdoi2010]Hide and Seek Time Limit: 16 Sec  Memory Limit: 162 MBSubmit: 830  Solved: 455[Submi ...

  2. [BZOJ1941][Sdoi2010]Hide and Seek

    [BZOJ1941][Sdoi2010]Hide and Seek 试题描述 小猪iPig在PKU刚上完了无聊的猪性代数课,天资聪慧的iPig被这门对他来说无比简单的课弄得非常寂寞,为了消除寂寞感,他 ...

  3. BZOJ3402: [Usaco2009 Open]Hide and Seek 捉迷藏

    3402: [Usaco2009 Open]Hide and Seek 捉迷藏 Time Limit: 3 Sec  Memory Limit: 128 MBSubmit: 51  Solved: 4 ...

  4. BZOJ 3402: [Usaco2009 Open]Hide and Seek 捉迷藏

    题目 3402: [Usaco2009 Open]Hide and Seek 捉迷藏 Time Limit: 3 Sec  Memory Limit: 128 MB Description     贝 ...

  5. 3402: [Usaco2009 Open]Hide and Seek 捉迷藏

    3402: [Usaco2009 Open]Hide and Seek 捉迷藏 Time Limit: 3 Sec  Memory Limit: 128 MBSubmit: 78  Solved: 6 ...

  6. bzoj:1941: [Sdoi2010]Hide and Seek

    1941: [Sdoi2010]Hide and Seek Time Limit: 16 Sec  Memory Limit: 162 MBSubmit: 531  Solved: 295[Submi ...

  7. 【BZOJ】【1941】【SDOI2010】Hide and Seek

    KD-Tree 一开始看错题了

  8. 洛谷 P2951 [USACO09OPEN]捉迷藏Hide and Seek

    题目戳 题目描述 Bessie is playing hide and seek (a game in which a number of players hide and a single play ...

  9. 【BZOJ1941】Hide and Seek(KD-Tree)

    [BZOJ1941]Hide and Seek(KD-Tree) 题面 BZOJ 洛谷 题解 \(KD-Tree\)对于每个点搜一下最近点和最远点就好了 #include<iostream> ...

随机推荐

  1. 关于sizeof的笔试面试题具体解释

    原创Blog,转载请注明处处 http://blog.csdn.net/hello_hwc 注意:sizeof是编译期计算出结果的,这一点对后面的理解非常重要 一.关于结构体 先看下代码 #inclu ...

  2. Swift - 滑块(UISlider)的用法

    1,滑块的创建 1 2 3 4 5 6 var slider=UISlider(frame:CGRectMake(0,0,300,50)) slider.center=self.view.center ...

  3. POJ1087 A Plug for UNIX 【最大流】

    A Plug for UNIX Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 13855   Accepted: 4635 ...

  4. C语言实现通用数据结构的高效设计

    近期在阅读一个开源的C++代码.里面用到了大量的STL里面的东西.或许是自己一直用C而非常少用C++来实现算法的原因.STL里面大量的模板令人心烦.一直对STL的效率表示怀疑,但在网上搜到这样一个帖子 ...

  5. Codechef Not a Triangle题解

    找出一个数组中的三个数,三个数不能组成三角形. 三个数不能组成三角形的条件是:a + b < c 两边和小于第三边. 这个问题属于三个数的组合问题了.暴力法可解,可是时间效率就是O(n*n*n) ...

  6. Cocos2d-x内存管理解说在ios开发中

    使用过 Cocos2d-x 都知道,其中有一套自己实现的内存管理机制,不同于一般 C++ 的编写常规,而在使用前,了解其原理是有必要的,网上已经有很多对内部实现详细解说的文章.而对于使用者而言,并不需 ...

  7. 实现Runnable接口和扩展Thread使用场景

    在上篇博文:java学习笔记-Thread中我们知道创建子线程的两个方式:实现Runnable接口和扩展Thread. 扩展Thread类和实现Runnable接口的使用场景: Thread类定义了派 ...

  8. sql server数据库保存图片或者其他小文件

    原文:sql server数据库保存图片或者其他小文件 测试用sql server数据库保存图片或者其他小文件. 文件流字段用varbinary类型. static void Main() { App ...

  9. ActionBar本部分适用述评

    http://note.youdao.com/share/?id=7f213cb64069bad221f4581507707294&type=note 因为把图片拿进来太麻烦,所以我给了一个直 ...

  10. HTML学习笔记——各种居中对齐

    0.前言     水平居中基本方法--指定块的宽度并设定块的左右外边距为auto,上下外边距可取0,那么该块能够在父元素中水平居中. 样式例如以下: 1:margin:0px auto 2:margi ...