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, ...
随机推荐
- Bitmap尺度变换
Bitmap bitMap = BitmapFactory.decodeFile(path); int width = bitMap.getWidth(); int height = bitMap.g ...
- CSerialPort串口类最新修正版(解决关闭死锁问题)2014-01-11
这是一份优秀的类文件,好多的地方值得我们学习,具体在多线程,事件,自定义消息,类的封装方面等等.Remon提供的串口类网址为:http://codeguru.earthweb.com/network/ ...
- HDU 2647--Reward【拓扑排序】
Reward Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Sub ...
- sim800L调试问题
SIM800L默认上电开机,若此时没有把rst和pwk引脚提前设置好,SIM800l会使stm32进入硬件中断(这可能是因为方面电源的原因导致的),同时sim800L开机后需要一定的时间稳定下来,建议 ...
- Atitit.web预览播放视频的总结
Atitit.web预览播放视频的总结 1. 浏览器类型的兼容性(chrome,ff,ie) 1 2. 操作系统的兼容性 1 3. 视频格式的内部视频格式跟播放器插件的兼容性.. 2 4. 指定播放器 ...
- 内存控制函数(1)-mmap() 建立内存映射
示例1: 1.首先建立一个文本文件,名字为tmp,内容为hello world 2.编写mmap.c #include <sys/types.h> #include <sys/sta ...
- windows phone 切换多语言时,商店标题显示错误的问题
前段时间,用业余时间写了一款 wp8 app(“超级滤镜”商店,中文地址:英文地址),在多语言的时候,给 app title 和 app tile title 进行多语言时(参考 MSDN),中文商店 ...
- map area 标签的使用
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...
- 记一次处理IE引起的上网异常处理
win7 64bit系统,IE(11)出问题.在更新记录里找不到IE11的更新项,也就无法通过正常卸载了.而网上的各种折腾卸载方式均宣告无效.后来无意间找到了一款国外大神开发的软件:RemoveIE, ...
- 记一次线上MySQL数据库死锁问题
最近线上项目报了一个MySQL死锁(DealLock)错误,虽说对业务上是没有什么影响的,由于自己对数据库锁这块了解不是很多,之前也没怎么的在线上碰到过.这次刚好遇到了,便在此记录一下 ...