2017 Multi-University Training Contest - Team 9 1004&&HDU 6164 Dying Light【数学+模拟】

简介: Dying Light Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 513    Accepted Submission(s): ...

Dying Light

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 513    Accepted Submission(s): 122


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 104. 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(109xi,yi109;0ki0.9), which means the ith mirror's one end is at position (xi,yi) and another end is at (xi+1mod n,yi+1mod 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).

 

 

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

 

Source
分析:由于LsF一开始不再镜子上,按题面模拟即可。
由于反射率<=0.9 0.9^100<1e-4,所以反射次数不会超过100次。
每次暴力判断和哪个镜子相交,以及有没有在镜子焦点上。
下面给出AC代码:
  1 #include <cstring>
  2 #include <algorithm>
  3 #include <cstdio>
  4 #include <iostream>
  5 
  6 #define MAXN 5000
  7 #define eps 1e-9
  8 
  9 struct point
 10 {
 11     double x,y;
 12     point(double a = 0,double b = 0)
 13     {
 14         x = a; y = b;
 15     }
 16     friend point operator + (point a,point b)
 17     {
 18         return point(a.x+b.x,a.y+b.y);
 19     }
 20     friend point operator - (point a,point b)
 21     {
 22         return point(a.x-b.x,a.y-b.y);
 23     }
 24     friend double operator ^ (point a,point b)
 25     {
 26         return a.x*b.y-a.y*b.x;
 27     }
 28     friend double operator * (point a,point b)
 29     {
 30         return a.x*b.x+a.y*b.y;
 31     }
 32     friend point operator * (point a,double b)
 33     {
 34         return point(a.x*b,a.y*b);
 35     }
 36     friend point operator * (double a,point b)
 37     {
 38         return point(a*b.x,a*b.y);
 39     }
 40 
 41 };
 42 
 43 struct line
 44 {
 45     point s,e;
 46     line(point a = point(0,0),point b = point(0,0))
 47     {
 48         s = a; e = b;
 49     }
 50 };
 51 
 52 point p[MAXN+5];
 53 double c[MAXN+5];
 54 int n;
 55 point s[2];
 56 
 57 int sgn(double x)
 58 {
 59     if (x>eps) return 1;
 60     if (x<-eps) return -1;
 61     return 0;
 62 }
 63 
 64 point Get_Intersect(line a,line b)
 65 {
 66     double u=(a.e-a.s)^(b.s-a.s);
 67     double v=(a.s-a.e)^(b.e-a.e);
 68     point p;
 69     p.x=(b.s.x*v+b.e.x*u)/(v+u);
 70     p.y=(b.s.y*v+b.e.y*u)/(v+u);
 71     return p;
 72 }
 73 
 74 int main()
 75 {
 76 //    freopen("input.txt","r",stdin);
 77     while(scanf("%d",&n)!=EOF)
 78     {for (int i=0;i<n;i++) scanf("%lf%lf%lf",&p[i].x,&p[i].y,&c[i]);
 79     p[n] = p[0];
 80     s[0] = point(0,0);
 81     scanf("%lf%lf",&s[1].x,&s[1].y);
 82 
 83     double now = 1.0;
 84     int ans = 0;
 85     bool flag = 1;
 86     point temp;
 87     point temp2;
 88     line l1,l2,l3,l4;
 89     while (now > 1e-4)
 90     {
 91         ans++;
 92         for (int i=0;i<n;i++)
 93         {
 94             if (!sgn((p[i]-s[0])^s[1]))
 95             {
 96                 now = 0;
 97                 flag = 0;
 98                 break;
 99             }
100         }
101         if (!flag) break;
102         for (int i=0;i<n;i++)
103         {
104             if (sgn((p[i]-s[0])^s[1]) > 0 && sgn(s[1]^(p[i+1]-s[0]))>0)
105             {
106                 l1 = line(p[i+1],p[i]);
107                 l2 = line(s[0],s[1]+s[0]);
108                 temp = Get_Intersect(l1,l2);
109 
110                 l3 = line(temp,point(p[i+1].y-p[i].y,p[i].x-p[i+1].x)+temp);
111                 l4 = line(s[0],point(p[i].x-p[i+1].x,p[i].y-p[i+1].y)+s[0]);
112 
113                 temp2 = Get_Intersect(l3,l4);
114                 temp2 = 2*temp2-s[0];
115                 s[0] = temp;
116                 s[1] = temp2-s[0];
117                 now *= c[i];
118                 break;
119             }
120         }
121     }
122     printf("%d\n",ans);
123     }
124     return 0;
125 }

 

目录
相关文章
|
2月前
|
机器学习/深度学习 算法
|
5月前
|
算法 数据挖掘
【博士每天一篇文献-算法】A pseudo-inverse decomposition-based self-organizing modular echo
本文提出了一种基于伪逆分解的自组织模块化回声状态网络(PDSM-ESN),通过增长-修剪方法和伪逆分解提高学习速度,有效解决了ESN中的不适定问题,并在多个数据集上展示了其优越的预测性能和鲁棒性。
29 1
|
Java
HDU - 2018 Multi-University Training Contest 3 - 1012: Visual Cube
HDU - 2018 Multi-University Training Contest 3 - 1012: Visual Cube
134 0
HDU - 2018 Multi-University Training Contest 3 - 1012: Visual Cube
|
Java
HDU - 2018 Multi-University Training Contest 2 - 1004: Game
HDU - 2018 Multi-University Training Contest 2 - 1004: Game
109 0
|
Java
HDU - 2018 Multi-University Training Contest 2 - 1010: Swaps and Inversions
HDU - 2018 Multi-University Training Contest 2 - 1010: Swaps and Inversions
118 0
|
Java
HDU - 2018 Multi-University Training Contest 1 - 1001: Maximum Multiple
HDU - 2018 Multi-University Training Contest 1 - 1001: Maximum Multiple
103 0
|
语音技术 机器学习/深度学习 开发者
语音顶会Interspeech 论文解读|Towards A Fault-tolerant Speaker Verification System: A Regularization Approach To Reduce The Condition Number
Interspeech是世界上规模最大,最全面的顶级语音领域会议,本文为Siqi Zheng, Gang Liu, Hongbin Suo, Yun Lei的入选论文
语音顶会Interspeech 论文解读|Towards A Fault-tolerant Speaker Verification System: A Regularization Approach To Reduce The Condition Number
|
Java
2017 Multi-University Training Contest - Team 9 1003&&HDU 6163 CSGO【计算几何】
CSGO Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 127    Accepted Submission(s): 20 Pro...
1422 0
|
Java
2017 Multi-University Training Contest - Team 9 1005&&HDU 6165 FFF at Valentine【强联通缩点+拓扑排序】
FFF at Valentine Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 1060    Accepted Submission(...
1217 0
|
Java
2017 Multi-University Training Contest - Team 9 1002&&HDU 6162 Ch’s gift【树链部分+线段树】
Ch’s gift Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 1354    Accepted Submission(s): 496 Problem Description Mr.
1305 0