BZOJ 4595 SHOI2015 激光发生器 射线,线段,偏转
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=4595
题意概述:
给出一条射线和N条线段,射线遇到线段会发生反射,令入射角alpha,出射角beta,则beta=alpha*phi_i(即对于每条线段phi是不同的),输出至多10条遇见的线段,没有发生相交的话输出NONE。
N<=100.
分析:
实际上记得板子怎么打还是没什么问题的,问题就是我当时记不得了......
还有一个事情,用余弦定理求两个向量夹角的时候记得-eps控制精度!
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<queue>
#include<set>
#include<map>
#include<vector>
#include<cctype>
using namespace std;
const int maxn=;
const double eps=1e-;
const double pi=acos(-1.0); int X,Y,dx,dy,N;
struct Point{
double x,y;
Point(){ }
Point(double xx,double yy){ x=xx,y=yy; }
}P[maxn]; int cnt=;
typedef Point Vector;
struct Line{
Point p; Vector v;
Line(){ }
Line(Point pp,Vector vv){ p=pp,v=vv; }
};
struct data{
int a,b;
Point p1,p2;
}A[maxn];
Vector operator + (const Vector &a,const Vector &b){ return Vector(a.x+b.x,a.y+b.y); }
Vector operator - (const Vector &a,const Vector &b){ return Vector(a.x-b.x,a.y-b.y); }
Vector operator * (const Vector &a,const double &b){ return Vector(a.x*b,a.y*b); }
int dcmp(double x){ return fabs(x)<eps?:(x>?:-); }
double Dot(const Vector &a,const Vector &b){ return a.x*b.x+a.y*b.y; }
double Cross(const Vector &a,const Vector &b){ return a.x*b.y-a.y*b.x; }
double Length(const Vector &a){ return sqrt(a.x*a.x+a.y*a.y); }
double Angle(const Vector &a,const Vector &b){ return acos(fabs(Dot(a,b))/Length(a)/Length(b)-eps); }
Vector Rotate(const Vector &v,const double &rad){
return Vector(v.x*cos(rad)-v.y*sin(rad),v.y*cos(rad)+v.x*sin(rad));
}
Point GetLineIntersection(const Line &a,const Line &b){
Vector u=a.p-b.p;
double t=Cross(b.v,u)/Cross(a.v,b.v);
return a.p+a.v*t;
}
bool Onsegment(const Point &p,const Point &a,const Point &b){
return dcmp(Dot(a-p,b-p))<=&&dcmp(Cross(a-p,a-p))==;
} void data_in()
{
scanf("%d%d%d%d%d",&X,&Y,&dx,&dy,&N);
for(int i=;i<=N;i++)
scanf("%lf%lf%lf%lf%d%d",&A[i].p1.x,&A[i].p1.y,&A[i].p2.x,&A[i].p2.y,&A[i].a,&A[i].b);
}
void work()
{
int t=;
Point p=Point(X,Y),pp;
Vector v=Vector(dx,dy),vv;
while(t<=){
double md=1e9,dis; int id=;
for(int i=;i<=N;i++){
if(dcmp(Cross(A[i].p1-A[i].p2,v))==) continue;
pp=GetLineIntersection(Line(A[i].p1,A[i].p2-A[i].p1),Line(p,v));
if(Onsegment(pp,A[i].p1,A[i].p2)&&dcmp(Dot(v,pp-p))>){
dis=Length(p-pp);
if(dis<md) md=dis,id=i;
}
}
if(!id) break;
p=GetLineIntersection(Line(A[id].p1,A[id].p2-A[id].p1),Line(p,v));
if(dcmp(Dot(A[id].p1-A[id].p2,v))==) v=v*-;
else{
if(dcmp(Dot(A[id].p1-A[id].p2,v))>) vv=A[id].p1-A[id].p2;
else vv=A[id].p2-A[id].p1;
double alp=pi/-Angle(vv,v);
if(dcmp(Cross(vv,v))>) v=Rotate(vv,alp*A[id].a/A[id].b-pi/);
else v=Rotate(vv,pi/-alp*A[id].a/A[id].b);
}
printf("%d ",id);
t++;
}
if(t==) printf("NONE\n");
}
int main()
{
data_in();
work();
return ;
}
BZOJ 4595 SHOI2015 激光发生器 射线,线段,偏转的更多相关文章
- BZOJ 4592 SHOI2015 脑洞治疗仪 线段树
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=4592 题意概述:需要维护一个01序列A,一开始A全部都是1.支持如下操作: 1.将区间[l ...
- bzoj 4595 激光发生器
bzoj 4595 激光发生器 光线为射线,每次找到与当前光线相交且距离最近的镜子,然后旋转光线. 直线,射线利用线上一点+方向向量的方式表示.旋转时,旋转中心作为线上一点不变,方向向量左乘旋转矩阵. ...
- [BZOJ 1483] [HNOI2009] 梦幻布丁 (线段树合并)
[BZOJ 1483] [HNOI2009] 梦幻布丁 (线段树合并) 题面 N个布丁摆成一行,进行M次操作.每次将某个颜色的布丁全部变成另一种颜色的,然后再询问当前一共有多少段颜色.例如颜色分别为1 ...
- [BZOJ 2653] middle(可持久化线段树+二分答案)
[BZOJ 2653] middle(可持久化线段树+二分答案) 题面 一个长度为n的序列a,设其排过序之后为b,其中位数定义为b[n/2],其中a,b从0开始标号,除法取下整. 给你一个长度为n的序 ...
- bzoj 4592(洛谷 4344) [Shoi2015]脑洞治疗仪——线段树上二分
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=4592 1操作就是用线段树来二分找到第一个有 k 个0的位置. 在洛谷上A了,与暴力和网上题解 ...
- bzoj 1537: [POI2005]Aut- The Bus 线段树
bzoj 1537: [POI2005]Aut- The Bus 先把坐标离散化 设f[i][j]表示从(1,1)走到(i,j)的最优解 这样直接dp::: f[i][j] = max{f[i-1][ ...
- [BZOJ 3196] 213平衡树 【线段树套set + 树状数组套线段树】
题目链接:BZOJ - 3196 题目分析 区间Kth和区间Rank用树状数组套线段树实现,区间前驱后继用线段树套set实现. 为了节省空间,需要离线,先离散化,这样需要的数组大小可以小一些,可以卡过 ...
- BZOJ.5286.[AHOI/HNOI2018]转盘(线段树)
BZOJ LOJ 洛谷 如果从\(1\)开始,把每个时间\(t_i\)减去\(i\),答案取决于\(\max\{t_i-i\}\).记取得最大值的位置是\(p\),答案是\(t_p+1+n-1-p=\ ...
- BZOJ.4399.魔法少女LJJ(线段树合并)
BZOJ 注意\(c\leq7\)→_→ 然后就是裸的权值线段树+线段树合并了. 对于取\(\max/\min\)操作可以直接区间修改清空超出范围的值,然后更新到对应位置上就行了(比如对\(v\)取\ ...
随机推荐
- detection and segmentation
Relation Networks for Object Detection https://arxiv.org/abs/1711.11575 Towards High Performance ...
- 数据库——MySQL——存储引擎
现实生活中我们用来存储数据的文件有不同的类型,每种文件类型对应各自不同的处理机制:比如处理文本用txt类型,处理表格用excel,处理图片用png等.数据库中的表也应该有不同的类型,表的类型不同,会对 ...
- element 表单的input循环生成,并可单个input失去焦点单个验证并保存; (多个表单实例)
<div class="box_item"> <el-form ref="aList" :model="form" :ru ...
- Unity 游戏框架搭建 (十四) 优雅的QSignleton(零) QuickStart
好久不见 !之前想着让各位直接用QFramework,但是后来想想,如果正在进行的项目直接使用QFramework,这样风险太高了,要改的代码太多,所以打算陆续独立出来一些工具和模块,允许各位一个 ...
- Sonar安装-Linux[20171227]
前言 一款不错的代码质量管理工具Sonar 前期准备 官方参考文档 https://docs.sonarqube.org/display/SONAR/Documentation ...
- PHP将二位数组按照第二维的某个元素的值进行排序
例如: //原始数组是这样的,希望能够按照第二维中的run_date升序或者降序进行排序: $arr=array( 0=>array( 'run_date'=>'2017-11-21', ...
- linux后台程序开发常用工具
linux开发工具: 1.编辑工具:1)sourceInsight2)Notepad++3)UltraEdit4)Altova XMLSpy 2.linux服务器访问工具:1)FileZilla2)X ...
- web前端逻辑计算,血的教训
在web前端进行页面开发的过程中,难免的遇到逻辑问题,这不是什么大问题,既然走上IT条黑道,那小伙伴们的逻辑推理能力及逻辑计算能力是不会有太大问题的. 然而,有的逻辑计算,就算你逻辑计算能力超强,也不 ...
- 【ospf-链路验证】
根据项目需求搭建好拓扑图 配置RT1的环回口IP和G0/0/0IP地址 开启RT1接口ospf认证,配置接口密码为H3C 配置RT1的ospf区域 同理 开启RT2接口ospf认证,配置接口密码为g0 ...
- Learning Experience of Big Data:The First Day-Try to set up a network connection on my virtural machine
After we install our virtual machine,the first thing we should do is to set up a network connection ...