POJ_3349_Snowflake Snow Snowflakes
| Time Limit: 4000MS | Memory Limit: 65536K | |
| Total Submissions: 43504 | Accepted: 11411 |
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
- 可以每次对于一个输入查询之前的雪花中是否有相同的
- 但是难点在于题目不保证雪花输入的方向和起点我们只能枚举
- 如果On枚举。。。还是算了吧
- 但是这里出了枚举好像也没有其他的办法了,因为我们没法定义一种对于雪花长短的一种排列方式使得通过这种排序在map中实现对于相同类型雪花的一个聚集效果
- 所以还是要在枚举上下功夫
- 显然两个完全一致的雪花各个花瓣之和相等
- 这里花瓣长度之和如果不加处理是不能用数组存的(好吧,做完题发现其实是可以用map来存,但是我们这里练hash)
- 我们对于sumi用素数p来进行hash,将对p取模结果相同的雪花合并为一类存储起来
- 进行比较的过程中就减少了枚举的个数
- 之后就是朴素的对于每一种可能性的检测,枚举起点和顺逆
- 这里需要以后注意的一点是对于hash结果的存放最好用vector,不要用数组,数组可能爆内存
- 说实在的,后来看看好像离散化后map存下也是可以的?
#include <iostream>
#include <string>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <climits>
#include <cmath>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
using namespace std;
typedef long long LL ;
typedef unsigned long long ULL ;
const int maxn = + ;
const int inf = 0x3f3f3f3f ;
const int npos = - ;
const int mod = 1e9 + ;
const int mxx = + ;
const double eps = 1e- ;
const double PI = acos(-1.0) ; int n, ans;
int c[maxn][], b[maxn];
int use[maxn];
std::vector<int> v[maxn];
int main(){
// freopen("in.txt","r",stdin);
// freopen("out.txt","w",stdout);
while(~scanf("%d",&n)){
ans=;
memset(use,,sizeof(use));
for(int i=;i<=n;i++){
int sum=;
for(int j=;j<;j++){
scanf("%d",&c[i][j]);
sum+=c[i][j];
}
sum%=;
b[i]=sum;
if(!use[sum]){
v[sum].clear();
}
use[sum]=;
v[sum].push_back(i);
if(!ans){
int sz=v[sum].size();
if(sz>){
for(int j=;j<sz;j++){
int idx=v[b[i]][j];
if(i!=idx){
int e, f, st;
if(!ans){
for(st=;st<;st++){
for(e=,f=st;e<;e++,f=(f++)%)
if(c[i][e]!=c[idx][f])
break;
if(e==)
ans=;
}
}
if(!ans){
for(st=;st<;st++){
for(e=,f=st;e<;e++,f=(f-+)%)
if(c[i][e]!=c[idx][f])
break;
if(e==)
ans=;
}
}
}
if(ans)
break;
}
}
}
}
puts(ans?"Twin snowflakes found.":"No two snowflakes are alike.");
}
return ;
}
POJ_3349_Snowflake Snow Snowflakes的更多相关文章
- POJ 3349 Snowflake Snow Snowflakes(简单哈希)
Snowflake Snow Snowflakes Time Limit: 4000MS Memory Limit: 65536K Total Submissions: 39324 Accep ...
- Snowflake Snow Snowflakes(哈希表的应用)
Snowflake Snow Snowflakes Time Limit: 4000MS Memory Limit: 65536K Total Submissions: 27312 Accep ...
- poj 3349:Snowflake Snow Snowflakes(哈希查找,求和取余法+拉链法)
Snowflake Snow Snowflakes Time Limit: 4000MS Memory Limit: 65536K Total Submissions: 30529 Accep ...
- POJ 3349 Snowflake Snow Snowflakes
Snowflake Snow Snowflakes Time Limit: 4000MS Memory Limit: 65536K Total Submissions: 27598 Accepted: ...
- POJ 3349:Snowflake Snow Snowflakes(数的Hash)
http://poj.org/problem?id=3349 Snowflake Snow Snowflakes Time Limit: 4000MS Memory Limit: 65536K T ...
- 哈希-Snowflake Snow Snowflakes 分类: POJ 哈希 2015-08-06 20:53 2人阅读 评论(0) 收藏
Snowflake Snow Snowflakes Time Limit: 4000MS Memory Limit: 65536K Total Submissions: 34762 Accepted: ...
- [poj3349]Snowflake Snow Snowflakes(hash)
Snowflake Snow Snowflakes Time Limit: 4000MS Memory Limit: 65536K Total Submissions: 37615 Accepted: ...
- POJ--3349 Snowflake Snow Snowflakes(数字hash)
链接:Snowflake Snow Snowflakes 判断所有的雪花里面有没有相同的 每次把雪花每个角的值进行相加和相乘 之后hash #include<iostream> #incl ...
- POJ 3349 Snowflake Snow Snowflakes (Hash)
Snowflake Snow Snowflakes Time Limit: 4000MS Memory Limit: 65536K Total Submissions: 48646 Accep ...
随机推荐
- iOS_UITextField 基本操作
基本操作 UITextField *userNameTextField = [[UITextField alloc] init]; userNameTextField.frame = CGRectMa ...
- 【Windows socket+IP+UDP+TCP】网络基础
Windows Socket+网络 Winsock是 Windows下套接字标准. Winsock 编程分为UDP[Windows socket + UDP],TCP[Wi ...
- Netty权威指南之伪异步I/O编程
为了解决同步阻塞I/O一个链路需要一个线程处理问题,对BIO模型做了优化——后端通过一个线程池处理多个客户端的请求接入,设置线程最大值,防止线程并发接入导致的线程耗尽. 当有新的客户端接入时,将客户端 ...
- Weblogic(CVE-2017-10271)漏洞复现
WebLogic XMLDecoder反序列化漏洞(CVE-2017-10271) 漏洞编号:CVE-2017-10271 漏洞描述:WebLogic WLS组件中存在CVE-2017-10271远程 ...
- Spring transaction事务 roll back各种回滚
Spring的AOP事务管理默认是针对unchecked exception回滚. 也就是默认对RuntimeException()异常极其子类进行事务回滚. Exception作为基类,下面还分ch ...
- Subversion权限详解
1 背景假设厦门央瞬公司是一家电子元器件设备供应商,其中有个ARM部门,专门负责ARM芯片的方案设计.销售,并在北京.上海各设立了一个办事处.对于工作日志,原先采用邮件方式发给经理,但是这种方式有 ...
- 【.NetCore学习】ASP.NET Core EF Core2.0 DB First现有数据库自动生成实体Context
主要参考微软官方文档 https://docs.microsoft.com/en-us/ef/core/get-started/aspnetcore/existing-db Microsoft .NE ...
- 为什么WAN口IP和外网IP不一样(不一致)?
正常的网络应该是动态公网ip,也就是路由器里面的WAN口IP与www.ip138.com上面显示的是一致的,不一致的话则说明该网络被电信或者联通做了NAT转发,导致您获取到了一个虚假的IP地址,无法用 ...
- activeMQ---->ActiveMQ的使用(一)
这里通过一个入门的案例来体会一下ActiveMQ的作用以及使用方法.你要做一个不动声色的大人了.不准情绪化,不准偷偷想念,不准回头看.去过自己另外的生活.你要听话,不是所有的鱼都会生活在同一片海里. ...
- 通俗大白话来理解TCP协议的三次握手和四次分手
通俗理解: 但是为什么一定要进行三次握手来保证连接是双工的呢,一次不行么?两次不行么?我们举一个现实生活中两个人进行语言沟通的例子来模拟三次握手. 引用网上的一些通俗易懂的例子,虽然不太正确,后面会指 ...