简单OJ题目,为何WA?分不多,仍请各位赐教!

来源:百度知道 编辑:UC知道 时间:2024/05/30 06:01:02
题目:
The Center of Gravity
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1209 Accepted Submission(s): 615

Problem Description
Everyone know the story that how Newton discovered the Universal Gravitation. One day, Newton walked
leisurely, suddenly, an apple hit his head. Then Newton discovered the Universal Gravitation.From then
on,people have sovled many problems by the the theory of the Universal Gravitation. What's more, wo also
have known every object has its Center of Gravity.
Now,you have been given the coordinates of three points of a triangle. Can you calculate the center
of gravity of the triangle?

Input
The first line is an integer n,which is the number of test cases.
Then n lines follow. Each line has 6 numbers x1,y1,x2,y2,x3,y3,which are the coordinates of three points.
The input is terminated by n = 0.

Output
Fo

给个原题链接吧,否则我也没法测试。

我的一个猜想是:
既然题目说n=0表示输入终止,那么是否意味着如下输入是合法的:

2
1.0 2.0 3.0 4.0 5.0 2.0
1.0 1.0 4.0 1.0 1.0 5.0
3
1.0 2.0 3.0 4.0 5.0 2.0
1.0 1.0 4.0 1.0 1.0 5.0
1.0 1.0 1.0 1.0 1.0 1.0
0

前三行n=2,然后两行是坐标;
4至7行输入中,n=3,接下来三行坐标;
第八行n=0,输入终止。

PS:
感觉你的if(n==0) goto loop;多余了
还有,baidu上做ACM的貌似不多,这个一般还是去专业的论坛问吧

三角形重心计算公式会不会的额。。。
#include<iostream>
using namespace std;
int main()
{
double x1,y1,x2,y2,x3,y3;
int n;
while(scanf("%d",&n)!=EOF&&n)
{
for(int i=0;i<n;i++)
{
scanf("%lf%lf%lf%lf%lf%lf",&x1,&y1,&x2,&y2,&x3,&y3);
double ans_x=(x1+x2)/2,ans_y=(y1+y2)/2;
ans_x+=(x3-ans_x)/3,ans_y+=(y3-ans_y)/3;
printf("%.1lf %.1lf\n",ans_x,ans_y);
}
}
}