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

给跪了,测试数据都过,常规思路,怎么WA

Posted by sunkuo at 2013-03-08 02:05:38 on Problem 1385
#include<iostream>
#include<iomanip>
#define eps 0.00001
using namespace std;

struct vector
{
	double x,y;
}v[1000010];
struct grave
{
	double x,y;
	double wei;
}g[1000010];

double area(vector a,vector b,vector c)
{
	return (  (b.x-a.x)*(c.y-a.y)-(b.y-a.y)*(c.x-a.x)    )/2.0;
}

void getgra(vector a,vector b,vector c,int n)
{
	g[n].x=(a.x+b.x+c.x)/3.0;
	g[n].y=(a.y+b.y+c.y)/3.0;
	g[n].wei=area(a,b,c);
}

int main()
{
	int t,n;
	cin>>t;
	while(t--)
	{
		cin>>n;
		for(int i=0;i<n;i++)
		{
			cin>>v[i].x>>v[i].y;	
		}

		for(int i=1;i<n-1;i++)
		{
			getgra(v[0],v[i],v[i+1],i-1);
		}

		double sumx,sumy,sumarea;
		sumarea=0;
		for(int i=0;i<n-2;i++)
			sumarea+=g[i].wei;

		int flag=1;//表示逆时针
		if(g[0].wei<=eps)flag=0;
		sumx=0;
		for(int i=0;i<n-2;i++)
		{
			sumx+=g[i].wei*g[i].x;
		}
		//if(!flag)sumx=sumx*-1;//////////////////
		sumy=0;
		for(int i=0;i<n-2;i++)
		{
			sumy+=g[i].wei*g[i].y;
		}
		//if(!flag)sumy=-sumy;

		cout<<fixed<<setprecision(2)<<sumx/sumarea<<' '<<sumy/sumarea<<endl;
	}
	return 0;
}

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