Created
February 16, 2012 03:42
-
-
Save msg555/1841749 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#include <iostream> | |
#include <vector> | |
#include <algorithm> | |
#include <cmath> | |
using namespace std; | |
int X1[3]; | |
int X2[3]; | |
int Y1[3]; | |
int Y2[3]; | |
int X3[3]; | |
int Y3[3]; | |
void rot(int x, double ang) { | |
X3[x] = (int)round(X1[x] * cos(ang) - Y1[x] * sin(ang)); | |
Y3[x] = (int)round(X1[x] * sin(ang) + Y1[x] * cos(ang)); | |
} | |
int trr(vector<int> pi, int dx, int dy) { | |
double ang = -atan2(dy, dx); | |
rot(0, ang); | |
rot(1, ang); | |
rot(2, ang); | |
int xs = 0; | |
int ys = 0; | |
for(int i = 0; i < 3; i++) { | |
for(int j = i + 1; j < 3; j++) { | |
int dx2 = X2[pi[j]] - X2[pi[i]]; | |
int dx3 = X3[j] - X3[i]; | |
int dy2 = Y2[pi[j]] - Y2[pi[i]]; | |
int dy3 = Y3[j] - Y3[i]; | |
if(dx3 != 0) { | |
if(dx2 == 0 || dx2 % dx3 != 0) return 0; | |
int nxs = dx2 / dx3; | |
if(xs && nxs != xs) return 0; | |
xs = nxs; | |
} else if(dx2) { | |
return 0; | |
} | |
if(dy3 != 0) { | |
if(dy2 == 0 || dy2 % dy3 != 0) return 0; | |
int nys = dy2 / dy3; | |
if(ys && nys != ys) return 0; | |
ys = nys; | |
} else if(dy2) { | |
return 0; | |
} | |
} | |
} | |
if(!xs || !ys) return 4; | |
return 1; | |
} | |
int main() { | |
cin >> X1[0] >> Y1[0] >> X1[1] >> Y1[1] >> X1[2] >> Y1[2]; | |
for(int t = 1; X1[0] || Y1[0] || X1[1] || Y1[1] || X1[2] || Y1[2]; t++) { | |
cin >> X2[0] >> Y2[0] >> X2[1] >> Y2[1] >> X2[2] >> Y2[2]; | |
int res = 0; | |
vector<int> pi; | |
for(int i = 0; i < 3; i++) pi.push_back(i); | |
do { | |
for(int dx = -10; dx <= 10; dx++) { | |
res += trr(pi, dx, 10); | |
res += trr(pi, dx, -10); | |
} | |
for(int dy = -9; dy <= 9; dy++) { | |
res += trr(pi, 10, dy); | |
res += trr(pi, -10, dy); | |
} | |
} while(next_permutation(pi.begin(), pi.end())); | |
res /= 2; | |
cout << "Case " << t << ": "; | |
if(res == 0) { | |
cout << "no solution" << endl; | |
} else if(res == 1) { | |
cout << "equivalent solutions" << endl; | |
} else { | |
cout << "inconsistent solutions" << endl; | |
} | |
cin >> X1[0] >> Y1[0] >> X1[1] >> Y1[1] >> X1[2] >> Y1[2]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment