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 |
谁帮我看一下为什么会超时。好不容易写出来的import java.util.Scanner; public class flakes { static Scanner input = new Scanner(System.in); static final int harsh=99997; static final int max=100003; static int[] head=new int[max]; static int[] next=new int[max]; static int[][] flakesArm=new int[max][6]; public static void main(String[] args){ qingling(); int N=input.nextInt(); boolean flag=true; for(int i=0;i<N;i++){ for(int j=0;j<6;j++){ flakesArm[i][j]=input.nextInt(); } if(judge(i)) { System.out.println("Twin snowflakes found."); flag=false; } } if(flag){ System.out.println("No two snowflakes are alike."); } } public static boolean judge(int i){ int h=harsh(flakesArm[i]); int u=head[h]; while(u>=0){ if(compare(flakesArm[i],flakesArm[u])) return true; u=next[u]; } next[i]=head[h]; head[h]=i; return false; } public static int harsh(int[] fla){ int sum=0; for(int i=0;i<6;i++){ sum+=fla[i]; } return sum%harsh; } public static void qingling(){ java.util.Arrays.fill(head,-1); java.util.Arrays.fill(next,0); } public static boolean compare(int[] a,int[] b){ int i,j; for(i=0;i<6;i++){ if(a[0]==b[i]){ for(j=1;j<6;j++){ if(a[j]!=b[(i+j)%6]) break; } if(j==6) return true; for(j=1;j<6;j++){ if(a[6-j]!=b[(i+j)%6]) break; } if(j==6) return true; } } return false; } } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator