zjuoj 3608 Signal Detection

http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3608

Signal Detection


Time Limit: 2 Seconds      Memory Limit: 65536 KB


Parallelepiped
Type Prism
Faces 6 parallelograms
Edges 12
Vertices 8

Dr. Gale is testing his laser system. He uses a detector to collect the signals from a laser generator. He also puts a special prism in the system so that he can filter the noise. But he is not very sure where to put the detector to collect the signals. Can you help him with this problem?


In order to simplify the problem, here we assume the prism is a parallelepiped, which is a three-dimensional figure formed by six parallelograms. The laser goes in one direction and the detector can receive signals from any direction. The detector is placed on the ground where the z-coordinate is zero. There is no energy lost in the refraction. That is to say, there is no reflection in the signal transmission. You don‘t need to consider the situation of total reflection or the degenerate situation.

Input

There are multiple test cases. The first line of input contains an integer T (T ≤ 50) indicating the number of test cases. Then T test cases follow.

The first line of each test case contains 3 integers, indicating the coordinates of the laser generator. The second line contains 3 integers describing a point the laser will go through without the prism. The third line contains 3 integers describing a vertex A of the prism. The fourth to the sixth lines contain 3 integers each, describing an adjacent vertex of A. The seventh line contains a real number u, the refractive index of the prism.(1 < u ≤ 10) The absolute value of the coordinates will not exceed 1000. The z coordinates are all nonnegative. The prism and the laser generator are strictly above the ground and the laser generator will not be inside the prism.

Output

If there is no place in the ground that can receive the signals output "Error". Otherwise, output the x and y coordinates the place accurate to 0.001.

Sample Input

2
0 0 10
0 0 0
-5 -5 1
5 -5 11
-5 5 1
-6 -5 2
1.4142136
0 0 10
0 0 11
-5 -5 1
5 -5 1
-5 5 1
-5 -5 2
2

Sample Output

0.423 0.000
Error

References



Author: GUAN, Yao
Contest: The 9th Zhejiang Provincial Collegiate Programming Contest

AC代码:

  1 #include <cstdlib>
  2 #include <cstdio>
  3 #include <cstring>
  4 #include <cmath>
  5 #include <iostream>
  6 #include <algorithm>
  7 #include <string>
  8 #include <vector>
  9 #include <set>
 10 #include <map>
 11 #include <queue>
 12 #include <time.h>
 13 using namespace std;
 14 typedef long long llong;
 15
 16 inline int bit(int x, int i){ return (x>>i) & 1;}
 17 inline int setb(int x, int i){ return x | (1 << i);}
 18 inline int clrb(int x, int i){ return x & (~(1 << i));}
 19 inline int lowb(int x){return x & (-x);}
 20 const double eps = 1e-9;
 21 struct Point{
 22     double x, y, z;
 23     Point(){}
 24     Point(double x, double y, double z):x(x), y(y), z(z){}
 25     double len(){
 26         return sqrt(x * x + y * y + z * z);
 27     }
 28     Point shrink(double l = 1.0){
 29         double s = l / len();
 30         return Point(x * s, y * s, z * s);
 31     }
 32     void input(){
 33         scanf("%lf %lf %lf", &x, &y, &z);
 34     }
 35 };
 36
 37 Point operator +(const Point &p, const Point &q){
 38     return Point(p.x + q.x, p.y + q.y, p.z + q.z);
 39 }
 40 Point operator -(const Point &p, const Point &q){
 41     return Point(p.x - q.x, p.y - q.y, p.z - q.z);
 42 }
 43 Point operator *(const Point &p, const double &s){
 44     return Point(p.x * s, p.y * s, p.z * s);
 45 }
 46 Point operator *(const Point &p, const Point &q){
 47     return Point(p.y * q.z - p.z * q.y,
 48                  p.z * q.x - p.x * q.z,
 49                  p.x * q.y - p.y * q.x);
 50 }
 51 double operator &(const Point &p, const Point &q){
 52     return p.x * q.x + p.y * q.y + p.z * q.z;
 53 }
 54
 55 Point p, q, v[8];
 56 double r;
 57 int face[][4] ={
 58 {3, 2, 1, 0},
 59 {4, 5, 6, 7},
 60 {0, 1, 5, 4},
 61 {2, 3, 7, 6},
 62 {1, 2, 6, 5},
 63 {0, 4, 7, 3},
 64 };
 65 Point fn[6];
 66 double fb[6];
 67
 68 double inter(const Point &p, const Point &d, const Point &n, double b){
 69     return (b - (n & p)) / (n & d);
 70 }
 71 bool collide(double R){
 72     int hf = -1;
 73     double ht;
 74     Point d = (q - p);
 75     for(int i = 0;i < 6; ++i){
 76         if(fabs(fn[i] & d) < eps) continue;
 77         double t = inter(p, d, fn[i], fb[i]);
 78         if(t <= eps) continue;
 79         Point hit = p + d * t;
 80         bool ok = true;
 81         for(int j = 0;j < 4; ++j){
 82             if((((v[face[i][j]]-hit) * (v[face[i][(j + 1)%4]] - hit)) & fn[i]) <= 0) ok = false;
 83         }
 84         if(ok && (hf < 0 || t < ht)){
 85             hf = i;
 86             ht = t;
 87         }
 88     }
 89     if(hf < 0) return false;
 90
 91     Point hit = p + d * ht;
 92     Point vx = fn[hf].shrink();
 93     if(fabs((vx * d).len()) < eps){
 94         p = hit;
 95         q = hit + d;
 96         return true;
 97     }
 98     double dx = vx & d;
 99     if(dx < 0) vx = vx * -1, dx = -dx;
100     Point vy = ((vx * d) * vx).shrink();
101     double dy = vy & d;
102     if(dy < 0) vy = vy * -1, dy = -dy;
103     double theta0 = atan2(dy, dx);
104     double theta = asin(sin(theta0) / R);
105     d = vx * cos(theta) + vy * sin(theta);
106     p = hit;
107     q = hit + d;
108     return true;
109 }
110 int main(){
111     int TT;
112     scanf("%d", &TT);
113     for(int cas = 1; cas <= TT; ++cas){
114         p.input();
115         q.input();
116
117         v[0].input();
118         v[1].input();
119         v[3].input();
120         v[2] = v[1] + v[3] - v[0];
121
122         v[4].input();
123         v[5] = v[4] + v[1] - v[0];
124         v[6] = v[4] + v[2] - v[0];
125         v[7] = v[4] + v[3] - v[0];
126
127         scanf("%lf", &r);
128         for(int i = 0;i < 6; ++i){
129             fn[i] = (v[face[i][1]] - v[face[i][0]]) *
130                     (v[face[i][3]] - v[face[i][0]]);
131             fb[i] = fn[i] & v[face[i][0]];
132         }
133         if(collide(r)){
134             collide(1./r);
135         }
136         Point norm(0, 0, 1);
137         Point dir = q - p;
138         if(fabs(norm & dir) < eps) puts("Error");
139         else{
140             double t = inter(p, dir, norm, 0);
141             if(t < 0) puts("Error");
142             else{
143                 Point hit = p + dir * t;
144                 printf("%.3f %.3f\n", hit.x, hit.y);
145             }
146         }
147     }
148     return 0;
149 }

