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 10−410−4. There's not much magnitude distance between the two numbers. 

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 numbers xi,yi,ki(−109≤xi,yi≤109;0≤ki≤0.9)xi,yi,ki(−109≤xi,yi≤109;0≤ki≤0.9), which means the ith mirror's one end is at position (xi,yi)(xi,yi) and another end is at (xi+1xi+1mod n,yi+1yi+1mod n), and its reflectivity is kiki. 

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

4
1 2 0.5
-1 0 0.5
1 -2 0.5
3 0 0.5
0 1
4
1 1 0.5
-1 1 0.5
-1 -1 0.5
1 -1 0.5
1 1

Sample Output

14
1

题解:因为0.1<=K<=0.9因此最多反射100,就一定可以消失。首先,我们判断该射线是否可以与镜面相交,如果与某一镜面相交,我们再判断是指向镜面还是反向指向镜面的,然后,我们可以计算出射线,与镜面的交点(用两个向量的投影相等)。然后更新O点与向量V;

#include<bits/stdc++.h>
using namespace std; struct Point{
double x,y,k;
} point[2010];
Point V;
Point vec(Point a,Point b)
{
return Point{a.x-b.x,a.y-b.y};
} double cha_ji(Point a,Point b) //判断是否相交
{
return a.x*b.y-a.y*b.x;
} Point jiao_point(Point O,Point V,Point a,Point b)//求交点
{
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+t*V.x,O.y+V.y*t};
} double Nod(Point a,Point b)
{
return a.x*b.x+a.y*b.y;
} int main()
{
int n;
while(scanf("%d",&n)!=EOF)
{
for(int i=0;i<n;i++) scanf("%lf%lf%lf",&point[i].x,&point[i].y,&point[i].k);
Point O{0,0};
scanf("%lf%lf",&V.x,&V.y);
double power=1;
int ans=0,flag=0;
while(power>=1e-4)
{
for(int i=0;i<n;i++)
{
if(cha_ji(V,vec(point[i],O))*cha_ji(V,vec(point[(i+1)%n],O))<0)
{
Point nod=jiao_point(O,V,point[i],point[(i+1)%n]);
if(Nod(V,vec(nod,O))<0) continue;
double dx=point[(i+1)%n].x-point[i].x;
double dy=point[(i+1)%n].y-point[i].y;
Point nex=(Point) {O.x-2*dx*(dx*O.x+dy*O.y-nod.x*dx-nod.y*dy)/(dx*dx+dy*dy),O.y-2*dy*(dx*O.x+dy*O.y-nod.x*dx-nod.y*dy)/(dx*dx+dy*dy)};
V=vec(nex,nod);
O=(Point){nod.x+0.1*V.x,nod.y+0.1*V.y};
ans++;
power*=point[i].k;
break;
}
else if(cha_ji(V,vec(point[i],O))*cha_ji(V,vec(point[(i+1)%n],O))==0)
{
ans++;flag=1;
break;
}
}
if(flag) break;
}
cout<<ans<<endl;
}
return 0;
}

最新文章

  1. 阿里提前批校招内推offer经历
  2. Python爬虫学习(8):浙大软院网络登陆保持
  3. 前端开发薪资之各地区对比(图文分析)(share)
  4. SQL存在一个表而不在另一个表中的数据, 更新字段为随机时间
  5. mongoDB数据库
  6. JSP中的隐式对象(implicit object)
  7. 在可以调用OLE之前,必须将当前线程设置为单线程单元(STA)模式,请确保您的Main函数带有STAThreadAttribute
  8. Windows下利用Windbg 分析dump
  9. Python LDAP中的时间戳转换为Linux下时间
  10. iOS: 学习笔记, Swift与C指针交互(译)
  11. react-redux原理
  12. For循环练习之99乘法表和转义字符
  13. 禁止UITextField 使用粘贴复制功能
  14. 开学&amp;东大一周游记
  15. 使用 memoryview 和 struct 查看一个 GIF 图像的首部
  16. Linux网络基本网络配置方法介绍
  17. HDFS及其各组件的机制
  18. 让我怀疑人生的bug集合
  19. Gradle nexus配置
  20. Django 之 ORM

热门文章

  1. 深入理解计算机系统 第二章 信息的表示和处理 part1
  2. Docker swarm集群增加节点和删除节点
  3. Swoole和Redis实现的并发队列处理系统
  4. pat 1011 World Cup Betting(20 分)
  5. NetCore基于EasyNetQ的高级API使用RabbitMq
  6. python:爬虫0
  7. Cognitive Graph for Multi-Hop Reading Comprehension at Scale(ACL2019) 阅读笔记与源码解析
  8. [Part 4] 在Windows 10上源码编译PCL 1.8.1支持VTK和QT,可视化三维点云
  9. 20191010-4 alpha week 1/2 Scrum立会报告+燃尽图 02
  10. docker容器访问宿主机的IP——以rocketmq管理工具为例