题目链接:hdu 1115

  计算几何求多边形的重心,弄清算法后就是裸题了,这儿有篇博客写得很不错的: 计算几何-多边形的重心

  代码如下:

 #include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
const int N = ; struct point {
double x,y;
point() {}
point(double x, double y): x(x), y(y) {}
void read() { scanf("%lf %lf",&x,&y); }
void readint() {
int x,y;
scanf("%d %d",&x,&y);
this->x = x;
this->y = y;
}
point operator - (const point &p2) const {
return point(x - p2.x, y - p2.y);
}
} p[N]; typedef point Vector; double cross(Vector a, Vector b) {
return a.x * b.y - a.y * b.x;
} double Area(point a, point b, point c) {
return cross(b - a, c - a) / ;
} inline double center3(double a, double b, double c) {
return a + b + c;
} int main() {
int t,n;
scanf("%d",&t);
while(t--) {
scanf("%d",&n);
for(int i = ; i <= n; ++i)
p[i].read(); double up = , down = ;
point ans;
for(int i = ; i <= n - ; ++i) {
up += center3(p[].x, p[i].x, p[i + ].x) * Area(p[], p[i], p[i + ]);
down += Area(p[], p[i], p[i + ]);
}
ans.x = up / down / ; up = ; down = ;
for(int i = ; i <= n - ; ++i) {
up += center3(p[].y, p[i].y, p[i + ].y) * Area(p[], p[i], p[i + ]);
down += Area(p[], p[i], p[i + ]);
}
ans.y = up / down / ;
printf("%.2lf %.2lf\n", ans.x, ans.y);
}
return ;
}

  有个要注意的小细节,对每个小三角形求重心时对最后结果 / 3 即可,而不必在中间过程 / 3,应该是精度问题,所以除法应尽可能避免,因为这题的 n 有点大,所以不断 / 3 操作损失的精度是很大的。

hdu 1115 Lifting the Stone的更多相关文章

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

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

  2. hdu 1115 Lifting the Stone 多边形的重心

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

  3. hdu 1115 Lifting the Stone (数学几何)

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

  4. poj 1115 Lifting the Stone 计算多边形的中心

    Lifting the Stone Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u S ...

  5. Hdoj 1115.Lifting the Stone 题解

    Problem Description There are many secret openings in the floor which are covered by a big heavy sto ...

  6. hdu1115 Lifting the Stone(几何,求多边形重心模板题)

    转载请注明出处:http://blog.csdn.net/u012860063 题目链接:pid=1115">http://acm.hdu.edu.cn/showproblem.php ...

  7. (hdu step 7.1.3)Lifting the Stone(求凸多边形的重心)

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

  8. Lifting the Stone(多边形重心)

    Lifting the Stone Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u S ...

  9. *HDU 1115 计算几何

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

随机推荐

  1. word中设置前几页为罗马数字,后几页设置为阿拉伯数字

    假如第1-5页摘要部分页脚要是罗马数字,第6页开始是正文部分是阿拉伯数字,起始页为1. WORD2003 1.将光标定位在第5页末尾处,在菜单栏中依次点击“插入——分隔符——(分节符类型)下一页”.按 ...

  2. Present

    Present time limit per test 2 seconds memory limit per test 256 megabytes input standard input outpu ...

  3. 新建一个DataTable(只针对一列)

    /// <summary> /// 新建一个DataTable(只针对一列) /// </summary> /// <param name="dataStr&q ...

  4. C语言typeof详解 offsetof

    http://blog.chinaunix.net/uid-28458801-id-4200573.html 前言:    typeof关键字是C语言中的一个新扩展,这个特性在linux内核中应用非常 ...

  5. hiho一下,第115周,FF,EK,DINIC

    题目1 : 网络流一·Ford-Fulkerson算法 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 小Hi和小Ho住在P市,P市是一个很大很大的城市,所以也面临着一个 ...

  6. Spring中DispacherServlet、WebApplicationContext、ServletContext的关系

    转载:http://blog.csdn.net/c289054531/article/details/9196149?utm_source=tuicool&utm_medium=referra ...

  7. IIS上部署MVC网站,打开后ExtensionlessUrlHandler-Integrated-4.0解决方法

    IIS上部署MVC网站,打开后ExtensionlessUrlHandler-Integrated-4.0解决方法 IIS上部署MVC网站,打开后500错误:处理程序“ExtensionlessUrl ...

  8. Spring 的优秀工具类盘点

    文件资源操作 文件资源的操作是应用程序中常见的功能,如当上传一个文件后将其保存在特定目录下,从指定地址加载一个配置文件等等.我们一般使用 JDK 的 I/O 处理类完成这些操作,但对于一般的应用程序来 ...

  9. SVG 是什么?

    SVG 意为可缩放矢量图形(Scalable Vectors Graphics).   SVG 图形在放大或者改变尺寸的情况下,其图形的质量不会有所损失.   SVG 使用 XML 格式定义图形.   ...

  10. anroid打包

    http://blog.csdn.net/qq435757399/article/details/46634363 转载 Gradle打包APP签名 默认情况下,debug被配置成使用一个debug ...