hdu 2105:The Center of Gravity(计算几何,求三角形重心)
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
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?
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.
#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(计算几何,求三角形重心)的更多相关文章
- HDU 2105 The Center of Gravity
http://acm.hdu.edu.cn/showproblem.php?pid=2105 Problem Description Everyone know the story that how ...
- HDU 2105 The Center of Gravity (数学)
题目链接 Problem Description Everyone know the story that how Newton discovered the Universal Gravitatio ...
- POJ 2225 / ZOJ 1438 / UVA 1438 Asteroids --三维凸包,求多面体重心
题意: 两个凸多面体,可以任意摆放,最多贴着,问他们重心的最短距离. 解法: 由于给出的是凸多面体,先构出两个三维凸包,再求其重心,求重心仿照求三角形重心的方式,然后再求两个多面体的重心到每个多面体的 ...
- fzu 1330:Center of Gravity(计算几何,求扇形重心)
Problem 1330 Center of Gravity Accept: 443 Submit: 830Time Limit: 1000 mSec Memory Limit : 327 ...
- hdu 1115:Lifting the Stone(计算几何,求多边形重心。 过年好!)
Lifting the Stone Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...
- HDU 5572 An Easy Physics Problem (计算几何+对称点模板)
HDU 5572 An Easy Physics Problem (计算几何) 题目链接http://acm.hdu.edu.cn/showproblem.php?pid=5572 Descripti ...
- hdu 4709:Herding(叉积求三角形面积+枚举)
Herding Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Sub ...
- UVa 11437:Triangle Fun(计算几何综合应用,求直线交点,向量运算,求三角形面积)
Problem ATriangle Fun Input: Standard Input Output: Standard Output In the picture below you can see ...
- hdu 2105
#include <iostream> #include <stdio.h> using namespace std; int main() { double a,b,c,d, ...
随机推荐
- UML学习(二)- 用例图
UML用例图 用例图主要用来图示化系统的主事件流程,它主要用来描述客户的需求,即用户希望系统具备的完成一定功能的动作,通俗地理解用例就是软件的功能模块,所以是设计系统分析阶段的起点,设计人员 ...
- java工具类之按对象中某属性排序
import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; import java.lang ...
- C#中byte类型转换为double类型
// Initialize unmanged memory to hold the array. int size = Marshal.SizeOf(bytes[0]) * bytes.Length; ...
- oracle 错误码查看命令oerr ora及常用错误码总结--不断更新
oracle 错误码查看命令oerr ora及常用错误码总结--不断更新 1.ORA-00907: 缺失右括号 我自己的问题出在 字段的default 和 not null 顺序反了,defalut ...
- spring in action小结3 运行时值注入
讨论依赖注入的时候,通常讨论的是一个bean引用注入到另一个bean的属性或者构造器参数中.bean装配的另一个方面是将值注入到bean的属性或者构造器参数中.避免硬编码的方式就是运行时确定值. sp ...
- SQL相关路径查询脚本
--1.查询机器名 SELECT @@servername AS 机器名称 --查询已安装的SQL实例名 SELECT * FROM Sys.Servers --2.查询SQL安装路径 DECLARE ...
- ubuntu16.04安装jekyll 3.3.1
本次安装的ekyll为最新的3.3.1版本. 一.预备工作,因位jekyll需要很多软件的支持,所以准备工作要做足. Ruby (including development headers, v1.9 ...
- 快速过滤出完整的SQL语句
[root@bass ca]# mysqlbinlog -- |egrep -v "^(/|SET|BEGIN|COMMITER|#|COMMIT)" >a.log [roo ...
- 用wget做站点镜像
用wget做站点镜像 -- :: 分类: LINUX # wget -r -p -np -k http://xxx.edu.cn -r 表示递归下载,会下载所有的链接,不过要注意的是,不要单独使用这个 ...
- 孙源即将分享 DynamicCocoa 实现细节
孙源即将分享 DynamicCocoa 实现细节 我的公众号之前发的一文中提到滴滴做了一个很牛逼的动态化方案 DynamicCocoa.该方案设计得非常精巧,解决了两种不同的语言在代码上如何等价生 ...