zoukankan      html  css  js  c++  java
  • hdu 1140(三维)

    War on Weather

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


    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
     
    刚开始被题目和AC的人吓唬了,感觉很难,,结果就一水题
    题意:给出n颗卫星和m个人的三维坐标,问这m个人中有多少人可以被卫星至少一颗卫星覆盖
    题解:求出卫星和地球的切线长度,在地球上与卫星的距离不超过切线长度的都能看到.
    #include <iostream>
    #include <cstdio>
    #include <string.h>
    #include <math.h>
    #include <algorithm>
    const double pi = atan(1.0)*4;
    const double R = 20000/pi; ///地球半径
    struct Point{
        double x,y,z;
    }sate[105],person[105];
    
    double dis(Point a,Point b){
        return (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y)+(a.z-b.z)*(a.z-b.z);
    }
    int main()
    {
        int n,m;
        while(scanf("%d%d",&n,&m)!=EOF,n+m){
            for(int i=0;i<n;i++){
                scanf("%lf%lf%lf",&sate[i].x,&sate[i].y,&sate[i].z);
            }
            for(int i=0;i<m;i++){
                scanf("%lf%lf%lf",&person[i].x,&person[i].y,&person[i].z);
            }
            int ans = 0;
            for(int i=0;i<m;i++){
                for(int j=0;j<n;j++){
                    Point p = {0,0,0}; ///球心
                    int L = dis(sate[j],p)-R*R; ///切线长度
                    if(sqrt(L)>=sqrt(dis(sate[j],person[i]))){
                        ans++;
                        break;
                    }
                }
            }
            printf("%d
    ",ans);
        }
        return 0;
    }
  • 相关阅读:
    读写excel的组件
    一个关于C#语言中的Property的低级BUG,花了我二十分钟
    使用wwAppConfiguration类库来轻松读写应用程序配置信息
    为因地震死难的同胞默哀
    页面执行时生成静态文件的方法
    【转载】sp_spaceused2,看库里全部表占用的物理空间
    在微软中文技术论坛 CSDN cnblogs 三个微软社区中提问
    在内网服务器中获得真正的客户端ip的方法
    深拷贝的通用方法
    你知道在word中如何将段落标记替换成其他字符吗?
  • 原文地址:https://www.cnblogs.com/liyinggang/p/5438989.html
Copyright © 2011-2022 走看看