时间: 2024-12-29 23:47:43

zjuoj 3608 Signal Detection的相关文章

CURRICULUM VITAE

Dr.  YUE  XIAO Professor National Key Lab of Communication Science and Technology on Communications University of Electronic Science and Technology of China (UESTC) No.2006, Xiyuan Ave, West Hi-Tech Zone, Chengdu, 611731, P.R.China Email: [email prot

天线罩基础[转载]

May 2008 A Fundamental and Technical Review of Radomes By Lance Griffiths, Ph.D., Radome Design Engineer, MFG Galileo Composites The basic function of a radome is to form a protective cover between an antenna and the environment with minimal impact t

ROC和AUC介绍以及如何计算AUC

ROC(Receiver Operating Characteristic)曲线和AUC常被用来评价一个二值分类器(binary classifier)的优劣,对两者的简单介绍见这里.这篇博文简单介绍ROC和AUC的特点,以及更为深入地,讨论如何作出ROC曲线图以及计算AUC. ROC曲线 需要提前说明的是,我们这里只讨论二值分类器.对于分类器,或者说分类算法,评价指标主要有precision,recall,F-score1,以及我们今天要讨论的ROC和AUC.下图是一个ROC曲线的示例2. 正

【转】ROC和AUC介绍以及如何计算AUC

转自:https://www.douban.com/note/284051363/ ROC(Receiver Operating Characteristic)曲线和AUC常被用来评价一个二值分类器(binary classifier)的优劣,对两者的简单介绍见[这里](http://bubblexc.com/y2011/148/).这篇博文简单介绍ROC和AUC的特点,以及更为深入地,讨论如何作出ROC曲线图以及计算AUC. # ROC曲线需要提前说明的是,我们这里只讨论二值分类器.对于分类器

libevent学习文档(三)working with event

Events have similar lifecycles. Once you call a Libevent function to set up an event and associate it with an event base, it becomes initialized. At this point, you can add, which makes it pending in the base. When the event is pending, if the condit

DSP开发资源总结,经典书籍,论坛

OMAP4开发资源总结: 一.TI OMAP4官网介绍: http://www.ti.com.cn/general/cn/docs/wtbu/wtbuproductcontent.tsp?templateId=6123&navigationId=12843&contentId=53243 二.OMAPpedia.org,This site has information on various projects in the communityaround OMAP platforms ht

ROC和AUC介绍以及如何计算AUC ---好!!!!

from:https://www.douban.com/note/284051363/?type=like 原帖发表在我的博客:http://alexkong.net/2013/06/introduction-to-auc-and-roc/ ROC(Receiver Operating Characteristic)曲线和AUC常被用来评价一个二值分类器(binary classifier)的优劣,对两者的简单介绍见[这里](http://bubblexc.com/y2011/148/).这篇博

ROC 曲线

Receiver Operating Characteristic (接收机操作特性曲线) 是以虚警率为横轴,以击中率为纵轴,长成如下模样: 所谓击中率(hit)是指将正样本判断为正样本的比例,而虚警率(false alarm)是指将负样本判断为正样本的比例. 对书中例子的解读: 假如我们要检测一个脉冲信号,检测器检测到的是内部某点的电压值,当外部脉冲信号出现时具有均值u1,不出现时具有均值u2.假设由于噪声的影响二者服从均值不同方差相同的两个正态分布,如下图: 构造分类器,以x*为阈值,对一堆

分类器模型评价指标

Spark mllib 自带了许多机器学习算法,它能够用来进行模型的训练和预测.当使用这些算法来构建模型的时候,我们需要一些指标来评估这些模型的性能,这取决于应用和和其要求的性能.Spark mllib 也提供一套指标用来评估这些机器学习模型. 具体的机器学习算法归入更广泛类型的机器学习应用,例如:分类,回归,聚类等等,每一种类型都很好的建立了性能评估指标.本节主要分享分类器模型评价指标. ROC曲线 ROC曲线指受试者工作特征曲线 / 接收器操作特性曲线(receiver operating