Hdu_4170 Supply Mission (Computational ry)

Source: Internet
Author: User

Question:
The aircraft is in the position (x0, y0), the flight speed is v km/h, there are N (0 <N <8) ships are (xi, yi) the velocity vector is (vxi, vyi) km/h, and the coordinate unit is km.
The plane must unload the cargo for one hour on each ship, and finally fly back to the original location (x0, y0). The minimum time is required and the time is output in minutes and seconds.
Ideas:
After thinking about it for a while, I have no idea. I looked at the data range. N is the maximum 8, and the time limit is 10 seconds. It can be completely violent.
Directly arrange the order of arrival to the ship, and take the minimum time. Be careful when calculating the encounter.
There is also a small trick, which is equal to 60 after the second is carried. It's been a long time for me here...
[Cpp]
/*
Program: hdu_4170 & hunnu_000015
Author: BlackAndWhite
*/
# Include <stdio. h>
# Include <math. h>
# Include <algorithm>
# Define eps 1e-6
Using namespace std;
Struct point
{
Int x, y;
} A [10], v [10], s;
Double t, ans;
Int N, sv, I, p [10], T [3], js = 1;
Double crosstime (double x0, double y0, double v0, double x1, double y1, double vx, double vy)
{// It indicates the time when the plane is in (x0, y0) and the speed is v0. The time it takes to meet the velocity vector of the ship (x1, y1) is (vx, vy.
Double a, B, c, t;
A = vx * vx + vy * vy-v0 * v0;
B = 2 * (vx * (x1-x0) + vy * (y1-y0 ));
C = (x1-x0) * (x1-x0) + (y1-y0) * (y1-y0 );
If (a <eps & a>-eps) return-c/B;
If (a <eps) {a =-a; B =-B; c =-c ;}
Return (-B + sqrt (B * B-4 * a * c)/(2 * );
}
Double back (double x0, double y0, double x1, double y1, double sv) // time spent returning to the start point
{
Return sqrt (x1-x0) * (x1-x0) + (y1-y0) * (y1-y0)/sv;
}
Void trs (double ans, int T [3]) // converts decimal form to hour/minute/second
{
T [0] = (int) ans;
Ans-= T [0];
T [1] = (int) (ans * = 60.0); ans-= T [1];
T [2] = (int) (ans x 60.0 + 0.9999999 );
If (T [2] = 60) {T [2] = 0; T [1] ++;} // trick, carry...
If (T [1] = 60) {T [1] = 0; T [0] ++ ;}
}
Int main ()
{
While (scanf ("% d", & N), N)
{
For (I = 0; I <N; I ++) scanf ("% d", & a [I]. x, & a [I]. y, & v [I]. x, & v [I]. y );
Scanf ("% d", & s. x, & s. y, & sv );
For (I = 0; I <= N; I ++) p [I] = I;
Ans = 1e9;
Do
{
T = crosstime (s. x * 1.0, s. y * 1.0, sv * 1.0, a [p [0]. x, a [p [0]. y, v [p [0]. x, v [p [0]. y) + 1.0;
For (I = 1; I <N; I ++) // The current departure moment on the p [I-1] ship is ready, p [I-1] has been traveling t hours, p [I] the same t hour
T + = 1.0 + crosstime (a [p [I-1]. x * 1.0 + t * v [p [I-1]. x, a [p [I-1]. y * 1.0 + t * v [p [I-1]. y, sv * 1.0, a [p [I]. x * 1.0 + t * v [p [I]. x, a [p [I]. y * 1.0 + t * v [p [I]. y, v [p [I]. x * 1.0, v [p [I]. y * 1.0 );
T + = back (a [p [N-1]. x * 1.0 + t * v [p [N-1]. x, a [p [N-1]. y * 1.0 + t * v [p [N-1]. y, s. x, s. y, sv );
If (t <ans) ans = t;
}
While (next_permutation (p, p + N ));
Trs (ans, T );
Printf ("Case % d: % d hour (s) % d minute (s) % d second (s) \ n", js ++, T [0], T [1], T [2]);
}
Return 0;
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.