-
-
Save kronos/d8ccb2941cd057c28d9bc0192b9a6652 to your computer and use it in GitHub Desktop.
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
#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