【UVALive】2145 - Lost in Space(数学)
2016-07-20 16:32
555 查看
点击打开题目
Time limit: 3.000 seconds
William Robinson was completely puzzled in the music room; he could not find his triangle in his bag. He was sure that he had prepared it the night before. He remembered its clank when he had stepped on the school
bus early that morning. No, not in his dream. His triangle was quite unique:no two sides had the same length, which made his favorite peculiar jingle. He insisted to the music teacher, Mr. Smith, that his triangle had probably been stolen by those aliens and
thrown away into deep space.
Your mission is to help Will find his triangle in space. His triangle has been made invisible by the aliens, but candidate positions of its vertices are somehow known. You have to tell which three of them make his
triangle. Having gone through worm-holes, the triangle may have changed its size. However, even in that case, all the sides are known to be enlarged or shrunk equally, that is, the transformed triangle is similar to the original.
The first line of each data set contains three decimals that give lengths of the sides of the original triangle, measured in centimeters. Three vertices of the original triangle are named P, Q, and R. Three decimals
given in the first line correspond to the lengths of sides QR, RP, and PQ, in this order. They are separated by one or more space characters.
The second line of a data set has an integer which is the number of points in space to be considered as candidates for vertices. At least three and at most thirty points are considered.
The rest of the data set are lines containing coordinates of candidate points, in light years. Each line has three decimals, corresponding to x, y, and z coordinates, separated by one or more space characters. Points
are numbered in the order of their appearances, starting from one.
Among all the triangles formed by three of the given points, only one of them is similar to the original, that is, ratios of the lengths of any two sides are equal to the corresponding ratios of the original allowing
an error of less than 0.01 percent. Other triangles have some of the ratios different from the original by at least 0.1 percent.
The origin of the coordinate system is not the center of the earth but the center of our galaxy. Note that negative coordinate values may appear here. As they are all within or close to our galaxy, coordinate values
are less than one hundred thousand light years. You don't have to take relativistic effects into account, i.e., you may assume that we are in a Euclidean space. You may also assume in your calculation that one light year is equal to 9.461 x 1012kilometers.
A succeeding data set, if any, starts from the line immediately following the last line of the preceding data set.
and then R.
纯属是数学题,先计算出两两点之间的距离,然后按照相似三角形的公式暴力跑出来就行了,n最大只有30。
代码如下:
#include <cstdio>
#include <cmath>
struct node
{
double x,y,z; //三边
}data[33];
double cal(node a,node b)
{
double l;
l = sqrt(pow(a.x - b.x , 2) + pow(a.y - b.y , 2) + pow(a.z - b.z , 2));
return l;
}
double abs(double a)
{
return (a < 0 ? -a : a);
}
int main()
{
int u;
double A,B,C;
double dis[33][33];
int n;
scanf ("%d",&u);
while (u--)
{
scanf ("%lf %lf %lf",&A,&B,&C);
scanf ("%d",&n);
for (int i = 1 ; i <= n ; i++)
scanf ("%lf %lf %lf",&data[i].x,&data[i].y,&data[i].z);
for (int i = 1 ; i < n ; i++)
for (int j = i + 1 ; j <= n ; j++)
dis[i][j] = dis[j][i] = cal(data[i],data[j]);
bool ans = false;
int ans_x,ans_y,ans_z;
for (int i = 1 ; i <= n ; i++)
{
for (int j = 1 ; j <= n ; j++)
{
if (j == i)
continue;
for (int k = 1 ; k <= n ; k++)
{
if (k == i || k == j)
continue;
if (abs(A/B - dis[j][k]/dis[i][k]) <= 0.0001 && abs(A/C - dis[j][k]/dis[i][j]) <= 0.001)
{
ans = true;
ans_x = i;
ans_y = j;
ans_z = k;
break;
}
}
if (ans)
break;
}
if (ans)
break;
}
printf ("%d %d %d\n",ans_x,ans_y,ans_z);
}
return 0;
}
2145 - Lost in Space
Time limit: 3.000 secondsWilliam Robinson was completely puzzled in the music room; he could not find his triangle in his bag. He was sure that he had prepared it the night before. He remembered its clank when he had stepped on the school
bus early that morning. No, not in his dream. His triangle was quite unique:no two sides had the same length, which made his favorite peculiar jingle. He insisted to the music teacher, Mr. Smith, that his triangle had probably been stolen by those aliens and
thrown away into deep space.
Your mission is to help Will find his triangle in space. His triangle has been made invisible by the aliens, but candidate positions of its vertices are somehow known. You have to tell which three of them make his
triangle. Having gone through worm-holes, the triangle may have changed its size. However, even in that case, all the sides are known to be enlarged or shrunk equally, that is, the transformed triangle is similar to the original.
Input
The very first line of the input has an integer which is the number of data sets. Each data set gives data for one incident such as that of Will's.The first line of each data set contains three decimals that give lengths of the sides of the original triangle, measured in centimeters. Three vertices of the original triangle are named P, Q, and R. Three decimals
given in the first line correspond to the lengths of sides QR, RP, and PQ, in this order. They are separated by one or more space characters.
The second line of a data set has an integer which is the number of points in space to be considered as candidates for vertices. At least three and at most thirty points are considered.
The rest of the data set are lines containing coordinates of candidate points, in light years. Each line has three decimals, corresponding to x, y, and z coordinates, separated by one or more space characters. Points
are numbered in the order of their appearances, starting from one.
Among all the triangles formed by three of the given points, only one of them is similar to the original, that is, ratios of the lengths of any two sides are equal to the corresponding ratios of the original allowing
an error of less than 0.01 percent. Other triangles have some of the ratios different from the original by at least 0.1 percent.
The origin of the coordinate system is not the center of the earth but the center of our galaxy. Note that negative coordinate values may appear here. As they are all within or close to our galaxy, coordinate values
are less than one hundred thousand light years. You don't have to take relativistic effects into account, i.e., you may assume that we are in a Euclidean space. You may also assume in your calculation that one light year is equal to 9.461 x 1012kilometers.
A succeeding data set, if any, starts from the line immediately following the last line of the preceding data set.
Output
For each data set, one line should be output. That line should contain the point numbers of the three vertices of the similar triangle, separated by a space character. They should be reported in the order P, Q,and then R.
Sample Input
2 50.36493 81.61338 79.96592 5 -10293.83 -4800.033 -5296.238 14936.30 6964.826 7684.818 -4516.069 25748.41 -27016.06 18301.59 -11946.25 5380.309 27115.20 43415.93 -71607.81 11.51547 13.35555 14.57307 5 -56292.27 2583.892 67754.62 -567.5082 -756.2763 -118.7268 -1235.987 -213.3318 -216.4862 -317.6108 -54.81976 -55.63033 22505.44 -40752.88 27482.94
Sample Output
1 2 4 3 4 2
纯属是数学题,先计算出两两点之间的距离,然后按照相似三角形的公式暴力跑出来就行了,n最大只有30。
代码如下:
#include <cstdio>
#include <cmath>
struct node
{
double x,y,z; //三边
}data[33];
double cal(node a,node b)
{
double l;
l = sqrt(pow(a.x - b.x , 2) + pow(a.y - b.y , 2) + pow(a.z - b.z , 2));
return l;
}
double abs(double a)
{
return (a < 0 ? -a : a);
}
int main()
{
int u;
double A,B,C;
double dis[33][33];
int n;
scanf ("%d",&u);
while (u--)
{
scanf ("%lf %lf %lf",&A,&B,&C);
scanf ("%d",&n);
for (int i = 1 ; i <= n ; i++)
scanf ("%lf %lf %lf",&data[i].x,&data[i].y,&data[i].z);
for (int i = 1 ; i < n ; i++)
for (int j = i + 1 ; j <= n ; j++)
dis[i][j] = dis[j][i] = cal(data[i],data[j]);
bool ans = false;
int ans_x,ans_y,ans_z;
for (int i = 1 ; i <= n ; i++)
{
for (int j = 1 ; j <= n ; j++)
{
if (j == i)
continue;
for (int k = 1 ; k <= n ; k++)
{
if (k == i || k == j)
continue;
if (abs(A/B - dis[j][k]/dis[i][k]) <= 0.0001 && abs(A/C - dis[j][k]/dis[i][j]) <= 0.001)
{
ans = true;
ans_x = i;
ans_y = j;
ans_z = k;
break;
}
}
if (ans)
break;
}
if (ans)
break;
}
printf ("%d %d %d\n",ans_x,ans_y,ans_z);
}
return 0;
}
相关文章推荐
- Maven 项目生成jar运行时提示“没有主清单属性”
- Android 图片比较
- 如何在Excel中通过VBA快速查找多列重复的值
- 26 c#类的组合
- 盗梦空间
- DNS学习笔记
- 网站性能优化大集合
- HTML5 canvas贝塞尔曲线_图解贝塞尔
- POJ-1067 取石子游戏(威佐夫博弈)
- HDOJ 1106 排序
- @synthesize myObject=_myObject的理解
- Android TagFlowLayout完全解析 一款针对Tag的布局(针对多个条目的单选操作)
- javascript获取frameset中各个模块中的数据
- windows server 2008 R2系统使用了正确的用户名和密码,却不能正常登录远程桌面
- 编译期注解框架浅析
- 关于去除easy ui 的input textarea 等输入框点击有蓝色框框
- 围住神经猫(2)
- Sql server DATEADD日期函数的使用
- Java静态代码块
- 用jQuery实现瀑布流效果学习笔记