2014
03-06

# Meltdown

A polygon is lowered at a constant speed of v metres per minute from the air into a liquid that dissolves it at a constant speed of c metres per minute from all sides. Given a point (x,y) inside the polygon that moves with the polygon, determine when the liquid reaches the point.

The border between air and liquid always has y-coordinate 0, and the liquid only eats away from the sides of the polygon in 2 dimensions. The polygon does not rotate as it is lowered into the liquid, and at time 0, it is not touching the liquid.

Unlike the polygon, which is flat (2-dimensional), the liquid exists in three dimensions. Therefore, the liquid seeps into cavities in the polygon. For example, if the polygon is "cup-shaped", the liquid can get "inside" the cup, as in the diagram below.

The input consists of several test cases.

The first line of each test case contains the five integers N, x, y, v, and c, where 3 <= N <= 30, -100 <= x <= 100, 1 <= y <= 100, and 1 <= c < v <= 10.

The following N lines of the test case each contain one vertex of the polygon. The ith line contains the two integers x, y, where -100 <= x <= 100, 1 <= y <= 100.

The vertices of the polygon are given in counter-clockwise order. The border of the polygon does not intersect or touch itself, and the point (x,y) lies strictly inside the polygon–it does not lie on the border of the polygon.

Input is terminated by a line containing 0 0 0 0 0. These zeros are not a test case and should not be processed.

The input consists of several test cases.

The first line of each test case contains the five integers N, x, y, v, and c, where 3 <= N <= 30, -100 <= x <= 100, 1 <= y <= 100, and 1 <= c < v <= 10.

The following N lines of the test case each contain one vertex of the polygon. The ith line contains the two integers x, y, where -100 <= x <= 100, 1 <= y <= 100.

The vertices of the polygon are given in counter-clockwise order. The border of the polygon does not intersect or touch itself, and the point (x,y) lies strictly inside the polygon–it does not lie on the border of the polygon.

Input is terminated by a line containing 0 0 0 0 0. These zeros are not a test case and should not be processed.

4 0 50 2 1
-1 10
1 10
1 90
-1 90
0 0 0 0 0

25.8660

#include <cstdio>
#include <cmath>
#include <cstdlib>
using namespace std;
template<class T> inline void checkmax(T &a, T b)
{if (b > a) a = b;}
template<class T> inline void checkmin(T &a, T b)
{if (b < a) a = b;}
inline double sqr(double x)
{return x * x;}
struct Point {
double x, y;
} pt[35];
int n;
double tx, ty, v, c, sx, sy, dx, dy;

double get(double p)
{
double cx = sx + dx * p;
double cy = sy + dy * p;
double cur = cy / v + sqrt(sqr(cx - tx) + sqr(cy - ty)) / c;
return cur;
}

int ansidx;
double ansp;
void work()
{
for (int i = 1; i <= n; ++i) scanf("%lf%lf", &pt[i].x, &pt[i].y);
pt[n + 1] = pt[1];
double ans = 1e9;
for (int i = 1; i <= n; ++i) {
dx = pt[i + 1].x - pt[i].x;
dy = pt[i + 1].y - pt[i].y;
sx = pt[i].x;
sy = pt[i].y;
for (int iter = 1; iter <= 35; ++iter) {
double p = 0;
for (double len = 1; len > 1e-9; len /= 1.5) for (int iter1 = 1; iter1 <= 35; ++iter1) {
if (rand() & 1) p += len; else p -= len;
checkmax(p, 0.0);
checkmin(p, 1.0);
double tmp = get(p);
if (tmp < ans) {
ans = tmp;
ansidx = i;
ansp = p;
}
}
}
}
double trueans = ans;
ansp -= 5000 * 1e-7;
for (int i = 0; i < 10000; ++i, ansp += 1e-7) {
dx = pt[ansidx + 1].x - pt[ansidx].x;
dy = pt[ansidx + 1].y - pt[ansidx].y;
sx = pt[ansidx].x;
sy = pt[ansidx].y;
if (ansp > -1e-7 && ansp < 1 + 1e-7) checkmin(trueans, get(ansp));
}
printf("%0.4lf\n", trueans);
}

int main()
{
while (scanf("%d%lf%lf%lf%lf", &n, &tx, &ty, &v, &c), n) work();
}

1. 为什么for循环找到的i一定是素数叻，而且约数定理说的是n=p1^a1*p2^a2*p3^a3*…*pk^ak，而你每次取余都用的是原来的m，也就是n