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

疑问?

Posted by alpc12 at 2007-08-10 21:35:30 on Problem 3334
下面这个代码在C++下通过 G++下WA 不知道为什么?
请管理员看看 谢谢!

#include <stdio.h>
#include <string.h>
#include <math.h>

const int N = 1010;
const double INF = 1e30;
const double EPS = 1e-12f;

struct Point { 
	double x, y; 
	void set(double xx, double yy) {
		x = xx; y = yy; 
	} 
} P[N], Q[N];

#define Max(a,b) ((a) > (b) ? (a) : (b))
#define Min(a,b) ((a) < (b) ? (a) : (b))

int n1, n2, c1, c2;
double V;

double cal(Point * p, double y, int c, int n) {

if (y < p[c].y) return 0;
	double cx = p[c].x, a, b, ret = 0, h;

	int i;
	for(i = 0; i < c; ++i) {
		if(y >= p[i].y) {
			h = p[i].y - p[i+1].y;
			a = p[i].x;
		}
		else if(y >= p[i+1].y) {
			h = y - p[i+1].y;
			a = p[i].x + (p[i+1].x - p[i].x) * (y-p[i].y) / (p[i+1].y - p[i].y);
		}
		else h = 0;
		b = p[i+1].x;
		ret += (cx-a+cx-b) / 2.0 * h;
	}

	for(i = c; i < n-1; ++i) {
		if(y >= p[i+1].y) {
			h = p[i+1].y - p[i].y;
			a = p[i+1].x;
		}
		else if(y >= p[i].y) {
			h = y - p[i].y;
			a = p[i].x + (p[i+1].x - p[i].x) * (y-p[i].y) / (p[i+1].y-p[i].y);
		}
		else h = 0;
		b = p[i].x;
		ret += (a-cx+b-cx)/2*h;
	}
	return ret;
}


double check(double y) {

	return cal(P, y, c1, n1) + cal(Q, y, c2, n2);
}

int main() {
	
//	freopen("t.in", "r", stdin);

	int ntc, i;
	scanf("%d", &ntc);
	while(ntc--) {
		scanf("%lf", &V);
		scanf("%d", &n1);
		double min = INF;
		for(i = 0; i < n1; ++i) {
			scanf("%lf%lf", &P[i].x, &P[i].y);
			if(P[i].y < min) 
				min = P[i].y, c1 = i;
		}
		scanf("%d", &n2);
		min = INF;
		for(i = 0; i < n2; ++i) {
			scanf("%lf%lf", &Q[i].x, &Q[i].y);
			if(Q[i].y < min) 
				min = Q[i].y, c2 = i;
		}

		double lo = Min(P[c1].y, Q[c2].y), 
			hi = Min(Min(Min(P[0].y, P[n1-1].y), Q[0].y), Q[n2-1].y);

		for(i = 0; i < 100; ++i) {
			double m = lo + (hi-lo)/2;
			if( check(m) >= V ) 
				hi = m;
			else lo = m;
		}
		printf("%.3lf\n", lo);
	}
	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