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 |
Re:BufferedReader 与Scanner 就好像scanf 与 cin...效率相差真大.In Reply To:java还能怎么优化? Posted by:MasterLuo at 2009-03-20 12:23:38 > > import java.util.*; > > public class Main { > public static void main(String[] args) { > int[][] rec = new int[10001][32]; > int[] xor = new int[32]; > xor[0] = 1; > for(int i = 1; i < 31; ++i) > xor[i] = xor[i - 1] * 2; > xor[31] = 0x80000000; > int n, q, ii, jj, num, temp; > Scanner scan = new Scanner(System.in); > n = scan.nextInt(); > for(int i = 1; i <= n; ++i) { > num = scan.nextInt(); > int tempx = i / 32; > int left = i % 32; > > if(left == 0) { > tempx = tempx - 1; > left = 32; > } > int temps = xor[left - 1]; > > for(int j = 0; j < num; ++j) { > temp = scan.nextInt(); > rec[temp][tempx] = (rec[temp][tempx] | temps); > } > } > q = scan.nextInt(); > int max = (n + 31) / 32; > for(int i = 0; i < q; ++i) { > ii = scan.nextInt(); > jj = scan.nextInt(); > boolean flag = false; > for(int j = 0; j < max; ++j) { > if((rec[ii][j] & rec[jj][j]) != 0) { > flag = true; > break; > } > } > if(flag) > System.out.println("Yes"); > else > System.out.println("No"); > } > } > } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator