Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.BufferedReader;
- import java.io.FileReader;
- import java.util.Scanner;
- public class Solution {
- int N,M,K;
- int xc,yc,k;
- Integer[][] arr;
- Solution()
- {
- read();
- fun(2,1,1);
- for(int i=0;i<N;i++)
- {
- System.out.println();
- for(int j=0;j<M;j++)
- System.out.print(arr[i][j]);
- }
- }
- void read()
- {
- try{
- BufferedReader br =new BufferedReader(new FileReader("input.txt"));
- Scanner sc= new Scanner(br);
- N=sc.nextInt();
- M=sc.nextInt();
- K=sc.nextInt();
- arr =new Integer[N][M];
- for(int i=0;i<K;i++)
- {
- k=sc.nextInt();
- k--;
- xc =k/N;
- yc =k%M;
- arr[xc][yc]=-1;
- //System.out.println(xc);
- //System.out.println(yc);
- }
- }
- catch (Exception e) {
- }
- }
- boolean isGood(int x,int y)
- {
- if( x >= 0 && x < N && y >= 0 && y < M &&arr[x][y]!=-1)
- return true;
- return false;
- }
- boolean fun(int x,int y , int add)
- {
- boolean check = false;
- check =( arr[x][y] == 0);
- arr[x][y]+=add;
- for (int i = x + 1 , j = y + 1; isGood(i,j); check|=(arr[i][j] == 1 ), i++, j++)
- arr[i][j]+=add;
- for (int i = x - 1 , j = y - 1; isGood(i,j);check|=(arr[i][j] == 1 ), i--, j--)
- arr[i][j]+=add;
- for (int i = x + 1 , j = y - 1; isGood(i,j);check|=(arr[i][j] == 1 ), i++, j--)
- arr[i][j]+=add;
- for (int i = x - 1 , j = y + 1; isGood(i,j);check|=(arr[i][j] == 1 ), i--, j++)
- arr[i][j]+=add;
- return check;
- }
- public static void main(String[] args)
- {
- Solution sln =new Solution();
- }
- }
Add Comment
Please, Sign In to add comment