主题链接:点击打开链接

必须指出的是,反射镜和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. jquery 学习 (二)

    1)jquery对象和dom对象区别及相互转换 2)jquery和其他库冲突解决 3)css选择器和jquery选择器 3.1)基本选择器(id选择器.类选择器.元素选择器.*选择器.多个选择器以逗号 ...

  2. Qt 4.7.4 完美动态编译发布动态调试,以及静态编译发布

    首先是准备工作,去QT主页下载独立的QT类库安装包以及完整QT SDK安装包,还有QT Creator for windows 版 下载地址:http://qt.nokia.com/downloads ...

  3. [Android学习笔记]ListView中含有Button导致无法响应onItemClick回调的解决办法

    转自:http://www.cnblogs.com/eyu8874521/archive/2012/10/17/2727882.html 问题描述: 当ListView的Item中的控件只是一些展示类 ...

  4. [Android学习笔记]ShareSDK的使用

    ShareSDK使用方便,集成简单,正式客户端开发人员的首选组件 集成步骤,使用说明见官方文档: http://wiki.sharesdk.cn/Android_快速集成指南 记录: 直接使用官方De ...

  5. ORACLE常用数据库类型(转)

    oracle常用数据类型 1.Char 定长格式字符串,在数据库中存储时不足位数填补空格,它的声明方式如下CHAR(L),L为字符串长度,缺省为1,作为变量最大32767个字符,作为数据存储在ORAC ...

  6. HDU1176:免费馅饼(DP)

    Problem Description 都说天上不会掉馅饼,但有一天gameboy正走在回家的小径上,忽然天上掉下大把大把的馅饼.说来gameboy的人品实在是太好了,这馅饼别处都不掉,就掉落在他身旁 ...

  7. 【Cocos2d-X开发笔记】第一期 Cocos2d-X的环境搭建

          作者今天开始正式开始学习Cocos2d-X引擎进行游戏编程,预计两天会更新一期,最后实现ios游戏的appsore上线. (部分内容转载自:http://blog.csdn.net/yan ...

  8. Android 实现环形进度按钮circular-progress-button

    ※效果 ※简单介绍 显示运行进度的button,可用于数据的提交.系统登录等.动画效果非常棒.提高用户体验. ※使用说明 Declare button inside your layout XML f ...

  9. nodejs启动守护程序pm2

    nodejs启动守护程序pm2 by 伍雪颖 做了个应用,server放阿里云,只是server总会自己断,后来写了个心跳程序,就是检測应用线程是否还在,不在就再启动, 这种方法好笨重啊,后来发现no ...

  10. Android中九种dialog对话框代码

    public class MainActivity extends Activity { private static final int MAX_PROGRESS = 100; private st ...