POJ 3129

How I Wonder What You Are!

Time Limit: 5000MS   Memory Limit: 65536K
Total Submissions: 1154   Accepted: 815

Description

One of the questions children often ask is “How many stars are there in the sky?” Under ideal conditions, even with the naked eye, nearly eight thousands are observable in the northern hemisphere. With a decent telescope, you may find many more, but as the sight field will be limited, you may find much less at a time.

Children may ask the same questions to their parents on a planet of some solar system billions of light-years away from the Earth. Their telescope are similar to ours with circular sight fields, but alien kids have many eyes and ca look into different directions at a time through may telescopes.

Given a set of positions of stars, a set of telescopes and the directions the are looking to, your task is to count up how many stars can be seen through these telescopes.

Input

The input consists of one or more datasets. The number of datasets is less than 50. Each dataset describes stars and the parameters of the telescopes used.

The first line of a dataset contains a positive integer n not exceeding 500, meaning the number of stars. Each of the n lines following it contains three decimal fractions, sx, sy, and sz. They give the position (sx, sy, sz) of the star described in Euclidean coordinates. You may assume −1000 ≤ sx ≤ 1000, −1000 ≤ sy ≤ 1000, −1000 ≤ sz ≤ 1000, and (sx, sy, sz) ≠ (0, 0, 0).

Then comes a line containing a positive integer m not exceeding 50, meaning the number of telescopes. Each of the following m lines contains four decimal fractions, tx, ty, tz and ψ, describing a telescope.

The first three numbers represent the direction of the telescope. All the telescopes are at the origin of the coordinate system (0, 0, 0) (we ignore the size of the planet). The three numbers give the point (tx, ty, tz) which can be see in the center of the sight through the telescope. You may assume −1000 ≤ tx ≤ 1000, −1000 ≤ ty ≤ 1000, −1000 ≤ tz ≤ 1000, and (tx, ty, tz) ≠ (0, 0, 0).

The fourth number ψ (0 ≤ ψ ≤ π ⁄ 2) gives the angular radius, radians, of the sight field of the telescope. Let us define that θi,j is the angle between the direction of the i-th star and the center direction of the j-th telescope and ψj is the angular radius of the sight field of the j-th telescope. the i-th star is observable through the j-th telescope if and only if θi,j is less than ψj. You may assume that |θi,j − ψj| > 0.00000001 for all pairs of i and j.

Figure 1: Direction and angular radius of a telescope

The end of the input is indicated with a line containing a single zero.

Output

For each dataset, one line containing an integer meaning the number of stars observable through the telescope should be output. No other characters should be contained in the output. Note that stars that can be seen through more than one telescope should not be counted twice or more.

Sample Input

3 
100 0 500 
-500.243 -200.1 -300.5 
0 300 200 
2 
1 1 1 0.65 
-1 0 0 1.57 
3 
1 0 0 
0 1 0 
0 0 1 
4 
1 -1 -1 0.9553 
-1 1 -1 0.9554
-1 -1 1 0.9553
-1 1 -1 0.9554
3 
1 0 0 
0 1 0 
0 0 1 
4 
1 -1 -1 0.9553
-1 1 -1 0.9553
-1 -1 1 0.9553
-1 1 -1 0.9553
0

Sample Output

2
1
0

Source

Japan 2006

大致题意:

给定一组恒星的位置,一组望远镜和正在寻找的方向,你的任务是计算通过这些望远镜可以看到多少颗恒星。

输入

输入由一个或多个数据集组成。数据集的数量小于50.每个数据集都描述了恒星和所用望远镜的参数。

数据集的第一行包含一个不超过500的正整数n,表示星数。其后面的n行中的每一行包含三个小数部分,sx,sy和sz。它们给出了欧几里德坐标中描述的恒星的位置(sx,sy,sz)。您可以假设-1000≤sx≤1000,-1000≤sy≤1000,-1000≤sz≤1000,并且(sx,sy,sz)≠(0,0,0)。

然后是一条包含一个不超过50的正整数的线,这意味着望远镜的数量。以下m行中的每一行包含四个小数部分,tx,ty,tz和ψ,描述望远镜。

前三个数字代表望远镜的方向。所有的望远镜都在坐标系的原点(0,0,0)(我们忽略了行星的大小)。这三个数字给出了点(tx,ty,tz),它可以通过望远镜在瞄准器的中心看到。您可以假设-1000≤tx≤1000,-1000≤ty≤1000,-1000≤tz≤1000,并且(tx,ty,tz)≠(0,0,0)。

第四个数ψ(0≤ψ≤π/ 2)给出望远镜视野的角半径弧度。让我们定义θi,j是第i个星的方向和第j个望远镜的中心方向之间的角度,ψj是第j个望远镜的视场的角半径。当且仅当θi,j小于ψj时,通过第j望远镜可观察到第i个恒星。你可以假设|θi,j  - ψj|所有i和j对都是> 0.00000001。

解题思路:

利用点积求每个望远镜与每颗星星之间的夹角,并将其与ψ对比,得出是否可以看到该星星,注意一颗星可能被多个望远镜看到。

代码:

#include <iostream>
#include <cmath>
#include <cstdio>
using namespace std;
const double eps=0.00000001;
struct P{
	double x,y,z;
}p[512],tel[64];
double a[64];
int main()
{
	int i,j,cnt,n,m;
	while(scanf("%d",&n)==1&&n){
		cnt=0;
		for(i=0;i<n;++i)
			scanf("%lf%lf%lf",&p[i].x,&p[i].y,&p[i].z);
		scanf("%d",&m);
		for(i=0;i<m;++i)
			scanf("%lf%lf%lf%lf",&tel[i].x,&tel[i].y,&tel[i].z,&a[i]);
		for(i=0;i<n;++i){
			int ok=0;
			for(j=0;j<m&&!ok;++j){
				double ra=sqrt(p[i].x*p[i].x+p[i].y*p[i].y+p[i].z*p[i].z);		
				double rb=sqrt(tel[j].x*tel[j].x+tel[j].y*tel[j].y+tel[j].z*tel[j].z);
				double c=acos((p[i].x*tel[j].x+p[i].y*tel[j].y+p[i].z*tel[j].z)/(ra*rb));
				if(c<a[j]||fabs(c-a[j])<eps)
					ok=1;
			}
			if(ok)
				++cnt;
		}
		printf("%d\n",cnt);
	}
	return 0;	
}
发布了158 篇原创文章 · 获赞 34 · 访问量 8万+

猜你喜欢

转载自blog.csdn.net/qq_40421671/article/details/95968374
POJ