hdoj1140War on Weather
2015-09-26 11:23
218 查看
War on WeatherTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 438 Accepted Submission(s): 239 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 |
解题思路:求出地球上与卫星的切线长如果卫星与到某点距离大于切线长不在攻击范围
#include<cstdio> #include<cstdlib> #include<cstring> #include<cmath> #define PI acos(-1.0) #define R (20000.0/PI) #define eps 11e-9 using namespace std; struct point{ double x,y,z; }sate[110],target[110]; int sgn(double n){ if(fabs(n)<eps)return 0; else if(n<0)return -1; return 1; } int main() { int n,m,i,j; while(scanf("%d%d",&n,&m),n||m){ for(i=0;i<n;++i){ scanf("%lf%lf%lf",&sate[i].x,&sate[i].y,&sate[i].z); } for(i=0;i<m;++i){ scanf("%lf%lf%lf",&target[i].x,&target[i].y,&target[i].z); } int ans=0; for(i=0;i<m;++i){ for(j=0;j<n;++j){ double d=sqrt(sate[j].x*sate[j].x+sate[j].y*sate[j].y+sate[j].z*sate[j].z-R*R); double dst=sqrt((sate[j].x-target[i].x)*(sate[j].x-target[i].x)+(sate[j].y-target[i].y)*(sate[j].y-target[i].y)+(sate[j].z-target[i].z)*(sate[j].z-target[i].z)); if(sgn(dst-d)<=0)break; } if(j<n)ans++; } printf("%d\n",ans); } return 0; }
相关文章推荐
- On Error Resume Next 语句
- 简单对比分析Ruby on Rails 和 Laravel
- VBScript中On Error语句用法小结
- 解析sql语句中left_join、inner_join中的on与where的区别
- INSERT INTO .. ON DUPLICATE KEY更新多行记录
- win7安装ruby on rails开发环境
- jQuery事件绑定.on()简要概述及应用
- jQuery中on()方法用法实例详解
- jQuery中delegate与on的用法与区别示例介绍
- mysql ON DUPLICATE KEY UPDATE语句示例
- List all the Databases on a SQL Server
- 用实际代码演示Ruby的容易被误解的6个特性
- 深入Oracle的left join中on和where的区别详解
- jQuery中delegate和on的用法与区别详细解析
- Apache No space left on device: mod_rewrite: could not create rewrite_log_lock Configuration Failed
- apache You don't have permission to access /test.php on this server解决方法
- nginx: [warn] "log_format" directive used only on "http" level 解决方法
- Auto Layout on iOS Versions prior to 6.0 解决办法
- Window7上安装Ruby on Rails
- 编译安装mod_jk on centOS