4595: [Shoi2015]激光发生器
Time Limit: 10 Sec Memory Limit: 256 MBSubmit: 8 Solved: 4
[ Submit][ Status][ Discuss]
Description
曾经发明了超能粒子炮·改的发明家SHTSC又公开了他的新发明:激光发生器--一种可以产生高能激光的神秘装置
。激光发生器从正上方看是一个无穷大的平面,里面由一个定向激光发射装置和若干个激光偏转装置组成。一个激
光发生器的示例如图所示,细箭头表示定向激光发射装置,粗线段表示激光偏转装置。
由定向激光发射装置发射出的激光可以看成是一条射线,如果遇到激光偏转装置就会发生偏转。奇特的是,SHTSC
所使用的激光偏转装置并非像传统的镜子那样遵循反射定律,而是对于每个激光偏转装置,有一个固定的偏转系数
λ,其出射角β与入射角α的关系为β=λα,并且能在这一过程中增强激光的能量。(入射角是入射光线和反射
平面法向量的夹角。)注意:1、偏转装置的两面均可偏转。2、如果激光平行射入偏转装置,则认为没有发生偏转
。3、如果不平行且照射到了端点则认为发生偏转。4、可能会偏转到另一面。
现在SHTSC希望你模拟他所设计的激光发生器的工作过程,来帮助他计算激光究竟被哪些激光偏转装置所偏转。
Input
第一行四个整数x,y,dx,dy。表示定向激光发射装置的位置是(x,y),方向是(dx,dy)。
第二行一个整数n,表示一共有n个激光偏转装置。
以下n行,每行五个整数x1,y1,x2,y2,a,b表示一个激光偏转装置是(x1,y1)到(x2,y2)的一条线段
其偏转系数λ=a/b。
n<=100,所有坐标与a和b的绝对值不超过1000,a、b均非0。保证所有的偏转装置没有交点。激光发射起始点不在
任何偏转装置上。方向向量不为零向量
Output
一行由空格隔开的若干个整数,表示激光依次照射到的激光偏转装置的编号(按照输入顺序从1到n编号)。如果激
光被偏转超过10次,则只需输出前10次所照射到的偏转装置的编号。特别地,如果激光没有被任何一个偏转装置所
偏转,输出NONE。
Sample Input
0 2 1 0
2
0 4 3 1 1 1
4 0 0 -4 1 1
2
0 4 3 1 1 1
4 0 0 -4 1 1
Sample Output
1 2
HINT
Source
把每个反射装置看成线段
每次暴力去看和哪一个装置碰撞(反正不会很多次)
先找到装置,然后用a*b = |a|*|b|*costheta求出夹角
注意求入射角要分四种情况讨论
最后用向量旋转矩阵去乘当前的向量,得出旋转后的新向量
不断重复即可
实数的比较使用三态函数--涨知识了
#include<iostream>
#include<cstdio>
#include<queue>
#include<vector>
#include<bitset>
#include<algorithm>
#include<cstring>
#include<map>
#include<stack>
#include<set>
#include<cmath>
#include<ext/pb_ds/priority_queue.hpp>
using namespace std;
typedef double DB;
const int maxn = 111;
const DB eps = 1E-10;
const DB PI = acos(-1.0);
struct Point{
DB x,y;
Point(){}
Point(DB x,DB y): x(x),y(y){}
Point operator - (const Point &b) {return Point(x - b.x,y - b.y);}
Point operator + (const Point &b) {return Point(x + b.x,y + b.y);}
Point operator * (const DB &t) {return Point(x*t,y*t);}
};
typedef Point Vector;
struct Line{
Point p;
Vector v;
Line(){}
Line(Point p,Vector v): p(p),v(v){}
}k,L[maxn];
int n,tot,ans[maxn];
DB lam[maxn];
DB Dot(Vector v1,Vector v2) {return v1.x*v2.x + v1.y*v2.y;}
DB Length(Vector v) {return sqrt(Dot(v,v));}
DB Cross(Vector v1,Vector v2) {return v1.x*v2.y - v2.x*v1.y;}
Point GetIntersection(Line a,Line b)
{
Vector d = a.p - b.p;
DB t = Cross(b.v,d)/Cross(a.v,b.v);
return a.p + a.v*t;
}
int cmp(DB x,DB y)
{
if (fabs(x - y) <= eps) return 0;
if (x > y) return 1;
return -1;
}
bool OnLine(Point p,Line t)
{
Point p1 = t.p;
Point p2 = p1 + t.v;
bool f1,f2;
f1 = cmp(p.x - min(p1.x,p2.x),0.00) >= 0 && cmp(max(p1.x,p2.x) - p.x,0.00) >= 0;
f2 = cmp(p.y - min(p1.y,p2.y),0.00) >= 0 && cmp(max(p1.y,p2.y) - p.y,0.00) >= 0;
return f1 && f2;
}
Vector Turn(Vector v,DB alpha,DB T)
{
DB x = v.x*cos(alpha) - T*v.y*sin(alpha);
DB y = T*v.x*sin(alpha) + v.y*cos(alpha);
return Point(x,y);
}
int main()
{
freopen("4595.in","r",stdin);
freopen("4595.out","w",stdout);
int x,y,a,b;
scanf("%d%d%d%d",&x,&y,&a,&b);
k = Line(Point(x,y),Point(a,b));
cin >> n;
for (int i = 1; i <= n; i++) {
scanf("%d%d%d%d",&x,&y,&a,&b);
Point p1 = Point(x,y);
Point p2 = Point(a,b);
L[i] = Line(p1,p2 - p1);
scanf("%d%d",&a,&b);
lam[i] = (DB)(a)/(DB)(b) + 1.00;
}
bool flag = 0;
int Last = 0;
for (int T = 1; T <= 10; T++) {
Point po;
DB Dis = 1E18;
int Num;
bool ok = 0;
for (int i = 1; i <= n; i++) {
if (i == Last) continue;
if (fabs(Cross(k.v,L[i].v)) <= eps) continue;
Point nex = GetIntersection(k,L[i]);
Vector ve = nex - k.p;
if (cmp(ve.x,0.00) != cmp(k.v.x,0.00)) continue;
if (cmp(ve.y,0.00) != cmp(k.v.y,0.00)) continue;
if (!OnLine(nex,L[i])) continue;
DB dis = Length(nex - k.p);
if (Dis - dis > eps) {
Dis = dis;
po = nex;
Num = i;
ok = 1;
}
}
if (!ok) break;
flag = 1;
Last = Num;
Vector ve = Point(-L[Num].v.y,L[Num].v.x);
DB d = Dot(ve,k.v)/Length(ve)/Length(k.v);
DB alpha = acos(d);
if (alpha*2.00 > PI) {
alpha = PI - alpha;
ve = Point(-ve.x,-ve.y);
}
alpha *= lam[Num];
d = Cross(ve,k.v);
DB TYP = cmp(d,0.00) == 1?1.00:-1.00;
k = Line(po,Turn(k.v,PI - alpha,TYP));
ans[++tot] = Num;
}
if (!flag) puts("NONE");
else {
for (int i = 1; i < tot; i++)
printf("%d ",ans[i]);
cout << ans[tot] << endl;
}
return 0;
}