Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
从这里可以看出系统判断时间的依据下面的代码结果超时 就是输入一个算一个 Problem Id:1012 User Id:ysg860607 Memory:712K Time:3156MS Language:Java Result:Time Limit Exceed Source import java.io.*; public class Main{ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); while (true) { int k = Integer.parseInt(in.readLine().trim()); if (k == 0) return; int times = 0; he:while (true) { out: for (int p = k; p < 2 * k; p++) { int i = times * 2 * k + p + 1; int t = 1; for (int j = 2 * k; j > k;) { t = (t + i - 1) % j; if (t == 0 || t > k) { j--; if (t == 0) t = 1; else t = t % j; } else continue out; } System.out.println(i); break he; } times++; } } } } 下面的代码就AC了, 我只是提前把结果算出来,存起来 然后直接输出 核心算法没有变,输入输出的策略改变,其结果相差十分大~!! Source Problem Id:1012 User Id:ysg860607 Memory:1864K Time:515MS Language:Java Result:Accepted Source import java.io.*; public class Main{ static int[] a=new int[14]; public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); int k=1; while (k<14) { int times = 0; he:while (true) { out: for (int p = k; p < 2 * k; p++) { int i = times * 2 * k + p + 1; int t = 1; for (int j = 2 * k; j > k;) { t = (t + i - 1) % j; if (t == 0 || t > k) { j--; if (t == 0) t = 1; else t = t % j; } else continue out; } a[k-1]=i; break he; } times++; } k++; } while(true){ int m = Integer.parseInt(in.readLine().trim()); if (m == 0) return; System.out.println(a[m-1]); } } } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator