在线测试:Time Limit Exceeded
北大的在线测试
题目在:http://poj.org/problem?id=1061
我用java写的,给的结果就是:Time Limit Exceeded,我知道java的运行速度比较慢,谁能帮我有话一下,可以在那个系统中通过,分就全部是谁的了?
贴上我的代码:
Java code
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