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 jsjhoubo at 2007-01-16 23:32:30 on Problem 1061
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#define stacksize 50
struct euclid
{
	long double d;
	long double x;
	long double y;
} eu;
long double mod(long double a,long double b)
{
	long double q=floor(a/b);
	q=a-q*b;
	while(q<0) q+=b;
	while(q>=b) q-=b;
	return q;
}
struct euclid  gcd(long double x,long double y)
{
	struct euclid eu1,eu2;
	if(y==0) 
	{
		eu1.d=x;
		eu1.x=1;
		eu1.y=0;
		return eu1;
	}
	else eu1=gcd(y,floor(mod(x,y)));
	eu2.d=eu1.d;
	eu2.x=eu1.y;
	eu2.y=eu1.x-floor(x/y)*eu1.y;
	return eu2;
}
	
int main()
{
	long double x,y,m,n,L,t,q,min,temp;
	__int64 i;
	scanf("%lf %lf %lf %lf %lf",&x,&y,&m,&n,&L);
	if(x<0) x=x+L;
	if(y<0) y=y+L;
	if(m==n&&x!=y)
	{ 
		printf("Impossible");
		return 0;
	}
	if((m-n<0)) t=m-n+L;
	else t=m-n;
	eu=gcd(t,L);
	if(eu.d!=t*eu.x+L*eu.y)
	{
		temp=eu.x;
		eu.x=eu.y;
		eu.y=temp;
	}
	if((y-x)<0) t=y-x+L;
	else t=y-x;
	if(mod(t,eu.d)!=0) 
	{
		printf("Impossible");
		return 0;
	}
	t=mod((eu.x*(t/eu.d)),L);
	i=0;
	q=t;
	min=q;
	while(i<=eu.d)
	{		
		q=mod((t+(i*(L/eu.d))),L);
		if(min>q) min=q;
		i++;
	}
	i=(__int64)floor(min);
	printf("%ld\n",i);
	system("pause");
  	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