Skip to content

Instantly share code, notes, and snippets.

@yongpitt
Last active December 18, 2015 01:29
Show Gist options
  • Save yongpitt/5704016 to your computer and use it in GitHub Desktop.
Save yongpitt/5704016 to your computer and use it in GitHub Desktop.
Snapper Chain Solution (Google Code Jam Qualification Round 2010)
/*Snapper Chain Solution (Google Code Jam Qualification Round 2010)*/
//For problem statement please go to: https://code.google.com/codejam/contest/433101/dashboard
//Easy problem. Done within 30 minutes and passed all tests.
void SnapperChain::PrintOnOff(ifstream &infile)
{
int T, N, K;
infile >> T;
ofstream outfile("D:/tests/SnapperChain.out");
for(int i=1; i<=T; i++){
infile >> N >> K;
long long int cycle = pow(2.0, N);
long long int start = cycle-1;
if((K>=start) && (K-start) % cycle == 0)
outfile << "Case #" << i << ": ON" << endl;
else
outfile << "Case #" << i << ": OFF" << endl;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment