110. Dungeon

time limit per test: 0.25 sec. 
memory limit per test: 4096 KB

The mission of space explorers found on planet M the vast dungeon. One of the dungeon halls is fill with the bright spheres. The explorers find out that the light rays reflect from the surface of the spheres according the ordinary law (the incidence angle is equal to the reflectance angle, the incidence ray, the reflected ray and the perpendicular to the sphere surface lay in the one plane). The ancient legend says that if the light ray will reflect from the spheres in the proper order, than the door to the room with very precious ancient knowledge will open. You are not to guess the right sequence; your task is much simpler. You are given the positions and the radii of the spheres, the place where the laser shot was made and the direction of light propagation. And you must find out the sequence in which the light will be reflected from the spheres.

Input

The first line of input contains the single integer n (1≤n≤50) - the amount of the spheres. The next n lines contain the coordinates and the radii of the spheres xi, yi, zi, ri (the integer numbers less or equal to 10000 by absolute value). The last line contains 6 real numbers - the coordinates of two points. The first one gives the coordinates of the place of laser shot, and the second gives the direction in which it was made (the second point is the point on the ray). The starting point of the ray lies strictly outside of any sphere.

Output

Your program must output the sequence of sphere numbers (spheres are numbers from 1 as they was given in input), from which the light ray was reflected. If the ray will reflect more the 10 times, than you must output first 10, then a space and the word 'etc.' (without quotes). Notice: if the light ray goes at a tangent to the sphere you must assume that the ray was reflected by the sphere.

Sample Input 1

1
0 0 2 1
0 0 0 0 0 1

Sample Output 1

1

Sample Input 2

2
0 0 2 1
0 0 -2 1
0 0 0 0 0 100

Sample Output 2

1 2 1 2 1 2 1 2 1 2 etc.

感想:计算几何远观的时候最难
思路:
1 判断射线反射交哪个球 如果使用点斜式会在0处出问题,题解使用了起点到球的距离相对射线反向的倍数,注意当这个倍数为0的时候,只要不是从这个球反射出去的也成立(也就是开始的时候光源就在这个球表面)
2 求反射后的光线向量,做一个以入射光线为平行边的一边,法线(圆心-入射点方向)为对角线做一个菱形,明显反射光线就是另外一边..的反向(!),所以反射光线就是入射向量-入射光线在法线上的投影*2,在这个地方弄成法线在入射光线WA一次
投影为单位法线*(入射和法线的点积)
最后注意一下,先判断有没有第11次反射再输出"etc."
#include<cstdio>
#include <cstring>
#include <cmath>
using namespace std;
class pnt{
public :
double x,y,z;
pnt():x(0),y(0),z(0){}
pnt(double tx,double ty,double tz):x(tx),y(ty),z(tz){}
pnt operator -(pnt besub){
pnt ans;
ans.x=x-besub.x;
ans.y=y-besub.y;
ans.z=z-besub.z;
return ans;
}
pnt operator +(pnt beadd){
pnt ans;
ans.x=x+beadd.x;
ans.y=y+beadd.y;
ans.z=z+beadd.z;
return ans;
}
pnt operator*(double bemul){
pnt ans;
ans.x=x*bemul;
ans.y=y*bemul;
ans.z=z*bemul;
return ans;
}
pnt operator/(double bediv){
pnt ans;
ans.x=x/bediv;
ans.y=y/bediv;
ans.z=z/bediv;
return ans;
}
double dot(pnt bepnt){
return x*bepnt.x+y*bepnt.y+z*bepnt.z;
}
double caldis(pnt other){
return sqrt((x-other.x)*(x-other.x)+(y-other.y)*(y-other.y)+(z-other.z)*(z-other.z));
}
double len(){
return sqrt(x*x+y*y+z*z);
}
}; pnt ball[51],nowref,dir,start,normal;
double ballr[51],mindis,nowdis;
int n,nowball,nxtball;
const double inf=1e18;
int main(){
scanf("%d",&n);
for(int i=1;i<=n;i++){
scanf("%lf%lf%lf%lf",&ball[i].x,&ball[i].y,&ball[i].z,ballr+i);
}
scanf("%lf%lf%lf%lf%lf%lf",&start.x,&start.y,&start.z,&dir.x,&dir.y,&dir.z);
dir=dir-start;
dir=dir/dir.len();
nowball=0;
for(int time=0;time<11;time++){
nxtball=0;
mindis=inf;
for(int i=1;i<=n;i++){//开始使用了点法式,不行...换成比例简洁不出错
if(i==nowball)continue;
double a=dir.x*dir.x+dir.y*dir.y+dir.z*dir.z;
double b=2*(dir.x*(start.x-ball[i].x)+dir.y*(start.y-ball[i].y)+dir.z*(start.z-ball[i].z));
double c=(start.x-ball[i].x)*(start.x-ball[i].x)+(start.y-ball[i].y)*(start.y-ball[i].y)+(start.z-ball[i].z)*(start.z-ball[i].z)-ballr[i]*ballr[i];
double delta=b*b-4*a*c;
if(delta<0)continue; nowdis=(-b+sqrt(delta))/2/a;
if(nowdis>=0&&nowdis<mindis){//ATTENTION
mindis=nowdis;
nxtball=i;
nowref=start+dir*(nowdis);
}
nowdis=(-b-sqrt(delta))/2/a;
if(nowdis>=0&&nowdis<mindis){//ATTENTION
mindis=nowdis;
nxtball=i;
nowref=start+dir*(nowdis);
}
} if(nxtball==0){break;}
if(time)putchar(' ');
if(time<10)printf("%d",nxtball);
else {puts("etc.");break;} normal=ball[nxtball]-nowref;
normal=normal/normal.len();
dir=dir-normal*(normal.dot(dir)*2.00);
start=nowref;
nowball=nxtball;
}
return 0;
}

  

最新文章

  1. hash表长度优化证明
  2. 【转】apache DateFormatUtils 与 DateUtils 的使用
  3. Python 3.6.0的sqlite3模块无法执行VACUUM语句
  4. TCP协议学习记录 (三) Ping程序 RR选项 记录路由hop
  5. bzoj4415&amp;&amp;bzoj4416&amp;&amp;bzoj4417:SHOI2013Day1题解
  6. c++ 左值 和 右值
  7. ubuntu 在mac 的 Parallels 的分辨率问题
  8. Linux基础入门(20135207 王国伊)
  9. HDU 5996:dingyeye loves stone(阶梯博弈)
  10. SQLServer 窗口函数
  11. poj2265
  12. beyond compare ftp 文件夹同步
  13. C++静态成员变量和静态成员函数小结
  14. 【转】设置SecureCRT会话的缓冲区大小
  15. HDU 1564 Play a game
  16. Gentoo(贱兔)Linux安装笔记
  17. Deviceiocontrol操作异常时,关于getlasterror的错误代码解析
  18. wpf改变网格字体颜色
  19. SAP+ 差旅报销集成方案的实现
  20. Linux命令缩写的全称

热门文章

  1. mpvue小程序开发入门级指南
  2. Win10 Edge浏览器怎么重装 Win10重装Edge浏览器
  3. [luogu2119]魔法阵 NOIP2016T4
  4. 项目梳理6——使用WebApiTestClient为webapi添加测试
  5. React Native控件之Picker
  6. 纯CSS实现一个微信logo,需要几个标签?
  7. Mac OS下 selenium 驱动safari日志
  8. Jmeter 中对响应报文处理后断言用到BeanShell Assertion
  9. Blue_Flke团队项目设计完善&amp;编码测试
  10. Codeforces 861D - Polycarp&#39;s phone book