POJ3349——Snowflake Snow Snowflakes
来源:互联网 发布:京东面试题java 编辑:程序博客网 时间:2024/06/11 15:44
转自http://blog.csdn.net/zcy_2016/article/details/52149070
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
21 2 3 4 5 64 3 2 1 6 5
Sample Output
Twin snowflakes found.
Source
给出N个雪花的格式, 判断是否有两个完全相同的雪花
#include <iostream>#include <cstdlib>#include <cstdio>#include <vector>#include <queue>#include <algorithm>using namespace std;const int N = 100007;int a[N][6];vector<int> s[N+1];bool check(int x, int y){ int i, j; for( i = 0;i < 6;i++ ) { if( a[x][i]==a[y][0] ) { for( j = 0;j <6;j++ ) if( a[x][(i+j)%6]!=a[y][j] ) break; if( j==6 ) return true; for( j = 0;j < 6;j++ ) if( a[x][(i+j)%6]!=a[y][(6-j)%6] ) break; if( j==6 ) return true; } } return false;}bool find(){ for( int i = 0;i < N;i++) { for( int j = 0;j < (int)s[i].size()-1;j++ ) { for( int k = j+1;k < (int)s[i].size();k++ ) { if( check(s[i][j],s[i][k]) ) return true; } } } return false;}int main(){ int n; scanf("%d",&n); for( int i = 0;i < n;i++ ) { int sum = 0; for( int j = 0;j < 6;j++ ) { scanf("%d",&a[i][j]); sum = (a[i][j]+sum)%N; } s[sum].push_back(i); } if( find() ) printf("Twin snowflakes found.\n"); else printf("No two snowflakes are alike.\n"); return 0;}
- POJ3349——Snowflake Snow Snowflakes
- poj3349 Snowflake Snow Snowflakes —— 哈希表
- poj3349——Snowflake Snow Snowflakes
- poj3349 Snowflake Snow Snowflakes
- POJ3349 Snowflake Snow Snowflakes
- poj3349 Snowflake Snow Snowflakes
- Snowflake Snow Snowflakes poj3349
- poj3349 Snowflake Snow Snowflakes
- POJ3349--Snowflake Snow Snowflakes
- poj3349 Snowflake Snow Snowflakes
- POJ3349-Snowflake Snow Snowflakes
- POJ3349---Snowflake Snow Snowflakes
- poj3349 Snowflake Snow Snowflakes
- poj3349——Snowflake Snow Snowflakes(hash表)
- POJ3349--Snowflake Snow Snowflakes--哈希表
- 哈希 poj3349 Snowflake Snow Snowflakes
- POJ3349 Snowflake Snow Snowflakes(hash)
- POJ3349 Snowflake Snow Snowflakes(hash)
- GUI与UI的区别
- hdoj 1576 A/B [扩展欧几里得.逆元]
- 遍历文件夹中的文件(以图片为例)
- Web应用设置统一错误友好界面
- Android Camera的使用 (一)
- POJ3349——Snowflake Snow Snowflakes
- 使用C++类的成员函数来做windows的窗口函数
- refresh的停车场
- 东芝硬盘数据丢失怎么恢复
- mysql索引的实现原理
- 课程【 判断链表是否有环】
- Android屏幕密度(Density)和分辨率的关系
- 【置顶】经典背包讲解01背包&&完全背包&&多重背包
- poj 1066 Treasure Hunt