Skip to content

Instantly share code, notes, and snippets.

@kronos

kronos/x.cpp Secret

Created April 13, 2019 04:13
Show Gist options
  • Save kronos/d8ccb2941cd057c28d9bc0192b9a6652 to your computer and use it in GitHub Desktop.
Save kronos/d8ccb2941cd057c28d9bc0192b9a6652 to your computer and use it in GitHub Desktop.
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
using namespace std;
int cases;
int n;
unsigned long long ans;
int main() {
cin.tie(0);
ios_base::sync_with_stdio(false);
cin >> cases;
int R, C;
for (int _case = 1; _case <= cases; _case++) {
cin >> R >> C;
bool reverted = R > C;
if (reverted) {
int t = R;
R = C;
C = t;
}
bool good;
if (R == 2) {
good = C > 4;
} else {
good = C > 3;
}
if (good) {
cout << "Case #" << _case << ": POSSIBLE\n";
int i = 1;
int j = 1;
int cnt = C*R;
bool right = true;
int jump = R == 2 ? 3 : 2;
int startj = 1;
while (cnt > 0) {
if (reverted){
cout << j << " " << i << "\n";
} else {
cout << i << " " << j << "\n";
}
i++;
if (i > R) {
i = 1;
startj++;
j = startj;
right = true;
} else{
if (right) {
j += jump;
if (j > C) {
j -= C;
}
} else {
j -= jump;
if (j < 1) {
j += C;
}
}
right = !right;
}
cnt--;
}
} else {
cout << "Case #" << _case << ": IMPOSSIBLE\n";
}
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment