Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

100万个点我开了个10万的数组居然过了。。。

Posted by Necs at 2012-10-25 11:15:49 on Problem 1385
按黑书的做法求重心:将多边形划分成多个三角形,利用三角形的重心公式。
自己阅读理解:
void getcentroid(point p[],int n,point &c){
       double tx=0,ty=0;
       double a=getarea(p,n);
       int i;
                 //p[n]=p[0];!
       for(i=0;i<n;i++)  tx=tx+(p[i].x+p[i+1].x)*(p[i].x*p[i+1].y-p[i+1].x*p[i].y);
       for(i=0;i<n;i++)  ty=ty+(p[i].y+p[i+1].y)*(p[i].x*p[i+1].y-p[i+1].x*p[i].y);
       c.x=tx/(6.0*a);c.y=ty/(6.0*a);
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator