HDU-6164:Dying Light
来源:互联网 发布:零基础学大数据靠谱吗 编辑:程序博客网 时间:2024/06/03 11:55
Dying Light
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 516 Accepted Submission(s): 124
Problem Description
LsF is visiting a local amusement park with his friends, and a mirror room successfully attracts his attention. Inside the mirror room, there are n plane mirrors standing vertically on the ground. They are placed end-to-end and face-to-face so that if you overlook the room, you can find a convex hull and the all the reflector surfaces are inside the pattern. The height of the mirror is not important in this problem.
Due to imperfect manufacturing techniques, mirrors can't reflect light without lose of energy. Each mirror has a reflection efficiency k, which means if the incident light's intensity is I, the reflected light's intensity will be reduced to kI. The only exception could happen when the light precisely goes to the two mirrors' junction. In that case, the light will be completely absorbed instantly. Note the laws of reflection of light applies in all other situations, that the angle of incidence equals the angle of reflection.
Now LsF stands inside the mirror hall, and shoots a laser beam paralleled to the ground using his laser pointer. Unfortunately, his laser pointer can only shot laser beams with intensity of 1. What's worse, a laser beam is considered disappeared if its intensity is below
LsF wants to know how many touches can his laser beam make with mirrors before it disappears.
Input
The first line contains an integer n(3≤n≤1000), indicating the number of mirrors;
Then n lines follow. The ith line contains three real numbersxi,yi,ki(−109≤xi,yi≤109;0≤ki≤0.9) , which means the ith mirror's one end is at position (xi,yi) and another end is at (xi+1 mod n,yi+1 mod n), and its reflectivity is ki .
Next there are two real numbers Vx,Vy(-109≤Vx,Vy≤109), indicating the initial direction vector of the laser beam.
LsF is standing at the origin (0, 0).
Then n lines follow. The ith line contains three real numbers
Next there are two real numbers Vx,Vy(-109≤Vx,Vy≤109), indicating the initial direction vector of the laser beam.
LsF is standing at the origin (0, 0).
Output
Output an integer in one line, the number of touches the laser beam could make before it disappears.
Sample Input
41 2 0.5-1 0 0.51 -2 0.53 0 0.50 141 1 0.5-1 1 0.5-1 -1 0.51 -1 0.51 1
Sample Output
141
Source
2017 Multi-University Training Contest - Team 9
题解:由于LsF一开始不再镜子上,按题面模拟即可。由于反射率<=0.9 0.9^100<1e-4,所以反射次数不会超过100次。每次暴力判断和哪个镜子相交,以及有没有在镜子交界处。
#include<bits/stdc++.h>using namespace std;struct Point{ double x,y,k;}p[2000],v;double cross(Point a,Point b){return (a.x*b.y-a.y*b.x);} //叉积Point Vector(Point a,Point b){return (Point){a.x-b.x,a.y-b.y};} //求向量a-bdouble dot(Point a,Point b){return (a.x*b.x+a.y*b.y);} //点积Point cla(Point o,Point V,Point a,Point b) //计算点o与镜子ab的交点,V为速度矢量{ double dx=a.x-b.x; double dy=a.y-b.y; double t=((o.x-a.x)*dy-(o.y-a.y)*dx)/(V.y*dx-V.x*dy); return (Point){o.x+V.x*t,o.y+V.y*t};}int main(){ int n; while(scanf("%d",&n)!=EOF) { for(int i=0;i<n;i++)scanf("%lf%lf%lf",&p[i].x,&p[i].y,&p[i].k); scanf("%lf%lf",&v.x,&v.y); Point o=(Point){0,0}; //初始点 double power=1; int ans=0; while(power>=1e-4) { for(int i=0;i<n;i++) { if(cross(v,Vector(p[i],o))*cross(v,Vector(p[(i+1)%n],o))<0) //光线与镜子有交点,用叉积判断 { Point c=cla(o,v,p[i],p[(i+1)%n]); //计算出交点 if(dot(v,Vector(c,o))<0)continue; //速度方向指向镜子反方向,用点积判断 double dx=p[(i+1)%n].x-p[i].x; double dy=p[(i+1)%n].y-p[i].y; //计算出o点关于法线的对称点 Point nex=(Point){o.x-2*dx*(dx*o.x+dy*o.y-c.x*dx-c.y*dy)/(dx*dx+dy*dy),o.y-2*dy*(dx*o.x+dy*o.y-c.x*dx-c.y*dy)/(dx*dx+dy*dy)}; v=Vector(nex,c); //反射后的速度矢量 o=(Point){c.x+0.1*v.x,c.y+0.1*v.y};//反射后的发射点,取小点,避免冲出边界 ans++; // printf("第%d个镜子上 第%d个交点=(%0.2lf,%0.2lf) 速度方向向量(%0.2lf,%0.2lf)\n",i+1,ans,c.x,c.y,v.x,v.y); power*=p[i].k; break; } else if(cross(v,Vector(p[i],o))*cross(v,Vector(p[(i+1)%n],o))==0){ans++;goto output;} //射到镜子交界处 } } output:cout<<ans<<endl; } return 0;}
阅读全文
1 0
- HDU-6164:Dying Light
- 多校9 HDU-6164 Dying Light 几何数学
- Dying Young
- Dying Gasp
- Dying[二分]
- hdu 4949 Light
- hdu 4949 Light 插头dp
- hdu 2587 Mirror and Light
- Dying In The Sun
- SharePoint is Dying
- A protocol for Dying
- Let the light guide us HDU
- HDU 4276--The Ghost Blows Light
- HDU 4276 The Ghost Blows Light
- hdu 4276 The Ghost Blows Light
- HDU 4276 The Ghost Blows Light
- HDU 4276 The Ghost Blows Light
- HDU 4276 The Ghost Blows Light
- 学习Linux-4.12内核网路协议栈(3.2)——网路层的发包处理
- PowerDesigner初学-1
- MAC连接服务器后不断开
- 续上篇,改用struts2实现JQuery的ajax异步请求
- 【图像语义分割】Label data的标注--Labelme(python)
- HDU-6164:Dying Light
- linux更改机器名localhost及启动停掉网卡
- 我对Java Serializable(序列化)的理解和总结
- try...catch...finally语句块
- jsonp调用
- 【JAVA基础】list和字符串判空
- 搬砖来的linux命令 (自己收藏)
- 【VC】VS2008+WDK 配置方法解析
- intellij idea出现“Usage of API documented as @since 1.6+”的解决办法