/* * idea of solution: * you can consider the points to be eluminated as an x,y coordinates. In this solution * I considered row number as x coord, and column number as a y coord. We have several * cases (we can optimize them in general form but I split one function for each direction): * 1. North: in this case each line will be as if equation x = b, where b is the row number * 2. South: the exact reverse case of North (just reverse the outer loop). * 3. East: in this case line will be as if equation y=b, where b is the column number * 4. West: the exact reverse case of East (just reverse the outer loop). * 5. NW: in this case the line has a slope and equation will be y=mx + b, take sample points and find the slope and the b * 6. SE: reverse case of NW * 5. NE: in this case the line has a slope and equation will be y=mx + b, take sample points and find the slope and the b * 6. SW: reverse case of NW * In all cases: the outer loop is for changing the bias (b) for each equation. * The second outer loop is for drawing the line with specific thickness * The inner loop is to draw the line (O's). * * All the shiftX functions are very similar and know one leads to knowing others if you know * the correct values for b and m. * */ import java.util.*; public class DiscoFloor { public static void main(String[] args){ String input = "2\n4 2 1\nE 4\n5 1 2\nS 2\nSE 2"; String input1 = "1\n6 4 2\nN 3\nN 1"; Scanner s = new Scanner (input); int cases =s.nextInt(); for(int i=0;i=0;bb--){ if(bb < 0) break; if(t++ >= thickness) break; //System.out.println("BB:" + bb); for(int y=0;y= rows || y <0 || y >= cols) continue; arr[x][y] = 'O'; } } printArray(arr); System.out.println(); reset(arr,'.'); } } static void shiftN(char[][] arr, int thickness){ //equation is x = b, where y is the rows coord and x is the columns coord int rows = arr.length; int cols = arr[0].length; for(int b = rows + thickness -2; b>=0;b--){ int t = 0; for(int bb = b; bb >=0;bb--){ if(bb < 0) break; if(t++ >= thickness) break; //System.out.println("BB:" + bb); for(int y=0;y= rows || y <0 || y >= cols) continue; arr[x][y] = 'O'; } } printArray(arr); System.out.println(); reset(arr,'.'); } } static void shiftE(char[][] arr, int thickness){ //equation is y = b, where y is the rows coord and x is the columns coord int rows = arr.length; int cols = arr[0].length; for(int b = 0;b < cols + thickness - 1;b++){ int t = 0; for(int bb = b; bb >=0;bb--){ if(bb < 0) break; if(t++ >= thickness) break; //System.out.println("BB:" + bb); for(int x=0;x= rows || y <0 || y >= cols) continue; arr[x][y] = 'O'; } } printArray(arr); System.out.println(); reset(arr,'.'); } } static void shiftW(char[][] arr, int thickness){ //equation is y = b, where y is the rows coord and x is the columns coord int rows = arr.length; int cols = arr[0].length; for(int b = cols + thickness -2;b >=0;b--){ int t = 0; for(int bb = b; bb >=0;bb--){ if(bb < 0) break; if(t++ >= thickness) break; //System.out.println("BB:" + bb); for(int x=0;x= rows || y <0 || y >= cols) continue; arr[x][y] = 'O'; } } printArray(arr); System.out.println(); reset(arr,'.'); } } static void shiftSE(char[][] arr, int thickness){ int rows = arr.length; int cols = arr[0].length; int slope = -1; for(int b = 0;b < rows + cols - 2 + thickness;b++){ int t = 0; for(int bb = b; bb >=0;bb--){ if(bb < 0) break; if(t++ >= thickness) break; //System.out.println("BB:" + bb); for(int x=0;x= rows || y <0 || y >= cols) continue; arr[x][y] = 'O'; } } printArray(arr); System.out.println(); reset(arr,'.'); } } static void shiftNW(char[][] arr, int thickness){ int rows = arr.length; int cols = arr[0].length; int slope = -1; for(int b = rows + cols - 3 + thickness;b>=0;b--){ int t = 0; for(int bb = b; bb >=0;bb--){ if(bb < 0) break; if(t++ >= thickness) break; //System.out.println("BB:" + bb); for(int x=0;x= rows || y <0 || y >= cols) continue; arr[x][y] = 'O'; } } printArray(arr); System.out.println(); reset(arr,'.'); } } static int fun(int x, int m , int b){ return m * x + b; } static void shiftNE(char[][] arr, int thickness){ int slope = 1; int rows = arr.length; int cols = arr[0].length; for(int b = - (rows -1 ); b < cols + thickness -1 ;b++){ int t = 0; for(int bb = b ; bb > -rows ; bb-- ){ if(t++ >= thickness) break; //System.out.println("BB:" + bb); for(int x=0;xb=" + bb); if(x >= rows || y <0 || y >= cols) continue; arr[x][y] = 'O'; } System.out.println(); } printArray(arr); System.out.println(); reset(arr,'.'); } } static void shiftSW(char[][] arr, int thickness){ int slope = 1; int rows = arr.length; int cols = arr[0].length; for(int b = cols +thickness; b >= - (rows -1 ); b--){ int t = 0; for(int bb = b ; bb > -rows ; bb-- ){ if(t++ >= thickness) break; //System.out.println("BB:" + bb); for(int x=0;xb=" + bb); if(x >= rows || y <0 || y >= cols) continue; arr[x][y] = 'O'; } System.out.println(); } printArray(arr); System.out.println(); reset(arr,'.'); } } static void printArray(char[][] mat){ for(int i=0;i