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

Re:G++WA,C++AC,应该又是编译器的精度缺损。。。

Posted by wjy666 at 2017-07-11 08:47:13 on Problem 2502
In Reply To:G++WA,C++AC,应该又是编译器的精度缺损。。。 Posted by:RoyYuan at 2015-10-18 00:37:14
...我也是
#include<cstdio>
#include<cmath>
#define N 210
#define For(i,j,k) for(int i=j;i<=k;i++)
using namespace std;
int read(){
	int l=1,x=0; char ch=getchar();
	while((ch<'0'||ch>'9')&&ch!='-') ch=getchar();
	if (ch=='-') ch=getchar(),l=-1;
	while(ch>='0'&&ch<='9') x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
	return x*l;
}
double leng(int a,int b,int c,int d){
	double x=(double)(a-c),y=(double)(b-d);
	return sqrt(x*x+y*y)*6.0;
}
double a[N][N];
int main(){
	int x[N],y[N],s=3,l;
	x[1]=read(),y[1]=read(),x[2]=read(),y[2]=read();
	a[1][2]=a[2][1]=leng(x[1],y[1],x[2],y[2]);
	while(scanf("%d%d",&x[s],&y[s])!=EOF){
		l=s;
		while(1){
			s++; x[s]=read(),y[s]=read();
			if (x[s]==-1&&y[s]==-1) break;
		}
		For(i,l,s-2) 
			For(j,i+1,s-1) {
				if (j==i+1) a[i][i+1]=a[i+1][i]=leng(x[i],y[i],x[i+1],y[i+1])/4.0;
				else a[i][j]=a[j][i]=leng(x[i],y[i],x[j],y[j]);
			}
		For(i,1,l-1)
			For(j,l,s-1) a[i][j]=a[j][i]=leng(x[i],y[i],x[j],y[j]);
	}
	s--;
	For(k,1,s)
	  	For(i,1,s){
	  		if (i==k) continue;
	    	For(j,1,s){
	    		if (j==i||j==k) continue;
	    		if (a[i][j]>a[i][k]+a[k][j]) a[i][j]=a[i][k]+a[k][j];
	    	}
		}
	printf("%.0lf",a[1][2]/1000.0);
	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