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 啊wa 郁闷!程序如下

Posted by cao_peng at 2005-01-15 18:45:15 on Problem 1931
保存叉积符号和两边长度的平方,再判断,始终不对。请大家帮忙,先谢谢了。

#include <iostream>
#include <cstdio>
#include <cmath>

#define ZERO 1e-8

using namespace std;

typedef struct point {
	int x,y;
} ;

typedef struct node {
	int xp,d1,d2;
	double j;
} ;

point temp[11];
node a[11],b[11];
double r;

int sgn(int x) {
	if (x>0) return 1;
	else return (x==0)?0:-1;
}

int dist(point a,point b) {
int x=a.x-b.x,y=a.y-b.y;
	return (x*x+y*y);
}

bool equ(node a,node b) {
	return ((a.xp==b.xp) && (fabs(a.d1-b.d1*r)<=ZERO) && (fabs(a.d2-b.d2*r)<=ZERO) && (fabs(a.j-b.j)<=ZERO));
}
	

int xmult(point p1,point p2,point p0){
	return (p1.x-p0.x)*(p2.y-p0.y)-(p2.x-p0.x)*(p1.y-p0.y);
}


int dmult(point p1,point p2,point p0){
	return (p1.x-p0.x)*(p2.x-p0.x)+(p1.y-p0.y)*(p2.y-p0.y);
}


int main() {
int n,i,j;
point p0,p1,p2;

	while (scanf("%d",&n)!=EOF) {
		if (!n) break;
		for (i=0;i<n;++i)
			scanf("%d%d",&temp[i].x,&temp[i].y);
		for (i=0;i<n;++i) {
			p0=temp[i];
			p1=temp[(i+n-1)%n];
			p2=temp[(i+1)%n];
			a[i].xp=sgn(xmult(p1,p2,p0));
			a[i].d1=dist(p1,p0);
			a[i].d2=dist(p2,p0);
			a[i].j=(double) dmult(p1,p2,p0)/sqrt(a[i].d1)/sqrt(a[i].d2);
		}
		for (i=0;i<n;++i)
			scanf("%d%d",&temp[i].x,&temp[i].y);
		for (i=0;i<n;++i) {
			p0=temp[i];
			p1=temp[(i+n-1)%n];
			p2=temp[(i+1)%n];
			b[i].xp=sgn(xmult(p1,p2,p0));
			b[i].d1=dist(p1,p0);
			b[i].d2=dist(p2,p0);
			b[i].j=(double) dmult(p1,p2,p0)/sqrt(b[i].d1)/sqrt(b[i].d2);
		}
		for (i=0;i<n;++i) {
			r=(double) a[0].d1/b[i].d1;
			for (j=0;j<n;++j) 
				if (!equ(a[j],b[(i+j)%n])) break;
			if (j==n) break;
		}
		if (i==n) 
			printf("dissimilar\n");
		else
			printf("similar\n");
	}
	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