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> ...
随机推荐
- 对于stackoverflow的中文翻译的相关问题
我们非常多朋友都给我留言说.希望我翻译一下stackoverflow的问题以及答案,首先我也非常愿意为大家翻译,在能够帮助大家的同一时候,对我本人的技能的提升有优点:可是工作量实在太大,所以我不可能翻 ...
- poj 1094
Sorting It All Out Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 26911 Accepted: 92 ...
- 【MongoDB】The description of index(一)
From this blog, we start to talk about the index in mongo Database, which is similar to the traditio ...
- Java---25---集合框架共性方法
集合类 为什么会出现集合类 面向对象语言对事物的体现都是以对象的形式,所以为了方便对较多个对象的操作,就对对象进行存储,集合就是存储对象最经常使用的一种方式 数组和集合类同一时候容器,有何不同? 数组 ...
- Activity数据传输到服务
activity数据接口负责启动该服务包.service获取数据.手术. 详细demo如下面: package com.example.android_service_trance; import a ...
- appium简明教程
appium简明教程 什么是appium? 下面这段介绍来自于appium的官网. Appium is an open-source tool you can use to automate mobi ...
- Android开发 更改返回button的图标
非常多的Android应用左上角都有返回button 在默认的情况下 ADT会默认给一个返回图标 而作为开发需求 非常多都要求定制一个新的图标 在Android的站点上 发现了2种能够更改的方法 1. ...
- poj3764(dfs+Trie树+贪心)
题目链接:http://poj.org/problem?id=3764 分析:好题!武森09年的论文中有道题CowXor,求的是线性结构上的,连续序列的异或最大值,用的办法是先预处理出前n项的异或值, ...
- 金句: "對比MBA學位,我們更需要PSD學位的人!" Poor, Smart and Deep Desire to… | consilient_lollapalooza on Xanga
金句: "對比MBA學位,我們更需要PSD學位的人!" Poor, Smart and Deep Desire to… | consilient_lollapalooza on X ...
- Effective Objective-C 2.0 笔记三(Literal Syntax简写语法)
当使用Objective-C的时候,你总会遇到Foundation 框架中的一些类,这些类包含NSString,NSNumber,NSArray和NSDictionary,这些数据结构都是自 ...