http://acm.hdu.edu.cn/showproblem.php?pid=2105

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

代码:

#include <bits/stdc++.h>
using namespace std; int main() {
int n;
while(~scanf("%d", &n)) {
if(n == 0) break;
for(int i = 1; i <= n; i ++) {
double x1, y1, x2, y2, x3, y3;
cin>> x1 >> y1 >> x2 >> y2 >> x3 >> y3;
double x = 0, y = 0;
x = 1.0 * (x1 + x2 + x3) / 3;
y = 1.0 * (y1 + y2 + y3) / 3;
printf("%.1lf %.1lf\n", x, y);
}
}
return 0;
}

  

HDU 2105 The Center of Gravity的更多相关文章

  1. hdu 2105:The Center of Gravity(计算几何,求三角形重心)

    The Center of Gravity Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Ot ...

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

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

  3. hdu 2105

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

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

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

  5. Android android:gravity属性介绍及效果图

    转自: http://blog.csdn.net/aminfo/article/details/7784229 Android:gravity的属性官方说明如下: public static fina ...

  6. 从零开始学android开发-布局中 layout_gravity、gravity、orientation、layout_weight

    线性布局中,有 4 个及其重要的参数,直接决定元素的布局和位置,这四个参数是 android:layout_gravity ( 是本元素相对于父元素的重力方向 ) android:gravity (是 ...

  7. Android中的layout_gravity和gravity的区别

    在Android的布局中,除了padding和margin容易弄混之外,还有layout_gravity和gravity.按照字面意思来说,layout_gravity就是相对于layout来设置的. ...

  8. 【整理】Android中的gravity和layout_gravity区别

    [背景] 在Android中,想要设置个按钮的水平对齐,都累死了: [已解决]ADT中已设置TableLayout布局的情况下如何设置按钮居中对齐    所以现在有必要搞清楚,到底gravity和la ...

  9. android 布局中 layout_gravity、gravity、orientation、layout_weight

    线性布局中,有 4 个及其重要的参数,直接决定元素的布局和位置,这四个参数是 android:layout_gravity ( 是本元素相对于父元素的重力方向 ) android:gravity (是 ...

随机推荐

  1. 域名和IP之间的关系

    域名和IP的关系 在早期的互联网时代,没有那么多的主机,全部是用ip直接访问.可是IP不符合人类的记忆习惯,于是出现域名. 域名和IP的对应关系,在早期通过电脑的hosts文件直接解析,后来互联网的发 ...

  2. 20155217 实验四 Android程序设计

    20155217 实验四 Android程序设计 任务一: 完成Hello World, 要求修改res目录中的内容,Hello World后要显示自己的学号. R.java文件是定义该项目所有资源的 ...

  3. 【POI2007】ZAP-Queries

    题面 题解 $$ \sum_{i=1}^a\sum_{j=1}^b[gcd(i,\;j)=d] \\ =\sum_{i=1}^{\left\lfloor\frac ad\right\rfloor}\s ...

  4. 19、Java并发编程:线程间协作的两种方式:wait、notify、notifyAll和Condition

    Java并发编程:线程间协作的两种方式:wait.notify.notifyAll和Condition 在前面我们将了很多关于同步的问题,然而在现实中,需要线程之间的协作.比如说最经典的生产者-消费者 ...

  5. 试用一下markdown

    1 2 3 4 5 6 Blog

  6. php小项目小结

    最近一直断更,并不是出于什么问题,而是想找个合适的机会去整理下html基本的一些琐碎的知识点 近期突发感冒,吊水,吊错药,原因只是重名重姓,这不是个梗,很是痛苦的现实事故 so,只能用剩下的半天去完成 ...

  7. TeamViewer卡在正在初始化显示参数

    在windows的mstsc远程桌面中打开teamviewer,远程桌面开着的时候可以连接teamviewer,但是当我断开mstsc之后,再用teamviewer连就连接不上了,一直都是正在初始化显 ...

  8. 强化学习读书笔记 - 13 - 策略梯度方法(Policy Gradient Methods)

    强化学习读书笔记 - 13 - 策略梯度方法(Policy Gradient Methods) 学习笔记: Reinforcement Learning: An Introduction, Richa ...

  9. html表单总结

    总结了下html表单: <!DOCTYPE html> <html lang="en"> <head> <meta charset=&qu ...

  10. 搭建RTSP服务器时nginx的nginx.conf文件配置

    worker_processes 1; events { worker_connections 1024;} http { include mime.types; default_type appli ...