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

最简单的编程方法,但是一直TLE,大牛能说说思路么?

Posted by zhb_msqx at 2007-08-24 17:59:27 on Problem 2002
#include <iostream>
#include <fstream>
using namespace std;

int num;
struct point{
	int x,y;
} p[1001];

int dis(int a,int b){
	int x1=p[a].x;int x2=p[b].x;int y1=p[a].y;int y2=p[b].y;
	return ((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));

}

bool square(int a,int b,int c,int d){    //  ab||cd
	if(dis(a,b)==dis(b,c)&&dis(b,c)==dis(c,d)&&dis(c,d)==dis(d,a)&&dis(a,c)==dis(b,d))return true;
	else return false;
}

bool check(int a,int b,int c,int d){
	if(square(a,b,c,d)||square(a,c,b,d)||square(a,b,d,c))return true;
	return false;
}


void main(){
//	ifstream cin("data.txt");
	while(1){
		cin>>num;
		if(num==0)break;
		for(int i=0;i<num;i++){
			cin>>p[i].x>>p[i].y;
		}
		int total=0;
		for(i=0;i<num-3;i++){
			for(int j=i+1;j<num-2;j++){
				for(int k=j+1;k<num-1;k++){
					for(int l=k+1;l<num;l++){
						if(check(i,j,k,l))total++;
					}
				}
			}
		}
		cout<<total<<endl;

	}
}

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