首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

1282(未透过)

2012-09-24 
1282(未通过)遍历法,超时?package p1import java.util.Scannerpublic class t1282 {public static void

1282(未通过)

遍历法,超时

?

package p1;import java.util.Scanner;public class t1282 {public static void main(String[] args) {Scanner s = new Scanner(System.in);int r = s.nextInt();int c = s.nextInt();int[][] n = new int[r][c];int[] m = new int[r];for (int i = 0; i < r; i++) {m[i] = i;for (int j = 0; j < c; j++) {n[i][j] = s.nextInt() - 1;}}s.close();for (int i = 0; i < 1000000001; i++) {if (check(m, n, i % c, r)) {System.out.println(i + 1);return;}}System.out.println("No one knows.");}private static boolean check(int[] m, int[][] n, int d, int r) {for (int i = 0; i < r; i++) {m[i] = n[m[i]][d];}for (int i = 0; i < r; i++) {if (i != m[i]) {return false;}}return true;}}
?

?

热点排行