bzoj 4595 激光发生器

  • 光线为射线,每次找到与当前光线相交且距离最近的镜子,然后旋转光线.
  • 直线,射线利用线上一点+方向向量的方式表示.旋转时,旋转中心作为线上一点不变,方向向量左乘旋转矩阵.
  • 即逆时针转过 \(\theta\) 角,方向向量 \((x,y)\) 变为 \((cos\theta \cdot x-sin\theta \cdot y,sin\theta\cdot x+cos\theta\cdot y)\).
  • 实现时特判较多,需注意细节.
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mp make_pair
#define pii pair<int,int>
inline int read()
{
int x=0;
bool pos=1;
char ch=getchar();
for(;!isdigit(ch);ch=getchar())
if(ch=='-')
pos=0;
for(;isdigit(ch);ch=getchar())
x=x*10+ch-'0';
return pos?x:-x;
}
const int MAXN=110;
const double eps=1e-8;
int dcmp(double x)
{
return fabs(x)<=eps?0:(x>0?1:-1);
}
struct v2{
double x,y;
v2(double x=0,double y=0):x(x),y(y) {}
v2 operator + (const v2 &rhs) const
{
return v2(x+rhs.x,y+rhs.y);
}
v2 operator / (const double &rhs) const
{
return v2(x/rhs,y/rhs);
}
v2 operator - (const v2 &rhs) const
{
return v2(x-rhs.x,y-rhs.y);
}
double operator * (const v2 &rhs) const
{
return x*rhs.y-y*rhs.x;
}
double modulus()
{
return sqrt(x*x+y*y);
}
};
#define point v2
#define vector v2
v2 rotate(v2 v,double rad)
{
return v2(v.x*cos(rad)-v.y*sin(rad),v.x*sin(rad)+v.y*cos(rad));
}
v2 inter(point p,vector v,point q,vector w)
{
v2 u=p-q;
double t=(w*u)/(v*w);
return p+v2(v.x*t,v.y*t);
}
double dot(v2 a,v2 b)
{
return a.x*b.x+a.y*b.y;
}
bool onseg(point p,point a1,point a2)
{
return dcmp((a1-p)*(a2-p))==0 && dcmp(dot(a1-p,a2-p))<0;
}
double angle(v2 a,v2 b)
{
return acos(fabs(dot(a,b)/a.modulus()/b.modulus()-eps));
}
struct mir{
v2 p1,p2;
double a,b;
}a[MAXN];
double x,y,dx,dy;
int n;
int main()
{
int cnt=0;
scanf("%lf%lf%lf%lf",&x,&y,&dx,&dy);
n=read();
for(int i=1;i<=n;++i)
scanf("%lf%lf%lf%lf%lf%lf",&a[i].p1.x,&a[i].p1.y,&a[i].p2.x,&a[i].p2.y,&a[i].a,&a[i].b);
point p(x,y);
vector v(dx,dy);
for(int T=1;T<=10;++T)
{
double mdis=1e100;
int id=0;
for(int i=1;i<=n;++i)
{
if(dcmp((a[i].p1-a[i].p2)*v)!=0)
{
point t=inter(a[i].p1,a[i].p2-a[i].p1,p,v);
if(onseg(t,a[i].p1,a[i].p2) && dcmp(dot(v,t-p))>0)
{
double dis=(p-t).modulus();
if(dis<mdis)
mdis=dis,id=i;
}
}
}
if(id==0)
break;
++cnt;
p=inter(a[id].p1,a[id].p2-a[id].p1,p,v);
if(dcmp(dot(a[id].p1-a[id].p2,v)==0))
v=v2(-v.x,-v.y);
else
{
vector t=a[id].p2-a[id].p1;
if(dcmp(dot(a[id].p1-a[id].p2,v)>0))
t=t/(-1);
double alpha=acos(-1)/2-angle(t,v);
int bt=dcmp(t*v);
v=rotate(t,bt*(alpha*a[id].a/a[id].b-acos(-1)/2));
}
printf("%d ",id);
}
if(!cnt)
puts("NONE");
return 0;
}

bzoj 4595 激光发生器的更多相关文章

  1. BZOJ 4595 SHOI2015 激光发生器 射线,线段,偏转

    题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=4595 题意概述: 给出一条射线和N条线段,射线遇到线段会发生反射,令入射角alpha,出射 ...

  2. bzoj AC倒序

    Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...

  3. BZOJ 2127: happiness [最小割]

    2127: happiness Time Limit: 51 Sec  Memory Limit: 259 MBSubmit: 1815  Solved: 878[Submit][Status][Di ...

  4. BZOJ 3275: Number

    3275: Number Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 874  Solved: 371[Submit][Status][Discus ...

  5. BZOJ 2879: [Noi2012]美食节

    2879: [Noi2012]美食节 Time Limit: 10 Sec  Memory Limit: 512 MBSubmit: 1834  Solved: 969[Submit][Status] ...

  6. bzoj 4610 Ceiling Functi

    bzoj 4610 Ceiling Functi Description bzoj上的描述有问题 给出\(n\)个长度为\(k\)的数列,将每个数列构成一个二叉搜索树,问有多少颗形态不同的树. Inp ...

  7. BZOJ 题目整理

    bzoj 500题纪念 总结一发题目吧,挑几道题整理一下,(方便拖板子) 1039:每条线段与前一条线段之间的长度的比例和夹角不会因平移.旋转.放缩而改变,所以将每条轨迹改为比例和夹角的序列,复制一份 ...

  8. 【sdoi2013】森林 BZOJ 3123

    Input 第一行包含一个正整数testcase,表示当前测试数据的测试点编号.保证1≤testcase≤20. 第二行包含三个整数N,M,T,分别表示节点数.初始边数.操作数.第三行包含N个非负整数 ...

  9. 【清华集训】楼房重建 BZOJ 2957

    Description 小A的楼房外有一大片施工工地,工地上有N栋待建的楼房.每天,这片工地上的房子拆了又建.建了又拆.他经常无聊地看着窗外发呆,数自己能够看到多少栋房子. 为了简化问题,我们考虑这些 ...

随机推荐

  1. Maven 一段时间知识小结2

    父 Pom.xml <parent> <groupId>org.springframework.boot</groupId> <artifactId>s ...

  2. Springboot依赖注入 Service类中使用静态变量

    @Component public class ServerHandler extends IoHandlerAdapter { @Autowired protected HealthDataServ ...

  3. Python模块学习之解决selenium的“can't access dead object”错误

    问题描述 在python执行过程中,提示selenium.common.exceptions.WebDriverException: Message: TypeError: can't access ...

  4. weblogic 12c重置console密码

    su - oracle cd /u02/weblogic/user_projects/domains/base_domain source   bin/setDomainEnv.sh cd /u02/ ...

  5. http请求的GET和POST请求:查询和新增(ajax)

    <!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content ...

  6. 015——数组(十五)sort natsort shuffle natcasesoft array_multisort

    <?php /*数组排序函数 * sort natsort shuffle natcasesoft array_multisort */ //sort() 对数组元素进行递增的排序, /*$ar ...

  7. Prism 4 文档 ---第3章 管理组件间的依赖关系

     基于Prism类库的应用程序可能是由多个松耦合的类型和服务组成的复杂应用程序,他们需要根据用户的动作发出内容和接收通知进行互动,由于他们是松耦合的,他们需要一种方式来互动和交流来传递业务功能的需求. ...

  8. mysql的搭建

    创建程序用户 root@localhost ~]# groupadd mysql [root@localhost ~]# useradd -s /sbin/nologin -g mysql -M my ...

  9. OpenMP学习

    当数据量较大或者时间复杂度高的时候,盲目地等待结果,开发效率极低. 听说OpenMP可以多核并行运算,加快运行速度.整理了一些OpenMP的资料,以待学习. 1.openMP的一点使用经验 2.Ope ...

  10. The program environment for cypress cy8ckit-002

    customer use cypress ic to make sure the  wireless products, we are prepare to establish the environ ...