北大的在线测试
题目在:http://poj.org/problem?id=1061
我用java写的,给的结果就是:Time Limit Exceeded,我知道java的运行速度比较慢,谁能帮我有话一下,可以在那个系统中通过,分就全部是谁的了?
贴上我的代码:import java.util.*;
public class Main {
public static void main(String[] args) throws Exception{
int x=0,y=0,m=0,n=0,l=0,count = 0;
Scanner cin = new Scanner(System.in);
x = cin.nextInt();
y = cin.nextInt();
m = cin.nextInt();
n = cin.nextInt();
l = cin.nextInt();
if(m==n){
System.out.println("Impossible");
return;
}
while (x!=y) {
count++;
x+=m;
y+=n;
if (x>l-1) {
x=x%l;
}
if (y>l-1) {
y=y%l;
}
}
System.out.println(count);
}
}
题目在:http://poj.org/problem?id=1061
我用java写的,给的结果就是:Time Limit Exceeded,我知道java的运行速度比较慢,谁能帮我有话一下,可以在那个系统中通过,分就全部是谁的了?
贴上我的代码:import java.util.*;
public class Main {
public static void main(String[] args) throws Exception{
int x=0,y=0,m=0,n=0,l=0,count = 0;
Scanner cin = new Scanner(System.in);
x = cin.nextInt();
y = cin.nextInt();
m = cin.nextInt();
n = cin.nextInt();
l = cin.nextInt();
if(m==n){
System.out.println("Impossible");
return;
}
while (x!=y) {
count++;
x+=m;
y+=n;
if (x>l-1) {
x=x%l;
}
if (y>l-1) {
y=y%l;
}
}
System.out.println(count);
}
}
http://www.iteye.com/topic/480856
import java.util.*;
public class Main {
public static void main(String[] args) throws Exception{
int x=0,y=0,m=0,n=0,l=0,count = 0;
Scanner cin = new Scanner(System.in);
x = cin.nextInt();
y = cin.nextInt();
m = cin.nextInt();
n = cin.nextInt();
l = cin.nextInt();
if(m==n){
System.out.println("Impossible");
return;
}
/*while (x!=y) {
count++;
x+=m;
y+=n;
if (x>l-1) {
x=x%l;
}
if (y>l-1) {
y=y%l;
}
}*/
else if(m>n){
if(x<y){
count=(y-x)/(m-n);
}else{//题目说过了 x!=y
count=(l-x+y)/(m-n);
}
}
else if(m<n){
if(x<y){
count=(l-y+x)/(n-m);
}else{
count=(x-y)/(n-m);
}
}
System.out.println(count);
}
}