Skip to content

Instantly share code, notes, and snippets.

@dudelson
Created January 8, 2017 18:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dudelson/c74d9daeb3faea4a5cf68f0512968852 to your computer and use it in GitHub Desktop.
Save dudelson/c74d9daeb3faea4a5cf68f0512968852 to your computer and use it in GitHub Desktop.
My incorrect solution for UVA 10920
#include <iostream>
typedef long long ll;
using namespace std;
ll size, p, x, y;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
while(cin >> size >> p, size||p) {
// start x and y at the center of the grid
ll x = size/2+1, y=size/2+1;
// these vars keep track of where we are in the spiral
ll I=1, i=I, pmo=1, J=1, j=J, why=true;
while(--p > 0) { // simulate!
if(why) {
y += pmo;
} else {
x += pmo;
}
i--; j--;
if(i==0) {
I+=2;
i = I;
pmo *= -1;
}
if(j==0) {
if(!why) J += 1;
j = J;
why = !why;
}
}
cout << "Line = " << y << ", column = " << x << ".\n";
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment