The Center of Gravity

Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 3971    Accepted Submission(s): 2280

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
For each case, print the coordinate, accurate up to 1 decimal places.
 
Sample Input
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
0
 
Sample Output
3.0 2.7
2.0 2.3
 
Source
 
Recommend
xhd   |   We have carefully selected several similar problems for you:  2101 2100 2103 2106 2102 

 
  计算几何,求三角形重心
  方法一(麻烦):先求两条边的中点,然后分别将中点与他们相对的顶点相连做直线,交点就是三角形重心。
  方法二(so easy):直接用重心公式求得。重心(x,y)==> x=(x1+x2+x3)/3 ;  y=(y1+y2+y3)/3 。
  重心的性质
    1、到三角形三顶点距离的平方和最小的点(距离的和最小的点是费马点)。
    2、三角形内到三角形三边距离之积最大的点。
  代码一
 #include <iostream>
#include <stdio.h>
using namespace std;
/********** 定义点 **********/
struct Point{
double x,y;
Point(double x=,double y=):x(x),y(y) {}
};
/********** 定义向量 **********/
typedef Point Vector; /********** 向量 + 向量 = 向量 **********/
Vector operator + (Vector a,Vector b)
{
return Vector(a.x+b.x,a.y+b.y);
}
/********** 点 - 点 = 向量 **********/
Vector operator - (Point a,Point b)
{
return Vector(a.x-b.x,a.y-b.y);
}
/********** 向量 * 数 = 向量 **********/
Vector operator * (Vector a,double b)
{
return Vector(a.x*b,a.y*b);
}
/********** 向量 / 数 = 向量 **********/
Vector operator / (Vector a,double b)
{
return Vector(a.x/b,a.y/b);
}
/********** 向量点积 **********/
double Dot(Vector a,Vector b)
{
return a.x*b.x+a.y*b.y;
}
/********** 2向量求叉积 **********/
double Cross(Vector a,Vector b)
{
return a.x*b.y-b.x*a.y;
}
/********** 3点求叉积 **********/
double Cross(Point a,Point b,Point c)
{
return (c.x-a.x)*(b.y-a.y) - (c.y-a.y)*(b.x-a.x);
}
Point GetLineIntersection(Point P,Vector v,Point Q,Vector w) //求射线交点
{
Vector u = P-Q;
double t = Cross(w,u) / Cross(v,w);
return P+v*t;
}
Point GetGravity(Point p[]) //求三角形重心
{
Vector v,w;
Point c1,c2;
c1.x = (p[].x+p[].x)/;
c1.y = (p[].y+p[].y)/;
c2.x = (p[].x+p[].x)/;
c2.y = (p[].y+p[].y)/;
v = c1-p[];
w = c2-p[];
return GetLineIntersection(p[],v,p[],w);
}
int main()
{
int n;
while(cin>>n){
if(n==) break;
for(int i=;i<n;i++){ //输入
Point p[];
cin>>p[].x>>p[].y;
cin>>p[].x>>p[].y;
cin>>p[].x>>p[].y;
Point r = GetGravity(p);
printf("%.1lf %.1lf\n",r.x,r.y);
}
}
return ;
}

  代码二

 #include <stdio.h>
typedef struct {
double x,y;
}Point;
int main()
{
int n;
while(scanf("%d",&n)!=EOF){
if(n==) break;
while(n--){
Point a,b,c;
scanf("%lf%lf%lf%lf%lf%lf",&a.x,&a.y,&b.x,&b.y,&c.x,&c.y);
Point z;
z.x = (a.x+b.x+c.x)/;
z.y = (a.y+b.y+c.y)/;
printf("%.1lf %.1lf\n",z.x,z.y);
}
}
return ;
}

Freecode : www.cnblogs.com/yym2013

