在线测试:Time Limit Exceeded

y2009270076 y2009270076 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
北大的在线测试
题目在: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);
}
}
...全文

相关推荐

评论 3
收藏 已收藏
分享
返回顶部
y2009270076
Java SE 62,620 成员 307,251 内容