Time Limit: 4000MS | Memory Limit: 65536K | |
Total Submissions: 35013 | Accepted: 9207 |
Description
You may have heard that no two snowflakes are alike. Your task is to write a program to determine whether this is really true. Your program will read information about a collection of snowflakes, and search for a pair that may be identical. Each snowflake has six arms. For each snowflake, your program will be provided with a measurement of the length of each of the six arms. Any pair of snowflakes which have the same lengths of corresponding arms should be flagged by your program as possibly identical.
Input
The first line of input will contain a single integer n, 0 < n ≤ 100000, the number of snowflakes to follow. This will be followed by n lines, each describing a snowflake. Each snowflake will be described by a line containing six integers (each integer is at least 0 and less than 10000000), the lengths of the arms of the snow ake. The lengths of the arms will be given in order around the snowflake (either clockwise or counterclockwise), but they may begin with any of the six arms. For example, the same snowflake could be described as 1 2 3 4 5 6 or 4 3 2 1 6 5.
Output
If all of the snowflakes are distinct, your program should print the message:
No two snowflakes are alike.
If there is a pair of possibly identical snow akes, your program should print the message:
Twin snowflakes found.
Sample Input
2 1 2 3 4 5 6 4 3 2 1 6 5
Sample Output
Twin snowflakes found.
Source
#include<cstdio>
#include<string>
#include<cstring>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<climits>
#include<queue>
#include<vector>
#include<map>
#include<sstream>
#include<set>
#include<stack>
#include<utility>
#pragma comment(linker, "/STACK:102400000,102400000")
#define PI 3.1415926535897932384626
#define eps 1e-10
#define sqr(x) ((x)*(x))
#define FOR0(i,n) for(int i=0 ;i<(n) ;i++)
#define FOR1(i,n) for(int i=1 ;i<=(n) ;i++)
#define FORD(i,n) for(int i=(n) ;i>=0 ;i--)
#define lson num<<1,le,mid
#define rson num<<1|1,mid+1,ri
#define MID int mid=(le+ri)>>1
#define zero(x)((x>0? x:-x)<1e-15)
#define mp make_pair
#define _f first
#define _s second
using namespace std;
const int INF =0x3f3f3f3f;
//const int maxn= ;
//const int maxm= ;
//const int INF= ;
typedef long long ll;
const ll inf =1000000000000000;//1e15;
//ifstream fin("input.txt");
//ofstream fout("output.txt");
//fin.close();
//fout.close();
//freopen("a.in","r",stdin);
//freopen("a.out","w",stdout);
//by yskysker123
int n;
int tmp[6];
const int mod=999983;
struct Node
{
int a[6];
Node* nex;
Node()
{
nex=NULL;
for(int i=0;i<6;i++)
a[i]=tmp[i];
}
};
Node* fir[mod+10];
bool clockwise(Node *p)
{
for(int i=0;i<6;i++)
{
int j;
for( j=0;j<=5;j++)
{
if(tmp[j]!= p->a[ (j+i)%6 ])
break;
}
if(j==6) return true;
}
return false;
}
bool counterclock(Node *p)
{
for(int i=0;i<6;i++)
{
int j;
for( j=0;j<=5;j++)
{
if(tmp[j]!=p->a [ (5-j+i+6 )%6 ] )
break;
}
if(j==6) return true;
}
return false;
}
bool insert(int sum)
{
if(fir[sum]==NULL)
{
fir[sum]=new Node;
return false;
}
Node* p;
for( p=fir[sum];p ;p=p->nex)
{
if( clockwise(p) ) return true;
if( counterclock(p) ) return true;
}
p=new Node;
return false;
}
void dele(Node* p)
{
if(p==NULL) return;
dele ( p->nex );
delete p;
}
int main()
{
while(~ scanf("%d",&n) )
{
memset(fir,0,sizeof fir);
bool ok=0;
int sum;
FOR1(i,n)
{
sum=0;
FOR0(j,6)
{
scanf("%d",&tmp[j]);
sum+=tmp[j]%mod;
}
if(ok) continue;
sum%=mod;
if( insert(sum) ) ok=1;
}
if(ok) puts("Twin snowflakes found.");
else puts("No two snowflakes are alike.");
for(int i=1;i<=mod;i++)
{
dele(fir[i]);
}
}
return 0;
}