2017年9月12日 星期二

UVA 10279:Minesweeper

  1. //由最內至外 依c的退步 斜線求出各行各列
  2. //由於偶數最中間是4個數字 故須特別 行,列+1再把邊界延升


  3. import java.util.*;  
  4. class main{  
  5. public static void main(String[] args){  
  6. Scanner sc = new Scanner(System.in);  
  7. int size , C=1;  
  8. while((size=sc.nextInt())!=0){  
  9. int[][] Matrix = new int[size][size];  
  10. int i , j ;  
  11. for( i=0;i<size;i++)  
  12.   for( j=0;j<size;j++)  
  13.       Matrix[i][j]=sc.nextInt();   
  14. //-----------  
  15. int count = (size-1)/2;  
  16. int[] st = new int[count+1];  
  17. int bounds = count;  
  18. if(size%2==0) bounds++;  
  19. for(int c=0;c<=count;c++){  
  20.   for( i=count-c;i<=bounds+c;i++){  
  21.      for( j=count-c;j<=bounds+c;j++){  
  22.           st[c]+=Matrix[i][j];   
  23.           Matrix[i][j]=0;    
  24.      }  
  25.   }  
  26. }  
  27.   
  28. //----------  
  29. for(int v=count;v>=0;v--)    
  30.   System.out.print((v==count?"Case "+(C++)+": ":" ")+st[v]);  
  31.    
  32.  System.out.println();  
  33.   
  34. }  
  35.   
  36. }  
  37.    
  38. }  

沒有留言:

張貼留言

注意:只有此網誌的成員可以留言。