hdu1140

来源:互联网 发布:生鲜电商源码 编辑:程序博客网 时间:2024/05/03 13:56

War on Weather

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


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.77925152692.58497298 -5291.64700245 4116.924022983006.49210582 2844.61925179 5274.032010532151.03635167 2255.29684503 5551.13972186-1000.08700886 -4770.25497971 4095.481273333 40 0 6466.1977236760 6466.197723676 06466.197723676 0 06366.197723676 0 06365.197723676 112.833485488 00 0 6366.1977236760 -6366.197723676 00 0
 

Sample Output
23

已知地球球心在空间坐标系原点(0, 0, 0)处,给出太空中n个卫星坐标,k个在地球表面上目标的坐标,问有多少个目标可以被卫星攻击。

利用向量点乘判断一个目标-卫星 与 目标-球心的夹角是否为钝角。


#include <cstdio>#include <cmath>#include <iostream>using namespace std;const int MAXN = 1e2 + 5;struct Point{double x, y, z;Point(){}Point(const double &a, const double &b, const double &c) : x(a), y(b), z(c){};double operator * (const Point &k){return this->x * k.x + this->y * k.y + this->z * k.z;}Point operator - (const Point &k){return Point( this->x - k.x, this->y - k.y, this->z - k.z);}void input(){scanf("%lf%lf%lf", &x, &y, &z);}};typedef Point Vector;Point O(0.0, 0.0, 0.0), sates[MAXN], target;void solve(){int n, m;register Vector u, v;while( scanf("%d%d", &n, &m) == 2 && (n || m)){int ans = 0;for(register int i = 0; i < n; ++i)sates[i].input();for(register int j = 0; j < m; ++j){target.input();for(register int i = 0; i < n; ++i){u = O - target;v = target - sates[i];if(u * v> 0.0){++ans;break;}}}printf("%d\n", ans);}}int main(){solve();return 0;}


0 0