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. 查看正在执行的sql语句

    ;WITH t AS( SELECT [Spid] = session_Id, ecid, [Database] = DB_NAME(sp.dbid), [User] = nt_username, [ ...

  2. profiler跟踪事件模板文件

    查找执行情况最差的查询. 例如,可以创建一个捕获与 TSQL 和 Stored Procedure 事件类(RPC:Completed 和SQL:BatchCompleted)相关的事件的跟踪.在此跟 ...

  3. 转:【微信小程序】 微信小程序-拍照或选择图片并上传文件

    调用拍照API:https://mp.weixin.qq.com/debug/wxadoc/dev/api/media-picture.html?t=20161222#wxchooseimageobj ...

  4. 强制关机后导致VBOX(4.2.16 r86992)的虚拟机不可使用问题的解决MEMO

    上周六晚上由于有急事,就强制关机,导致今天晚上用VirtualBox(4.2.16 r86992)时,虚拟机上写着不可使用. 显示异常Message如下: D:\tinderbox\win-4.2\s ...

  5. Ubuntu 64编译32位程序

    首先要打开64位系统对32位的支持 第一步:确认64为架构的内核 dpkg --print-architecture 输出:adm64 说明已拥有64位架构内核. 第二步:确认打开了多架构支持功能 d ...

  6. Aperture Time与NPLC

    NPLC工频周期数 NPLC是采样电源的周期倍数,N代表是多少倍,PLC与采样电源有关 交流电源的干扰是很厉害的.为了减少交流电源的干扰,一个常用的方法就是把测量周期尽可能的取成交流周波的整数倍,这样 ...

  7. OCR 识别原理

    https://mp.weixin.qq.com/s?__biz=MzA3MDExNzcyNA==&mid=402907292&idx=1&sn=889c4abcf576e24 ...

  8. php 检查该数组有重复值

    if (count($array) != count(array_unique($array))) { echo '该数组有重复值'; }

  9. Mysql 修改数据库,mysql修改表类型,Mysql增加表字段,Mysql删除表字段,Mysql修改字段名,Mysql修改字段排列顺序,Mysql修改表名

    对于已经创建好的表,尤其是已经有大量数据的表,如果需要对表做一些结构上的改变,我们可以先将表删除(drop),然后再按照新的表定义重建表.这样做没有问题,但是必然要做一些额外的工作,比如数据的重新加载 ...

  10. atitit.编程语言会形成进化树--哪些特性会繁荣??通才还是专才的选型 现代编程语言的特性总结

    atitit.编程语言会形成进化树--哪些特性会繁荣??通才还是专才的选型 现代编程语言的特性总结 1.  有一种观点,编程语言就像物种,会形成进化树,有的分支会死掉. 多年之后,你觉得语言会演化成什 ...