nyoj-130-相同的雪花(hash)
/*
Name:NYOJ-130-相同的雪花
Copyright:
Author:
Date: 2018/4/14 15:13:39
Description:
将雪花各个分支上的值加起来,hash
*/
#include <iostream>
#include <vector>
#include <cstdio>
#include <cstring>
using namespace std;
const int MAXN = 1e5+;
int snowflakes[MAXN][];
vector<int> snow[];//hash
int Like(int x,int y)//判断两片雪花是否相同
{
for(int i=;i<;i++)
{
if((snowflakes[x][]==snowflakes[y][i]&&snowflakes[x][]==snowflakes[y][(i+)%]&&snowflakes[x][]==snowflakes[y][(i+)%]&&snowflakes[x][]==snowflakes[y][(i+)%]&&snowflakes[x][]==snowflakes[y][(i+)%]&&snowflakes[x][]==snowflakes[y][(i+)%])///顺时针方向判断两个雪花是否相同
||(snowflakes[x][]==snowflakes[y][(i+)%]&&snowflakes[x][]==snowflakes[y][(i+)%]&&snowflakes[x][]==snowflakes[y][(i+)%]&&snowflakes[x][]==snowflakes[y][(i+)%]&&snowflakes[x][]==snowflakes[y][(i+)%]&&snowflakes[x][]==snowflakes[y][i]))///逆时针方向判断两个雪花是否相同
return ;
}
return ;
}
int main()
{
// freopen("in.txt", "r", stdin);
int t;
cin>>t;
while (t--) {
memset(snow, , sizeof(snow));
int n;
cin>>n;
for (int i=; i<n; i++) {
int sum = ;
for (int j=; j<; j++) {
int tmp;
cin>>tmp;
snowflakes[i][j] = tmp;
sum += tmp;
}
sum = sum % ;//防止越界
snow[sum].push_back(i);
}
int flag = ;
for (int i=; i<; i++) {
if (flag) break;
if (snow[i].size() < ) continue;
for (int j=; j<snow[i].size()-; j++) {
for (int k=j+; k<snow[i].size(); k++) {
if (Like(snow[i][j], snow[i][k])) {
flag = ;
break;
} }
}
}
if(flag)printf("Twin snowflakes found.\n");
else printf("No two snowflakes are alike.\n");
}
return ;
}
nyoj-130-相同的雪花(hash)的更多相关文章
- nyoj 130 同样的雪花 【哈希】
同样的雪花 时间限制:1000 ms | 内存限制:65535 KB 难度:4 描写叙述 You may have heard that no two snowflakes are alike. ...
- 相同的雪花 Hash
相同的雪花 时间限制:1000 ms | 内存限制:65535 KB 难度:4 描述 You may have heard that no two snowflakes are alike. ...
- 子序列 NYOJ (尺取法+队列+hash) (尺取法+离散化)
子序列 时间限制:3000 ms | 内存限制:65535 KB 难度:5 描述 给定一个序列,请你求出该序列的一个连续的子序列,使原串中出现的所有元素皆在该子序列中出现过至少1次. 如2 8 ...
- POJ 3349 HASH
题目链接:http://poj.org/problem?id=3349 题意:你可能听说话世界上没有两片相同的雪花,我们定义一个雪花有6个瓣,如果存在有2个雪花相同[雪花是环形的,所以相同可以是旋转过 ...
- 0x14 hash
被虐爆了 cry 我的hash是真的菜啊... poj3349 肝了一个上午心态崩了...一上午fail了42次我的天,一开始搞了个排序复杂度多了个log,而且是那种可能不同值相等的hash,把12种 ...
- redis4.0.6集群搭建
文件环境:CentOS7 + redis4.0.6 先去官网下载redis:https://redis.io/,然后上传到你的虚拟机,我上传到了/mysoft 先解压->然后进入主目录-> ...
- bzoj3820 虫逢
Description 小强和阿米巴是好朋友. 阿米巴告诉小强,变形虫(又叫阿米巴虫)和绝大多数生物一样,也是有 DNA 的.并且,变形虫可以通过分裂的方式进行无性繁殖. 我们把一个变形虫的基因组抽象 ...
- POJ 3349 Snowflake Snow Snowflakes(哈希表)
题意:判断有没有两朵相同的雪花.每朵雪花有六瓣,比较花瓣长度的方法看是否是一样的,如果对应的arms有相同的长度说明是一样的.给出n朵,只要有两朵是一样的就输出有Twin snowflakes fou ...
- 一致性哈希算法C#实现
一致性hash实现,以下实现没有考虑多线程情况,也就是没有加锁,需要的可以自行加上.因为换行的问题,阅读不太方便,可以拷贝到本地再读. 1 /// <summary> 2 /// 一致性哈 ...
随机推荐
- HAProxy安装及简单配置
一.HAProxy简介 代理的作用:web缓存(加速).反向代理.内容路由(根据流量及内容类型等将请求转发至特定服务器).转码器(将后端服务器的内容压缩后传输给client端).缓存的作用:减少冗余内 ...
- Protobuf支持 pointf
Protobuf支持 pointf序列化 加入:ProtoBuf.Meta.RuntimeTypeModel.Default.Add(typeof(System.Drawing.PointF), fa ...
- RocketMq入坑指南
报错信息Caused by: org.apache.rocketmq.remoting.exception.RemotingConnectException: connect to <172.1 ...
- Keepalived + LVS/DR 安装配置
Keepalived + LVS/DR 说明 Keepalived:可以踢出掉故障服务 Keepalived:可以实现主从切换,解决单点故障 实验环境 四台主机:Linux Centos 6.4 32 ...
- SDWebImage第三方库学习
1.基本使用方法 //异步下载并缓存 - (void)sd_setImageWithURL:(nullable NSURL *)url NS_REFINED_FOR_SWIFT; //使用占位图片,当 ...
- POJ 1459 网络流 EK算法
题意: 2 1 1 2 (0,1)20 (1,0)10 (0)15 (1)20 2 1 1 2 表示 共有2个节点,生产能量的点1个,消耗能量的点1个, 传递能量的通道2条:(0,1)20 (1,0) ...
- JAVA基础补漏---数组
int[] a = new int[5]; int[] b = new int{1,2,3}; int[] c = {4,5,6}; 以上几种定义都可以. a叫动态初始化. b叫静态初始化. c叫静态 ...
- java.sql.SQLException: Lock wait timeout exceeded; try restarting transaction
java.sql.SQLException: Lock wait timeout exceeded; try restarting transaction问题 1.问题描述 执行了几条update语句 ...
- Servlet和Filter的url匹配以及url-pattern详解
Servlet和filter是J2EE开发中常用的技术,使用方便,配置简单,老少皆宜.估计大多数朋友都是直接配置用,也没有关心过具体的细节,今天遇到一个问题,上网查了servlet的规范才发现,ser ...
- 基于主主复制的mysql双机热备+keepalived实现高可用性