Codeforces 32E Hide-and-Seek 乞讨2关于镜面反射点 计算几何
主题链接:点击打开链接
必须指出的是,反射镜和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关于镜面反射点 计算几何的更多相关文章
- 【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> ...
随机推荐
- [Codecademy] HTML&CSS 第一课:HTML Basic
本文出自 http://blog.csdn.net/shuangde800 ------------------------------------------------------------ ...
- google 搜索url详解
www.google.com [http://www.google.cn/search?q=112&hl=zh-CN&client=aff- 360daohang&hs=yhE ...
- [计算机基础]关于实体( Entity )和模型( Model )
实体与模型的浅析 在日常开发过程中经常看到Entity,Model,DataModel,它们之间到底有什么异同?下面是我个人的一些理解. 一.Entity,Model,它们是什么? 维基百科描述: 实 ...
- Oracle定时执行存储过程(转)
定时执行存储过程在平时开发中经常会用到,年前的时候自己也做了一个,由于时间关系一直没能记录,现记录下来. 首先用一个完整的例子来实现定时执行存储过程. 任务目标:每小时向test表中插入一 ...
- 激动啊,终于诞生了,编译了属于俺自己的 JDK
激动啊,终于诞生了,编译了属于俺自己的 JDK 折腾了2天,现在编译过去了 30多分钟了,久违的 java.exe 终于出现在了 bin 目录中,属于俺自己的 JDK 终于诞生了,激动啊
- Java提高篇(三二)-----List总结
前面LZ已经充分介绍了有关于List接口的大部分知识,如ArrayList.LinkedList.Vector.Stack,通过这几个知识点能够对List接口有了比較深的了解了.仅仅有通过归纳总结的知 ...
- nagios二次开发(五岁以下儿童)---nagios和nagiosql关系
基于nagios和nagiosql理解.这将是这两个梳理比较粗糙的简单关系,有关详细信息,请参阅下面的图如: 从上面的关系图中能够看出,nagios与nagiosql共享了主机.主机组.服务 ...
- POJ1789 Truck History 【最小生成树Prim】
Truck History Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 18981 Accepted: 7321 De ...
- c++程序猿经典面试题
1.请问i的值会输出什么? #include"iostream.h" int i=1; void main() { int i=i; cout<<i<<en ...
- firebug登陆之数据包分析
登陆之数据包分析 工具: python-urllib2 | firefox+firebug或者chrome,用浏览器打开登陆页面之后,按F12键会默认打开开发者工具或者启动firebug,点击n ...