站点图标 陌路寒暄

Problem E - Paintball

Problem E - Paintball

时间: 1ms        内存:128M

描述:

Problem E - Paintball

You are playing paintball on a 1000x1000 square field. A number of your opponents are on the field hiding behind trees at various positions. Each opponent can fire a paintball a certain distance in any direction. Can you cross the field without being hit by a paintball?

Assume that the southwest corner of the field is at (0,0) and the northwest corner at (0,1000). The input consists of a line containing n <= 1000, the number of opponents. A line follows for each opponent, containing three real numbers: the (x,y) location of the opponent and its firing range. The opponent can hit you with a paintball if you ever pass within his firing range.

You must enter the field somewhere between the southwest and northwest corner and must leave somewhere between the southeast and northeast corners.

If you can complete the trip, output four real numbers with two digits after the decimal place, the coordinates at which you may enter and leave the field, separated by spaces. If you can enter and leave at several places, give the most northerly. If there is no such pair of positions, print the line:
IMPOSSIBLE

输入:

输出:

示例输入:

3
500 500 499
0 0 999
1000 1000 200

示例输出:

0.00 1000.00 1000.00 800.00

提示:

参考答案(内存最优[788]):

#include <stdio.h>
#include <math.h>

int n;
double x[1000], y[1000], r[1000];
int top[1000];

int possible = 1;
double ne = 1000, nw = 1000;

main(){
   int i,j,k;
   scanf("%d",&n);
   for (i=0;i<n;i++) scanf("%lf%lf%lf",&x[i],&y[i],&r[i]);
   for (i=0;i<n;i++) if (y[i]+r[i] > 1000) visit(i);
   /*
   if (possible) printf(
     "Bill enters at (0.00, %0.2lf) and leaves at (1000.00, %0.2lf).\n",nw,ne);
   else printf("Bill will be bitten.\n");
   */
   if (possible) printf(
     "0.00 %0.2lf 1000.00 %0.2lf\n",nw,ne);
   else printf("IMPOSSIBLE\n");
}

visit(int i){
   int j,k;
   double yy;
   if (top[i]++) return;

   for (j=0;j<n;j++) {
      if (hypot(x[j]-x[i],y[j]-y[i]) < r[i]+r[j]) visit(j);
   }
   if (y[i]-r[i] < 0) possible = 0;
   if (x[i]-r[i] < 0) {
      yy = y[i] - sqrt(r[i]*r[i] - x[i]*x[i]);
      if (yy < nw) nw = yy;
   }
   if (x[i]+r[i] > 1000) {
      yy = y[i] - sqrt(r[i]*r[i] - (1000-x[i])*(1000-x[i]));
      if (yy < ne) ne = yy;
   }
}

参考答案(时间最优[8]):

#include <stdio.h>

#define ROUND 0
int cad[10000];
int usd[10000];

double rate[10000];

int initcad = 100000;
int initusd = 0;
double commission = .03;

double max(double a, double b, double c) {
    if(a>=b && a>=c) return a;
    if(b>=c) return b;
    return c;
}

main() {
    int n, i;
    while(1) {
    scanf("%d", &n);
    if(!n) break;
    for(i = 0; i < n; i++) {
        scanf("%lf", rate + i);
    }

    for(i = 0; i < n; i++) {
        cad[i+1] = max(initcad + initusd*rate[i]*(1-commission) + ROUND,
                cad[i], usd[i]*rate[i]*(1-commission) + ROUND);
        usd[i+1] = max(initusd + initcad/rate[i]*(1-commission) + ROUND,
                usd[i], cad[i]/rate[i]*(1-commission) + ROUND);
        //printf("%d %d\n", usd[i+1], cad[i+1]);
    }

    printf("%01d.%02d\n", cad[n]/100, cad[n]%100);
    }
}

题目和答案均来自于互联网,仅供参考,如有问题请联系管理员修改或删除。

退出移动版