forked from mohitsh/SPOJ
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtwinsnow.cpp
72 lines (72 loc) · 1.1 KB
/
twinsnow.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// 2009-05-12
// modified 2014-10-07
#include <iostream>
#include <algorithm>
#include <vector>
#include <utility>
#include <functional>
using namespace std;
struct Snowflake
{
int x[6];
};
bool operator<(const Snowflake& X1,const Snowflake& X2)
{
return lexicographical_compare(X1.x,X1.x+6,X2.x,X2.x+6);
}
bool operator==(const Snowflake& X1,const Snowflake& X2)
{
return equal(X1.x,X1.x+6,X2.x);
}
void canonicalize(Snowflake& x)
{
Snowflake y=x;
int i;
for (i=0; i<6; i++)
{
rotate(y.x,y.x+1,y.x+6);
x=min(x,y);
}
reverse(y.x,y.x+6);
for (i=0; i<6; i++)
{
rotate(y.x,y.x+1,y.x+6);
x=min(x,y);
}
}
int in()
{
char c;
int x=0;
for (;;)
{
c=getchar_unlocked();
if (c<=32) return x;
x=(x<<1)+(x<<3)+c-'0';
}
}
int main()
{
int n,i;
n=in();
vector<Snowflake> V;
Snowflake s;
bool b=false;
while (n--)
{
for (i=0; i<6; i++)
s.x[i]=in();
// canonicalize(s);
sort(s.x,s.x+6);
V.push_back(s);
}
sort(V.begin(),V.end());
for (i=1; i<V.size(); i++)
if (V[i]==V[i-1])
{
printf("Twin snowflakes found.\n");
return 0;
}
printf("No two snowflakes are alike.\n");
return 0;
}