hdu 2105:The Center of Gravity(计算几何,求三角形重心)的更多相关文章

  1. HDU 2105 The Center of Gravity

    http://acm.hdu.edu.cn/showproblem.php?pid=2105 Problem Description Everyone know the story that how ...

  2. HDU 2105 The Center of Gravity (数学)

    题目链接 Problem Description Everyone know the story that how Newton discovered the Universal Gravitatio ...

  3. POJ 2225 / ZOJ 1438 / UVA 1438 Asteroids --三维凸包,求多面体重心

    题意: 两个凸多面体,可以任意摆放,最多贴着,问他们重心的最短距离. 解法: 由于给出的是凸多面体,先构出两个三维凸包,再求其重心,求重心仿照求三角形重心的方式,然后再求两个多面体的重心到每个多面体的 ...

  4. fzu 1330:Center of Gravity(计算几何,求扇形重心)

    Problem 1330 Center of Gravity Accept: 443    Submit: 830Time Limit: 1000 mSec    Memory Limit : 327 ...

  5. hdu 1115:Lifting the Stone(计算几何,求多边形重心。 过年好!)

    Lifting the Stone Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others ...

  6. HDU 5572 An Easy Physics Problem (计算几何+对称点模板)

    HDU 5572 An Easy Physics Problem (计算几何) 题目链接http://acm.hdu.edu.cn/showproblem.php?pid=5572 Descripti ...

  7. hdu 4709:Herding(叉积求三角形面积+枚举)

    Herding Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Sub ...

  8. UVa 11437:Triangle Fun(计算几何综合应用,求直线交点,向量运算,求三角形面积)

    Problem ATriangle Fun Input: Standard Input Output: Standard Output In the picture below you can see ...

  9. hdu 2105

    #include <iostream> #include <stdio.h> using namespace std; int main() { double a,b,c,d, ...

随机推荐

  1. STDIN_FILENO vs stdin

    数据类型不一致:stdin类型为 FILE*STDIN_FILENO类型为 int 使用stdin的函数主要有:fread.fwrite.fclose等,基本上都以f开头使用STDIN_FILENO的 ...

  2. 【Redis】redis+php处理高并发,很好的教程||附上 php的文件锁

    链接至:http://blog.csdn.net/nuli888/article/details/51865401 很好的教程,其中redis+php有点小问题. 附上php文件锁: $fp = fo ...

  3. 那些最好的轮子 - PHP篇

    转载于:http://avnpc.com/pages/best-wheels-for-php 在关于不要重复造轮子的二三事一文中,交代了一些背景和想法.本篇则完全是一些干货,列举一些我用过或者即将会用 ...

  4. oracle和其他数据库对表名、列名的长度限制

    ============== 数据库 表名列名长度限制问题 今天修改数据库表名,感觉现有的定义列名都无含义...修改后被同事告知,列名有点长,怕有的数据库不支持.. 我头一次听说数据库表名和列名长度限 ...

  5. 【服务器防护】centos iptables 防火墙设置 mac过滤

    1.阻止MAC地址为XX:XX:XX:XX:XX:XX主机的所有通信: iptables -A INPUT -s 192.168.1.21 -m mac --mac-source XX:XX:XX:X ...

  6. 字符串函数---itoa()函数具体解释及实现

    itoa()函数 itoa():char *itoa( int value, char *string,int radix); 原型说明: value:欲转换的数据. string:目标字符串的地址. ...

  7. git配置文件读取顺序

    作者:zhanhailiang 日期:2014-11-03 git包括三个配置文件: /etc/gitconfig 文件:系统中对全部用户都普遍适用的配置. 若使用git config 时用' –sy ...

  8. vim的窗口切换

    当用vim写代码的时候,我喜欢一边看着头文件中结构的定义,一边编写实现的代码,这样就经常用到多窗口来编辑,查看文档. 1.同时打开多个文件,并横向排列 vim -o t.c t.h 2.同时打开多个文 ...

  9. atitit.手动配置列表文件的选择and 数据的层次结构 attilax总结最佳实践--yaml

    atitit.手动配置列表文件的选择and 数据的层次结构 attilax总结最佳实践--yaml 1. yaml是个好的选择.. 1 2. 数据的层次结构--结构:hash,list,和block  ...

  10. API Management Architecture Notes

    Kong/Tyk/Zuul/strongloop/Ambassador/Gravitee IBM Reference Architecture for API Management: https:// ...