hdu-1140 War on Weather(基础三维几何)

题目链接:点击打开链接

War on Weather

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 492    Accepted Submission(s): 268


Problem Description
After an unprovoked hurricane attack on the south shore, Glorious Warrior has declared war on weather. The first salvo in this campaign will be a coordinated pre-emptive attack on as many tropical depressions as possible. GW reckons that the attack will neutralize the tropical depressions before they become storms, and dissuade others from forming. 
GW has at his disposal k space-to-earth killer satellites at various locations in space. m tropical depressions are known to exist at various locations on the earth's surface. Each satellite can attack any number of targets on the earth provided there is line of sight between the satellite and each target. How many different targets can be hit? 
 

Input
The input consists of several test cases. Each case begins with a line containing integers 0 < k, m &le 100 as defined above. k lines follow, each giving x,y,z - the location in space of a satellite at the scheduled time of attack. m lines then follow, each giving x,y,z - the location of a target tropical depression. Assume the earth is a sphere centred at (0,0,0) with circumference 40,000 km. All targets will be on the surface of the earth (within 10-9 km) and all satellites will be at least 50 km above the surface. A line containing 0 0 follows the last test case. 
 

Output
For each test case, output a line giving the total number of targets that can be hit. If a particular target falls within 10-8 km of the boundary between being within line-of-sight and not, it may be counted either way. (That is, you need not consider rounding error so long as it does not exceed 10-8 km.) 
 

Sample Input
  
  
3 2 -10.82404031 -1594.10929753 -6239.77925152 692.58497298 -5291.64700245 4116.92402298 3006.49210582 2844.61925179 5274.03201053 2151.03635167 2255.29684503 5551.13972186 -1000.08700886 -4770.25497971 4095.48127333 3 4 0 0 6466.197723676 0 6466.197723676 0 6466.197723676 0 0 6366.197723676 0 0 6365.197723676 112.833485488 0 0 0 6366.197723676 0 -6366.197723676 0 0 0
 

Sample Output
  
  
2 3
题意:地球的球心在(0,0,0),球最中心的圆周长是40000.也就是说半径是20000/π。  有k个卫星在地球外,卫星能看到的范围是有限的,可以理解为一个太阳能照射到地球上的面是有限的,不是整个球面。然后再给m个地球上的点,问一共有几个点会被卫星观察到。

思路:我们知道,卫星能照射到的最远距离是该点到地球的切线的切点。距离是sqrt(卫星到球心的距离的平方-地球半径的平方)。所以对于这个卫星,只要地球上的点到卫星的距离小于或等于这个距离,就是能照射到的。

代码:

#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
#define PI 3.1415926535897932384626433832795//一般题目写成3.1415926就可以了
#define R 20000.0/PI
#define N 1010
struct Node
{
    double x,y,z;
}node[N];
int main()
{
    int k,m;
    double maxd,d,x,y,z;
    while(scanf("%d %d",&k,&m)&&k&&m)
    {
        int num=0;
        for(int i=0;i<k;i++)
            scanf("%lf %lf %lf",&node[i].x,&node[i].y,&node[i].z);
        for(int i=0;i<m;i++)
        {
            scanf("%lf %lf %lf",&x,&y,&z);
            for(int j=0;j<k;j++)
            {
                maxd=sqrt(node[j].x*node[j].x+node[j].y*node[j].y+node[j].z*node[j].z-R*R);
                d=sqrt((node[j].x-x)*(node[j].x-x)+(node[j].y-y)*(node[j].y-y)+(node[j].z-z)*(node[j].z-z));
                if(d<=maxd)
                {
                    num++;
                    break;
                }
            }
        }
        printf("%d\n",num);
    }
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值