This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public int moves(int N, int M) { | |
int x = (N+1)/2; | |
int result = ((x+M-1)/M)*M; | |
if(result>N) result = -1; | |
System.out.printf("%d\n", result); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private void find(N,M) { | |
boolean [][] visited = new boolean[100000][1000]; | |
int [][] cache = new int[100000][13]; | |
int ans = dfs(N, visited, cache, 0, M); | |
if(ans>N) ans = -1; | |
System.out.printf("%d\n", ans); | |
} | |
private int dfs(int N, boolean[][]visited, int [][] cache, int moves, int M) { | |
if(N==0) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void printAllSubsets(int[] input){ | |
if ((input == null) || (input.length == 0)) return; | |
int N = input.length; | |
int [] output = new int[N]; | |
printAllSubsets(input, 0, output, 0); | |
} | |
private void printAllSubsets(int [] input, int read, int [] output, int write) { | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.BufferedReader; | |
import java.io.InputStreamReader; | |
public class SagheerTheHausmeister { | |
private static BufferedReader buf = new BufferedReader(new InputStreamReader(System.in)); | |
private static int M_MAX; | |
private static int N,M; | |
private static int MATRIX [][] = new int [16][150]; | |
private static int ILL [] = new int [16]; // has index of last bulb while entering from left. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Scanner; | |
import java.util.Arrays; | |
import java.util.Comparator; | |
class Main { | |
private static Scanner sc; | |
// input number in array of size N | |
private static long[] input(int N){ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# include <iostream> | |
# include <vector> | |
using namespace std; | |
int main() { | |
char caps[] = {'F', 'F', 'B', 'B', 'B', 'F', 'B', 'B', 'B', 'F', 'F', 'B', 'F'}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# include <iostream> | |
# include <algorithm> | |
# include <string> | |
using namespace std; | |
bool isOdd(int number){ | |
return number&1; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
// for each subset calculate the sum and compare with expected sum | |
bool checkSetBitAndValidateSum(long *array, long b, long sum) { | |
long i=0; | |
long runningSum=0; | |
while (b>0) { | |
if(b&1) { // check if bit is set |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void generateSubset(char* array) { | |
int N = strlen(array); | |
int range = (1<<N)-1; | |
for (int i=0;i<range;i++) { | |
checkBitSetAndPrint(array, i); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
n & n-1 |