首页 > ACM题库 > HDU-杭电 > HDU 4439- No place to hide[解题报告]HOJ
2015
07-16

HDU 4439- No place to hide[解题报告]HOJ

No place to hide

问题描述 :

It was in a dark daybreak. Dr. Gneh, who was a crazy scientist once trying to dominate the whole humankind by deploying a powerful AI network, had been discovered in a mansion on the grand field outside city of ACM. This time, he got no place to hide.
To help specify the capture operation, let’s assume the grand field had nothing else but the mansion on coordinate (Xm, Ym). N interpol elites had been assigned to N different positions around the mansion. The i-th interpol on initial position (Xi, Yi) could move at a maximum speed rate Vi m/s. It was said that Dr. Gneh had invent a rocket motorbike to escape this operation. According to our information, his ride could not change any direction, and ran at a maximum speed rate Vm m/s. For the human future, any failure in this operation was not acceptable. We had to make sure that Dr. Gneh would be captured no matter which way (a particular speed and direction) to flee. It was assumed that our interpols would take action from their positions immediately after Dr. Gneh left his hideout, and be informed of his flee direction at the same time.
Apparently, this was an interesting algorithm problem. Could you tell us whether this operation would be success by our given layout? If yes, what was the minimum number of interpols needed to achieve this success?

输入:

There are multiple test cases.
The first line contains a number T (1 ≤ T ≤ 100) indicating the number of test cases.
In each test case, there is an integer N (1 ≤ N ≤ 1000) indicating the number of interpols on the first line.
In the following N+1 lines, describe the specification of Dr. Gneh and our N interpols, and the first line for Dr. Gneh and the next N lines for interpols.
On each line, three float numbers (range [-1e5, 1e5]) represent the speed rate in m/s(which is none negative), x and y coordinate in meters.

输出:

There are multiple test cases.
The first line contains a number T (1 ≤ T ≤ 100) indicating the number of test cases.
In each test case, there is an integer N (1 ≤ N ≤ 1000) indicating the number of interpols on the first line.
In the following N+1 lines, describe the specification of Dr. Gneh and our N interpols, and the first line for Dr. Gneh and the next N lines for interpols.
On each line, three float numbers (range [-1e5, 1e5]) represent the speed rate in m/s(which is none negative), x and y coordinate in meters.

样例输入:

2
4
1.0 0 0
1.0 1 0
1.0 0 1
1.0 -1 0
1.0 0 -1
4
2.0 0 0
1.0 1 0
1.0 0 1
1.0 -1 0
1.0 0 -1

样例输出:

2
0
Hint
If the distance between interpol and Dr. Gneh can be infinitely small, Dr. Gneh is considered to be captured.

/*
 * Author:  xioumu
 * Created Time:  2012/10/28 17:18:24
 * File Name: I.cpp
 * solve: I.cpp
 */
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<iostream>
#include<vector>
#include<queue>

using namespace std;
#define sz(v) ((int)(v).size())
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repf(i, a, b) for (int i = (a); i <= (b); ++i)
#define repd(i, a, b) for (int i = (a); i >= (b); --i)
#define clr(x) memset(x,0,sizeof(x))
#define clrs( x , y ) memset(x,y,sizeof(x))
#define out(x) printf(#x" %d\n", x)
#define sqr(x) ((x) * (x))
typedef long long lint;

const int maxint = -1u>>1;
const double esp = 1e-8;
const double PI = acos(-1.0);
const int MAXN = 1000 + 50;

int sgn(const double &x) {  return (x > esp) - (x < -esp); }

int T,N;

struct Point {
    double x,y,v;
    Point() {};
    Point(const double &_x,const double &_y,const double &_v) :
        x(_x),y(_y),v(_v) {};
    void input() {
        scanf("%lf%lf%lf",&v,&x,&y);
    }
}th,po[MAXN];

struct TEvent {
	double angf,angt;
	TEvent() {};
	TEvent(const double &_angf,const double &_angt) :
		angf(_angf),angt(_angt) {};
	bool operator < (const TEvent &A) const {
		return sgn(angf - A.angf) < 0;
	}
}ev[MAXN * 2];

int main(){
    scanf("%d",&T);
    while(scanf("%d",&N) == 1) {
        th.input();
        for(int i = 0 ; i < N ; i++) {
            po[i].input();
        }
        for(int i = 0 ; i < N ; i++) {
			if (sgn(po[i].x - th.x) == 0 && sgn(po[i].y - th.y) == 0) {
				ev[i] = TEvent(-PI,PI);
				continue;
			}
			if (sgn(th.v) == 0) {
				ev[i] = TEvent(0,0);
				continue;
			}
            double d = po[i].v / th.v;
            if (sgn(d - 1.0) > 0) {
				ev[i] = TEvent(-PI,PI);
				continue;
			}
            double ang = atan2(po[i].y - th.y,po[i].x - th.x);
            double del = asin(d);
			ev[i] = TEvent(ang - del,ang + del);
        }
        sort(ev , ev + N);
		//for(int i = 0 ; i < N ; i++) {
			//printf("%lf %lf\n",ev[i].angf,ev[i].angt);
		//}
        for(int i = 0 ; i < N ; i++) {
            ev[i + N] = ev[i];
        }

        int res = maxint;
        
		for(int i = 0 ; i < N ; i++) {
			int ans = 1;
			double needCover = ev[i].angf + 2 * PI;
			double havCover = ev[i].angt;
			//printf("%lf %lf\n",needCover,havCover);
			int j = i + 1;
			if (sgn(havCover - needCover) >= 0) {
				res = min(res,ans);
				break;
			}
			while(j < i + N) {
				if (sgn(havCover - ev[j].angf) >= 0) {
					double willCover = ev[j].angt;
					while(j < i + N && sgn(havCover - ev[j].angf) >= 0) {
						willCover = max(willCover,ev[j].angt);
						j++;
					}
					ans++;
					havCover = willCover;
				}
				else {
					//printf("--%d %d %lf %d\n",i,j,havCover,ans);
					break;
				}
				if (sgn(havCover - needCover) >= 0) {
					res = min(res,ans);
					break;
				}
			}
		}
        printf("%d\n",res == maxint ? 0 : res);
    }
}