2011-02-03 63 views
-1

這裏的問題陳述:CodeChef陣列變換計劃

給定n個數字,你可以執行下列操作的任何數量的 時間:選擇 號碼,其中沒有一個是0的任何子集。 遞減通過 1子集中的號碼,並增加數量並不 被K的子集可以 進行操作,從而使得除了其中一人所有 數字變成0? 輸入:第一行包含 多的測試用例T. 2 * T線 後續,2對於每種情況。第一 線測試用例包含 數n和K.下一行 含有n個數,A_1 ... A_N。輸出 :輸出T行,每個測試用例對應 。對於測試用例,如果存在所述的 操作序列,則 輸出「是」,否則輸出「否」 。

Sample Input : 
3 
2 1 
10 10 
3 2 
1 2 2 
3 2 
1 2 3 

Sample Output : 
YES 
YES 
NO 

Constraints : 
1 <= T <= 1000 
2 <= n <= 100 
1 <= K <= 10 
0 <= a_i <= 1000 

&這裏是我的代碼:

import java.util.*; 

public class ArrayTransform { 
    public static void main(String args[]) { 
     Scanner sc = new Scanner(System.in); 
     int no_of_tests = sc.nextInt(); 

     int size; 
     int a[] = new int[100]; 
     boolean yes; 
     int j; 
     int k; 
     for (int i = 0; i < no_of_tests; i++) { 
      size = sc.nextInt(); 
      k = sc.nextInt(); 
      for (j = 0; j < size; j++) { 
       a[j] = sc.nextInt(); 
      } 
      yes = is_possible(a, size, k + 1); 
      if (yes) 
       System.out.println("YES\n"); 
      else 
       System.out.println("NO\n"); 
     } 
    } 

    static boolean is_possible(int a[], int size, int k_1) { 
     int count = 0; 
     int m[] = { -1, -1 }; 
     int mod; 
     for (int i = 0; i < size; i++) { 
      mod = a[i] % k_1; 
      if (m[0] != mod && m[1] != mod) { 
       if (m[0] == -1) 
        m[0] = mod; 
       else if (m[1] == -1) 
        m[1] = mod; 
       else 
        return false; 
      } 
     } 
     return true; 
    } 
} 
+3

哪來的問題??? – maaartinus 2011-02-03 13:30:40

回答

3
if (m[0] != mod && m[1] != mod) 

這裏,而不是&&應該有||。只有m需要匹配mod。