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:你测一下这一题讨论中的几个数据吧,这么乘的话,数据早就越界了

Posted by DTfly at 2008-09-26 13:31:39 on Problem 1061
In Reply To:Re:你测一下这一题讨论中的几个数据吧,这么乘的话,数据早就越界了 Posted by:8013 at 2003-12-13 14:23:11
#include "stdio.h"
#define false 0
#define true 1
int main() {
	int x, y, m, n, L, count=0, sA, sB, speDif, i;
	int state = false;
	scanf("%d %d %d %d %d", &x, &y, &m, &n, &L);
	if(m>n) {
		speDif = m-n;
		if(x>y) {
			for(i=0; i<speDif; i++) {
				if(((i+1)*L-x+y)%speDif == 0) {
					state = true;
					printf("%d", ((i+1)*L-x+y)/speDif);
					return 0;
				}
			}
			if(state == false) printf("Impossible");
		}
		else if(x<y) {
			for(i=0; i<speDif; i++) {
				if((i*L+y-x)%speDif == 0) {
					state = true;
					printf("%d", (i*L+y-x)/speDif);
					return 0;
				}
			}
			if(state == false) printf("Impossible");
		}
		else {}
	}
	else if(m==n) {
		printf("Impossible");
	}
	else {
		speDif = n-m;
		if(x>y) {
			for(i=0; i<speDif; i++) {
				if((i*L+x-y)%speDif == 0) {
					state = true;
					printf("%d", (i*L+x-y)/speDif);
					return 0;
				}
			}
			if(state == false) printf("Impossible");
		}
		else if(x<y) {
			for(i=0; i<speDif; i++) {
				if(((i+1)*L-x+y)%speDif == 0) {
					state = true;
					printf("%d", ((i+1)*L-x+y)/speDif);
					return 0;
				}
			}
			if(state == false) printf("Impossible");
		}
		else {}
	}
}


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