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;
}

(全国多校重现赛一)D Dying light的更多相关文章

  1. (全国多校重现赛一)F-Senior Pan

    Senior Pan fails in his discrete math exam again. So he asks Master ZKC to give him graph theory pro ...

  2. (全国多校重现赛一) J-Two strings

    Giving two strings and you should judge if they are matched.  The first string contains lowercase le ...

  3. (全国多校重现赛一) H Numbers

    zk has n numbers a1,a2,...,ana1,a2,...,an. For each (i,j) satisfying 1≤i<j≤n, zk generates a new ...

  4. (全国多校重现赛一)E-FFF at Valentine

    At Valentine's eve, Shylock and Lucar were enjoying their time as any other couples. Suddenly, LSH, ...

  5. (全国多校重现赛一)B-Ch's gifts

    Mr. Cui is working off-campus and he misses his girl friend very much. After a whole night tossing a ...

  6. (全国多校重现赛一)A-Big Binary Tree

    You are given a complete binary tree with n nodes. The root node is numbered 1, and node x's father ...

  7. 2016ACM/ICPC亚洲区沈阳站-重现赛赛题

    今天做的沈阳站重现赛,自己还是太水,只做出两道签到题,另外两道看懂题意了,但是也没能做出来. 1. Thickest Burger Time Limit: 2000/1000 MS (Java/Oth ...

  8. 2016 CCPC 东北地区重现赛

    1. 2016 CCPC 东北地区重现赛 2.总结:弱渣,只做出01.03.05水题 08   HDU5929 Basic Data Structure    模拟,双端队列 1.题意:模拟一个栈的操 ...

  9. 2016 CCPC长春重现赛

    1.2016中国大学生程序设计竞赛(长春)-重现赛 2.总结:会做的太少,应变能力也不行,或者说猜题目的能力不行 02  水 04  HDU 5914  Triangle 1.题意:1~n,n个数,问 ...

随机推荐

  1. 《计算机网络 自顶向下方法》 第2章 应用层 Part1

    常见的应用层协议有哪些?  HTTP(HyperText Transfer  Protocol):超文本传输协议 FTP(File Transfer Protocol):文件传输协议 SMTP(Sim ...

  2. 微信小程序api封装(promise)

    顺带这是我平时公司切换改变网络环境 直接上代码,我相信就可以懂了, //app.js function fetchApi(url, type, params, method) { return new ...

  3. spark基于yarn的两种提交模式

    一.spark的三种提交模式 1.第一种,Spark内核架构,即standalone模式,基于Spark自己的Master-Worker集群. 2.第二种,基于YARN的yarn-cluster模式. ...

  4. sbt安装

    使用 Scala 编写的程序需要使用 sbt 进行编译打包,官网sbt下载解压 在解压路径下创建脚本: #!/bin/bash SBT_OPTS="-Xms512M -Xmx1536M -X ...

  5. # & 等特殊字符会导致传参失败

    # & 等特殊字符会导致 post 传参失败 处理方法使用 encodeURIComponent 将字符串转化一下 实例 // toUpperCase() 转化为大写字母 var cateco ...

  6. pat 1132 Cut Integer(20 分)

    1132 Cut Integer(20 分) Cutting an integer means to cut a K digits lone integer Z into two integers o ...

  7. JavaWeb核心知识点

    一:HTTP协议     一.概述 1. 概念:超文本传输协议 2. 作用:规范了客户端(浏览器)和服务器的数据交互格式 3. 特点 1. 简单快速:客户端向服务器请求服务时,仅通过键值对来传输请求方 ...

  8. 推荐算法之用矩阵分解做协调过滤——LFM模型

    隐语义模型(Latent factor model,以下简称LFM),是推荐系统领域上广泛使用的算法.它将矩阵分解应用于推荐算法推到了新的高度,在推荐算法历史上留下了光辉灿烂的一笔.本文将对 LFM ...

  9. 隐藏input输入框的增减按钮

    当input 使用了type='number'后,会出现这个增减数值的按钮,如上所示, 解决办法: 1.type='text' ,改为输入字符串,缺点是要做类型转换,而且移动端不会调出纯数字键盘 2. ...

  10. TypeError: Cannot read property '_t' of undefined (VUE + ElementUI + i18n)

    在使用vue的ElementUI库,在多语言时报错: TypeError: Cannot read property '_t' of undefined 错误是在点菜单栏时随机抛出的,F12抓不到,只 ...