Guest User

Untitled

a guest
Jan 24th, 2018
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.53 KB | None | 0 0
  1. import java.io.BufferedReader;
  2. import java.io.FileReader;
  3. import java.util.Scanner;
  4.  
  5.  
  6. public class Solution {
  7.     int N,M,K;
  8.     int xc,yc,k;
  9.     Integer[][] arr;
  10.     Solution()
  11.     {
  12.         read();
  13.         fun(2,1,1);
  14.         for(int i=0;i<N;i++)
  15.         {
  16.             System.out.println();
  17.             for(int j=0;j<M;j++)
  18.            
  19.                 System.out.print(arr[i][j]);
  20.             }
  21.     }
  22.     void read()
  23.     {
  24.         try{       
  25.         BufferedReader br =new BufferedReader(new FileReader("input.txt"));
  26.         Scanner sc= new Scanner(br);
  27.         N=sc.nextInt();
  28.         M=sc.nextInt();
  29.         K=sc.nextInt();
  30.         arr =new Integer[N][M];
  31.        
  32.         for(int i=0;i<K;i++)
  33.         {
  34.             k=sc.nextInt();
  35.             k--;
  36.             xc =k/N;
  37.             yc =k%M;
  38.             arr[xc][yc]=-1;
  39.             //System.out.println(xc);
  40.             //System.out.println(yc);
  41.         }
  42.     }
  43.  
  44.         catch (Exception e) {
  45.         }
  46.     }
  47. boolean isGood(int x,int y)
  48.     {
  49.     if( x >= 0 && x < N && y >= 0 && y < M &&arr[x][y]!=-1)
  50.             return true;
  51.         return false;
  52.     }
  53. boolean fun(int x,int y , int add)
  54. {
  55.     boolean   check = false;
  56.     check =( arr[x][y] == 0);
  57.     arr[x][y]+=add;
  58.     for (int i = x + 1 , j = y + 1; isGood(i,j); check|=(arr[i][j] == 1 ), i++, j++)
  59.         arr[i][j]+=add;
  60.     for (int i = x - 1 , j = y - 1; isGood(i,j);check|=(arr[i][j] == 1 ),  i--, j--)
  61.         arr[i][j]+=add;
  62.     for (int i = x + 1 , j = y - 1; isGood(i,j);check|=(arr[i][j] == 1 ),  i++, j--)
  63.         arr[i][j]+=add;
  64.     for (int i = x - 1 , j = y + 1; isGood(i,j);check|=(arr[i][j] == 1 ),  i--, j++)
  65.         arr[i][j]+=add;
  66.     return check;
  67. }
  68.     public static void main(String[] args)
  69.     {
  70.         Solution sln =new Solution();
  71.     }
  72.  
  73. }
Add Comment
Please, Sign In to add comment