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 bakey at 2005-05-03 11:42:12 on Problem 1624
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>
#define eps 1e-12
struct pos{
	double x,y;
}p[200];
double cal(int s,int e)
{
	double sum = 0;
	int i;
	for (i = s; i < s+e; i ++){
		sum += p[i%8].x*p[(i+1)%8].y-p[i%8].y*p[(i+1)%8].x;
	}
	sum += p[(s+e)%8].x*p[s%8].y-p[(s+e)%8].y*p[s%8].x;
	sum = (double)fabs(sum*0.5);
	return sum;
}

void solve()
{
	double t_area,area1,area2;
	double best1,best2;
	int i,j;
	t_area = cal(0,7);
	double min = t_area;
	for (i = 0 ; i < 8 ; i ++){
		for (j = 0; j < 8; j ++){
		    area1 = cal(i,j); area2 = t_area - area1;
			if (fabs(area1-area2) < min){
			     min = fabs(area1-area2);
				 best1 = area1; best2 = area2;
			}
		}
	}
	if (best1 < best2)
		printf("%.3lf %.3lf\n",best1,best2);
	else
		printf("%.3lf %.3lf\n",best2,best1);
}

int main()
{
	freopen("input.txt","r",stdin);
//	freopen("output.txt","w",stdout);
    int i,j,count = 0;
	double t;
	while (1)
	{
		t = 0;
		for (i = 0 ; i < 4 ; i ++){
			scanf("%lf %lf",&p[i].x,&p[i].y);
			t += p[i].x + p[i].y;
		}
		if (fabs(t) < eps) break;
		count ++;
		j = 3;
		for (i = 6; i >= 2 ; i -= 2){
			p[i].x = p[j].x; p[i].y = p[j].y;
			j --;
		}
		for (i = 1; i < 8; i +=2){
			p[i].x = (double)(p[i-1].x+p[(i+1)%8].x)/2;
			p[i].y = (double)(p[i-1].y+p[(i+1)%8].y)/2;
		}
		printf("Cake %d: ",count);
		solve();
	}
	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