(全国多校重现赛一)D Dying light
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的更多相关文章
- (全国多校重现赛一)F-Senior Pan
Senior Pan fails in his discrete math exam again. So he asks Master ZKC to give him graph theory pro ...
- (全国多校重现赛一) J-Two strings
Giving two strings and you should judge if they are matched. The first string contains lowercase le ...
- (全国多校重现赛一) H Numbers
zk has n numbers a1,a2,...,ana1,a2,...,an. For each (i,j) satisfying 1≤i<j≤n, zk generates a new ...
- (全国多校重现赛一)E-FFF at Valentine
At Valentine's eve, Shylock and Lucar were enjoying their time as any other couples. Suddenly, LSH, ...
- (全国多校重现赛一)B-Ch's gifts
Mr. Cui is working off-campus and he misses his girl friend very much. After a whole night tossing a ...
- (全国多校重现赛一)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 ...
- 2016ACM/ICPC亚洲区沈阳站-重现赛赛题
今天做的沈阳站重现赛,自己还是太水,只做出两道签到题,另外两道看懂题意了,但是也没能做出来. 1. Thickest Burger Time Limit: 2000/1000 MS (Java/Oth ...
- 2016 CCPC 东北地区重现赛
1. 2016 CCPC 东北地区重现赛 2.总结:弱渣,只做出01.03.05水题 08 HDU5929 Basic Data Structure 模拟,双端队列 1.题意:模拟一个栈的操 ...
- 2016 CCPC长春重现赛
1.2016中国大学生程序设计竞赛(长春)-重现赛 2.总结:会做的太少,应变能力也不行,或者说猜题目的能力不行 02 水 04 HDU 5914 Triangle 1.题意:1~n,n个数,问 ...
随机推荐
- 用这个库 3 分钟实现让你满意的表格功能:Bootstrap-Table
本文作者:HelloGitHub-kalifun 这是 HelloGitHub 推出的<讲解开源项目>系列,今天给大家推荐一个基于 Bootstrap 和 jQuery 的表格插件:Boo ...
- python 做一个简单的登录接口
# -*- conding :utf-8 -*-# File Name: homewoe# Create Date: 2019/11/20 / 9:15# Change Activity: 2019/ ...
- 《JAVA 程序员面试宝典(第四版)》之传递与引用篇
废话开场白 这个周末突然很想创业,为什么呢?原因很简单,我周围的同学或者说玩的比较好的朋友都发达了,前一个月和一个两年前还睡在一张床上的朋友,他现在已经在深圳买房买车了,没错是在深圳买 ...
- ES6 Map 原理
ES6的Map的键可以是任意的数据结构,并且不重复. 那么map的底层原理是啥呢? Map利用链表,hash的思想来实现. 首先,Map可以实现删除,而且删除的数据可以是中间的值.而链表的优势就是在中 ...
- 深入ObjC GCD中的dispatch group工作原理。
本文是基于GCD的支持库libdispatch的源代码分析的结果或是用于作为源代码阅读的参考,尽量不帖代码,力求用UML图来说明工作流. 本文参考的源代码版本为v501.20.1,如有兴趣请自行到苹果 ...
- Head First设计模式——适配器和外观模式
前言:为什么要一次讲解这两个模式,说点骚话:因为比较简单(*^_^*),其实是他们两个有相似和有时候我们容易搞混概念. 讲到这两个设计模式与另外一个“装饰者模式”也有相似,他们三个按照结构模式分类都属 ...
- 【Luogu P1878】舞蹈课
Luogu P1878 事实上这道题并不难,但我真没弄懂我手写堆为什么过不了.所以 STL大法好!!! 基本思路 对于每一对相邻异性,将他们的舞蹈技术的差插入一个堆 通过维护这个小根堆,每次就可以取得 ...
- 数据表与简单java类——一对多映射
例如:给定一个分类表和子分类表 得到如下信息: 1.一个分类的完整信息: 2.根据分类获取其对应的子分类 package Mapping_transformation; class item { pr ...
- SpringMVC 请求/响应乱码问题解决方案
请求乱码解决之get乱码问题 GET请求乱码原因分析 GET请求参数是通过请求行中的URL发送给Web服务器(Tomcat)的. Tomcat服务器会对URL进行编码操作(此时使用的是Tomcat设置 ...
- Prometheus Label 标签管理
目录 前言 配置测试 删除metric值 重新加载配置文件后测试 更换 重新加载配置文件后测试 删除 Label 标签 前言 在prometheus监控体系中.标签label是一个极为重要的参数,考虑 ...