标签:.com printf pac using arch oid int 2.0 \n
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1115
思路:带公式:http://www.cnblogs.com/jbelial/archive/2011/08/08/2131165.html
#include<iostream> #include<cstdio> #include<cmath> using namespace std; struct Node{ double x,y; }; double Area(Node p1,Node p2,Node p3) { return ((p1.x*p2.y+p2.x*p3.y+p3.x*p1.y)-(p1.y*p2.x+p2.y*p3.x+p3.y*p1.x))/2.0; } int main(void) { Node p1,p2,p3; int t,n,i; double area,area_x,area_y; scanf("%d",&t); while(t--) { area=0,area_x=0,area_y=0; scanf("%d",&n); scanf("%lf%lf",&p1.x,&p1.y); scanf("%lf%lf",&p2.x,&p2.y); for(i=2;i<n;i++) { scanf("%lf%lf",&p3.x,&p3.y); double tmp=Area(p1,p2,p3); area+=tmp; area_x+=(p1.x+p2.x+p3.x)*tmp; area_y+=(p1.y+p2.y+p3.y)*tmp; p2=p3; } printf("%.2f %.2f\n",area_x/(area*3.0),area_y/(area*3.0)); } return 0; }
标签:.com printf pac using arch oid int 2.0 \n
原文地址:https://www.cnblogs.com/2018zxy/p/9902211.html