题目链接:http://acm.hrbust.edu.cn/index.php?m=ProblemSet&a=showProblem&problem_id=2300
下雪啦 | ||||||
| ||||||
Description | ||||||
陈月亮最喜欢的季节就是冬天了,这不看着窗外飘起了雪花,陈月亮开心的跑出屋来看雪。但是迷迷糊糊的陈月亮不知道自己是在做梦还是真的下起了雪。突然她想起了一句话,在真实世界中是没有两片一样的雪花的。于是你的任务就是比较这场雪中的所有雪花,如果出现了两朵完全一致的雪花,则证明陈月亮是在梦中。 每朵雪花用六个整数表示,范围在(1 – 10000000)之间,表示雪花六个花瓣的长度,六个整数的先后出现顺序可能是顺时针顺序也可能是逆时针顺序,并且可能是从任意一个花瓣开始的。比如说对同一个花瓣,描述方法可能是1 2 3 4 5 6 或者 4 3 2 1 6 5 | ||||||
Input | ||||||
第一行为一个整数T,表示有T组测试数据。 每组测试数据第一行为一个整数N(0 < N <= 100000),表示雪花的数目。 接下来n行每行六个整数,描述一朵雪花。 | ||||||
Output | ||||||
如果没有相同的雪花,输出“No two snowflakes are alike.”,否则输出“Twin snowflakes found.” | ||||||
Sample Input | ||||||
1 2 1 2 3 4 5 6 4 3 2 1 6 5 | ||||||
Sample Output | ||||||
Twin snowflakes found. |
题解:直接字符串HASH即可。
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <assert.h>
#include <string.h>
#include <math.h>
#include <iostream>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
#define x0 x0___
#define y0 y0___
#define pb push_back
#define SZ(X) ((int)X.size())
#define mp make_pair
#define fi first
#define se second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pli pair<ll,int>
#define pil pair<int,ll>
#define ALL(X) X.begin(),X.end()
#define RALL(X) X.rbegin(),X.rend()
#define rep(i,j,k) for(int i = j;i <= k;i ++)
#define per(i,j,k) for(int i = j;i >= k;i --)
#define mem(a,p) memset(a,p,sizeof(a))
const int MOD = 1E9 + 7;
ll qmod(ll a,ll b,ll c) {ll res=1;a%=c; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%c;a=a*a%c;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
template<typename T, typename S>
void upmax(T& a,S b){if(a<b) a=b;}
template<typename T, typename S>
void upmin(T& a,S b){if(a>b) a=b;}
template<typename T>
void W(T b){cout << b << endl;}
void gettle() {while(1);}
void getre() {int t=0;t/=t;}
/
/
/
/
const int N = 1E5 + 7, M = 10000;
int snow[N][6];
bool same(int t1, int t2)
{
rep (i,0,5) {
bool fg1 = 1;
bool fg2 = 1;
rep (p,0,5) {
fg1 &= (snow[t1][p] == snow[t2][ (p + i) % 6 ]);
fg2 &= (snow[t1][p] == snow[t2][ (5 - p + i) % 6 ]);
// printf("%d %d\n",p,(p+5-i));
}
if(fg1 || fg2) return 1;
}
return 0;
}
int main()
{
int T;
scanf("%d", &T);
while(T --) {
int n;
scanf("%d", &n);
rep(i,0,n-1) rep(j,0,5) scanf("%d",&snow[i][j]);
vector<int>hx[M];
bool fg = 1;
rep (i,0,n-1) {
int sum = 0;
rep(j,0,5) sum += snow[i][j];
int key = sum % M;
rep (j,0,SZ(hx[key])-1) {
if(same(hx[key][j], i)) {
fg = 0; break;
}
}
if(!fg) break;
hx[key].pb(i);
}
puts(fg ? "No two snowflakes are alike." : "Twin snowflakes found.");
}
return 0;
}