Skip to content

Instantly share code, notes, and snippets.

View ivorynoise's full-sized avatar
💭
I may be slow to respond.

Deepak Aggarwal ivorynoise

💭
I may be slow to respond.
View GitHub Profile
@ivorynoise
ivorynoise / 0_reuse_code.js
Created September 18, 2016 09:02
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
//print a 'subset' that sum to number nearest to k
#include <cstdio>
#include <algorithm>
using namespace std;
int tracks[20];
int n, k;
int ans;
int used[20], sz, ansSize, ansArr[20];
bool found;
@ivorynoise
ivorynoise / p10576.cpp
Created September 20, 2016 06:34
Y2K Accounting Bug backtrack
/*
Calculate sum of all permutation of 12 numbers
satisfying a given constraint
*/
#include <cstdio>
#define inf 1000000000
#define mon 12
#define csc 4 //consecutive
int s, d;
long long ans, maxSurplus;
@ivorynoise
ivorynoise / p11085.cpp
Last active September 20, 2016 12:57
UVA 11085 Back to the 8-Queens
// Precomputes all valid combinations and match
#include <bits/stdc++.h>
using namespace std;
#define N 8
#define vi vector<int>
#define vvi vector<vi>
#define rdi(r,c) (r - c + N - 1) //right diag index Why N + 1 discuss wid akku
#define ldi(r,c) (r + c) //left diag index
bool row[8] = {0}, rd[30] = {0}, ld[30] = {0};
vvi queens;
@ivorynoise
ivorynoise / p00524.cpp
Last active September 20, 2016 13:49
UVA 524 Prime Ring Problem
#include <bits/stdc++.h>
using namespace std;
int n;
int num[16];
int mask;
bool isprime(int x){
if (x == 1) return false;
for (int i = 2; i * i <= x; ++i)
@ivorynoise
ivorynoise / p10503.cpp
Last active September 22, 2016 04:10
UVA 10503 The dominoes solitaire Complete Search
#include <bits/stdc++.h>
using namespace std;
#define prev(n) n-1
struct piece{
int x, y;
piece(){}
piece(int a, int b):x(a), y(b){}
};
int n, m;
@ivorynoise
ivorynoise / wordReverse.cpp
Created September 22, 2016 03:41
Reverse each word of sentence Amazon
#include <bits/stdc++.h>
#include <bits/stdc++.h>
using namespace std;
// int rev(string &s){
// int be = 0;
// int en = s.size();
// int sp = 0;
// while(sp != string::npos && be < en){
// sp = find()
@ivorynoise
ivorynoise / largestSubarray.java
Created September 23, 2016 11:56
Largest Subarray with given sum Amazon
import java.util.*;
class largestSubarray{
public static void main(String[] args){
Scanner s = new Scanner(System.in);
int n = s.nextInt();
int sum = s.nextInt();
int num[] = new int[n];
for (int i = 0; i < n; ++i)
num[i] = s.nextInt();
@ivorynoise
ivorynoise / wordsRev.java
Created September 23, 2016 12:44
Reverse Individual words in a string Amazon
import java.util.*;
class wordsRev{
public static void main(String[] args){
Scanner s = new Scanner(System.in);
String inp = s.nextLine();
String rev = wordsReverse(inp);
System.out.println(rev);
}
@ivorynoise
ivorynoise / balParant.java
Last active September 23, 2016 14:23
Check if balanced parantheses Amazon
import java.util.*;
class balParant{
public static void main(String[] args){
Scanner s = new Scanner(System.in);
String str = s.nextLine();
System.out.println(check(str));
}
public static boolean check(String s){
char[] exp = s.toCharArray();