SGU 110. Dungeon 计算几何 难度:3
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;
}
SGU 110. Dungeon 计算几何 难度:3的更多相关文章
- sgu 110 Dungeon
这道题是计算几何,这是写的第一道计算几何,主要是难在如何求入射光线的反射光线. 我们可以用入射光线 - 入射光线在法线(交点到圆心的向量)上的投影*2 来计算反射光线,自己画一个图,非常清晰明了. 具 ...
- sgu 129 Inheritance 凸包,线段交点,计算几何 难度:2
129. Inheritance time limit per test: 0.25 sec. memory limit per test: 4096 KB The old King decided ...
- SGU 124. Broken line 射线法 eps的精准运用,计算几何 难度:3
124. Broken line time limit per test: 0.25 sec. memory limit per test: 4096 KB There is a closed bro ...
- sgu 125 Shtirlits dfs 难度:0
125. Shtirlits time limit per test: 0.25 sec. memory limit per test: 4096 KB There is a checkered fi ...
- hdu 3694 10 福州 现场 E - Fermat Point in Quadrangle 费马点 计算几何 难度:1
In geometry the Fermat point of a triangle, also called Torricelli point, is a point such that the t ...
- hdu 3685 10 杭州 现场 F - Rotational Painting 重心 计算几何 难度:1
F - Rotational Painting Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & % ...
- poj 3348 Cows 凸包 求多边形面积 计算几何 难度:0 Source:CCC207
Cows Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 7038 Accepted: 3242 Description ...
- SGU 分类
http://acm.sgu.ru/problemset.php?contest=0&volume=1 101 Domino 欧拉路 102 Coprime 枚举/数学方法 103 Traff ...
- 2018.10.15 bzoj4445: [Scoi2015]小凸想跑步(半平面交)
传送门 话说去年的省选计算几何难度跟前几年比起来根本不能做啊(虽然去年考的时候并没有学过计算几何) 这题就是推个式子然后上半平面交就做完了. 什么? 怎么推式子? 先把题目的概率转换成求出可行区域. ...
随机推荐
- bzoj 2118 墨墨的等式 - 图论最短路建模
墨墨突然对等式很感兴趣,他正在研究a1x1+a2y2+…+anxn=B存在非负整数解的条件,他要求你编写一个程序,给定N.{an}.以及B的取值范围,求出有多少B可以使等式存在非负整数解. Input ...
- C++ shared_ptr的用法
一. http://www.cnblogs.com/welkinwalker/archive/2011/10/20/2218804.html 二.http://www.cnblogs.com/Tian ...
- 如何修改ls命令列出来的目录颜色
答:默认为蓝色,在黑色背景下无法看清楚,因此以以下方法修改; 1.往~/.bash_profile文件中添加以下内容: export LS_COLORS='no=00:fi=00:di=01;33:l ...
- 蚂蚁感冒|2014年蓝桥杯B组题解析第八题-fishers
蚂蚁感冒 长100厘米的细长直杆子上有n只蚂蚁.它们的头有的朝左,有的朝右. 每只蚂蚁都只能沿着杆子向前爬,速度是1厘米/秒. 当两只蚂蚁碰面时,它们会同时掉头往相反的方向爬行. 这些蚂蚁中,有1只蚂 ...
- hdu 2586 How far away ? 倍增求LCA
倍增求LCA LCA函数返回(u,v)两点的最近公共祖先 #include <bits/stdc++.h> using namespace std; *; struct node { in ...
- BZOJ1307: 玩具 单调队列
Description 小球球是个可爱的孩子,他喜欢玩具,另外小球球有个大大的柜子,里面放满了玩具,由于柜子太高了,每天小球球都会让妈妈从柜子上拿一些玩具放在地板上让小球球玩. 这天,小球球把所有的N ...
- Oracle SQL Developer 中配置JDBC驱动程序连接
此博客仅作为自己备忘,没有丝毫技术含量.把Postgres的JDBC驱动程序放在Oracle SQL Developer的JDBC的文件夹下,然后安装Oracle SQL Developer,添加新连 ...
- Java8的新特性,二进制序列转十进制数字
package kata_007_二进制序列转十进制int; /** * java8 Lambda表达式转换binary序列->十进制数 */ import java.util.ArrayLis ...
- windows 模拟用户会话创建进程
在渗透当中,经常会碰到这样的问题.一个机器,机器上好几个用户,或者域内,想让某个机器的某个会话执行你想要执行的程序,或者中马,以当前会话来上线. 现在模拟如下的一个情况: 严格的DMZ,内网--> ...
- python ros 回充demo
#!/usr/bin/env python #coding=utf- import rospy from std_msgs.msg import String i= def talker(): glo ...