ACM-Easy Problem-Where is wrong?
来源:互联网 发布:淘宝客云建站 编辑:程序博客网 时间:2024/06/15 17:23
Time limit:1000ms Memory limit:65536 KB
Total Submit:1760(464 users) Accepted Submit:367 (333users)
Description
In this problem,you're to calculate the distance between a point P(xp, yp, zp) and a segment(x1, y1, z1) ? (x2, y2, z2), in a 3D space, i.e. the minimal distance from P toany point Q(xq, yq, zq) on the segment (a segment is part of a line).
Input
The first linecontains a single integer T (1 ≤ T ≤ 1000), the number of test cases. Each testcase is a single line containing 9 integers xp, yp, zp, x1, y1, z1, x2, y2, z2.These integers are all in [-1000,1000].
Output
For each test case,print the case number and the minimal distance, to two decimal places.
Sample Input
3
0 0 0 0 1 0 1 1 0
1 0 0 1 0 1 1 1 0
-1 -1 -1 0 1 0 -1 0-1
Sample Output
Case 1: 1.00
Case 2: 0.71
Case 3: 1.00
Problem Source
The 32nd ACM-ICPC
This is the requestfor one of the five test questions of ACM (Association of Computing Machinery,simply called ACM: 美国计算机协会) International Collegiate Programming Contest(ACM-ICPC or ICPC: ACM国际大学生程序设计竞赛) which Itook part in last year (2007). And Ianswered this problem as followed:
#include<stdio.h>
#include<math.h>
int main()
{
int x0,y0,z0;
int x1,y1,z1;
int x2,y2,z2;
float a,b,c,d,p,s;
int i = 0, j = 0;
int n;
scanf("%d",&n);
float distant[100];
if (n > 0 && n < 1000)
{
for (i = 0; i < n; i++)
{
scanf("%d%d%d%d%d%d%d%d%d",&x0,&y0,&z0,&x1,&y1,&z1,&x2,&y2,&z2);
a = sqrt((x0 - x1) * (x0 -x1) + (y0 - y1) * (y0 - y1) + (z0 - z1) * (z0 - z1));
b = sqrt((x0 - x2) * (x0 -x2) + (y0 - y2) * (y0 - y2) + (z0 - z2) * (z0 - z2));
c = sqrt((x2 - x1) * (x2 -x1) + (y2 - y1) * (y2 - y1) + (z2 - z1) * (z2 - z1));
p = (a + b + c ) / 2;
s = sqrt(p * (p - a) * (p -b) * (p - c));
d = (2 * s) / c;
if (a * a + c * c < b *b || b * b + c * c < a * a || abs(a - b) == c)
{
if (a > b)
distant[i] =b;
else
distant[i] =a;
}
else
{
distant[i] = d;
}
}
for (j = 0; j < n; j++)
{
printf("Case %d: %
}
}
return 0;
}
But at last, I didn’tknow why this part of code wasn’t been received by the ACM-ICPC server. I justwant to know why. This method had made me thinking too long times. The time andmemory used by this code when it running has not out of its limits, and theinput parameters & the output results are all right too – as the same asthe example has been given. I think there was no problem for that kind of algorithm.
Then I had finishedtwo of the five questions between the period of the exam, and what made me feelglade is that I thought the way to solve this problem.
My written Englishis not well, so if any where of this topic has some error in grammar of words,please give me a tip and I’ll improve my English writing.
- ACM-Easy Problem-Where is wrong?
- acm-A problem is easy
- ACM 数论 A problem is easy
- ACM 中wrong answer(WA)的一种处理办法 UVA10474 where is the marble
- 南阳理工ACM 题目216 A problem is easy
- A problem is easy
- A problem is easy
- A problem is easy
- A problem is easy
- A problem is easy
- A problem is easy
- A problem is easy
- A problem is easy
- NYOJ - A problem is easy
- NYOJ - A problem is easy
- NYOJ a problem is easy
- NYOJ216 A problem is easy
- 216 A problem is easy
- 某A的工口游戏创作者体验记(下)
- 网络字节序与主机字节序
- MD5算法研究
- java中判断socket网络远端是否断开连接
- MD5加密(2)
- ACM-Easy Problem-Where is wrong?
- C++ 运算符优先级列表
- 深析C++析构函数
- 用C++编写strcpy函数
- 安装 SQL Server 2005 的硬件和软件要求
- C/C++编译的程序占用的内存
- 学计算机学生的困惑
- 一个程序员的奋斗历程——来自百度贴吧《程序员》
- 3Q