Point of view in Flatland

Point of view in Flatland

时间: 5ms        内存:128M

描述:

Everything is flat in Flatland. The planets are round but they are flat, that is, they are discs in a plane.

The centers of three planets in Flatland are given and their radii. Find the point in Flatland from which all three planets are visible at the same angle, that is, they appear to have the same size measured as angular diameter. Let's call such a point an isoobservation point. There can be at most two such points and we are interested in finding the one that gives the largest angular diameter of the planets.

Input consists of several cases, each case is presented at a single line. Each line has nine numbers, three for each disc. Each triple has x and y coordinates of the disc center and the radius r of that disc. The input is terminated by a line with nine zeros and this line should not be processed.

For each case of input, print the x and y coordinates of the isoobservation point as described above in the format shown in the sample; but if there is no such point, print   No solution

To simplify the problem you may assume that:

  • The discs centers are not all collinear.
  • The discs are totally disjoint.
  • The discs are transparent and non-refractive. That is, a disc is visible and has the same apparent shape and size, whether or not there's another disc in front of it.
  • The input data are such that the existence or non-existence of such a point is computable, even with slight rounding error. But use double-precision, eh?

输入:

输出:

示例输入:

10 10 1 30 30 1 50 10 1
0 30 1.0 30 0 1.0 40 40 1.0
10 30 1.0 31 0 1.0 42 43 1.0
10 42 1 62.8 62.8 1 52.5 -25.3 1
10 42 1.1 62.8 62.8 1.2 52.5 25.3 25
0 0 0 0 0 0 0 0 0

示例输出:

30.00 10.00
23.00 23.00
31.58 22.76
49.27 19.73
No solution

提示:

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

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

unsigned countl(char *s){
   unsigned r;
   if (strlen(s) == 1) return 1;
   if (s[0] == '0') {
      sscanf(s+1,"%lu",&r);
      return 1 + r + countl(s+1);
   }
   r = pow(10,strlen(s+1));
   r += (s[0]-'0') * strlen(s+1) * pow(10,strlen(s+1)-1);
   r += countl(s+1);
   return r;
}

unsigned count(char *s){
   unsigned r = 1; char tmp[20];
   if (strlen(s) == 1) return 1;
   for (r=0;r<strlen(s)-1;r++) tmp[r] = '9';
   tmp[r] = 0;
   r = count(tmp);
   r += (s[0]-'1') * strlen(s+1) * pow(10,strlen(s+1)-1);
   r += countl(s+1);
   return r;
}

char x[100], y[100];
unsigned u;

main(){
   while (2 == scanf("%s%s",x,y) && x[0] != '-') {
      if (x[0] == '0') printf("%lu\n",count(y));
      else {
         sscanf(x,"%lu",&u);
         sprintf(x,"%lu",u-1);
         printf("%lu\n",count(y)-count(x));
      }
   }
}

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

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

unsigned countl(char *s){
   unsigned r;
   if (strlen(s) == 1) return 1;
   if (s[0] == '0') {
      sscanf(s+1,"%lu",&r);
      return 1 + r + countl(s+1);
   }
   r = pow(10,strlen(s+1));
   r += (s[0]-'0') * strlen(s+1) * pow(10,strlen(s+1)-1);
   r += countl(s+1);
   return r;
}

unsigned count(char *s){
   unsigned r = 1; char tmp[20];
   if (strlen(s) == 1) return 1;
   for (r=0;r<strlen(s)-1;r++) tmp[r] = '9';
   tmp[r] = 0;
   r = count(tmp);
   r += (s[0]-'1') * strlen(s+1) * pow(10,strlen(s+1)-1);
   r += countl(s+1);
   return r;
}

char x[100], y[100];
unsigned u;

main(){
   while (2 == scanf("%s%s",x,y) && x[0] != '-') {
      if (x[0] == '0') printf("%lu\n",count(y));
      else {
         sscanf(x,"%lu",&u);
         sprintf(x,"%lu",u-1);
         printf("%lu\n",count(y)-count(x));
      }
   }
}

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

点赞

发表评论

电子邮件地址不会被公开。必填项已用 * 标注