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 /// 一致性哈 ...
随机推荐
- 1.6 使用电脑测试MC20的读取带中文短信功能
需要准备的硬件 MC20开发板 1个 https://item.taobao.com/item.htm?id=562661881042 GSM/GPRS天线 1根 https://item.taoba ...
- DP专题(不定期更新)
1.UVa 11584 Partitioning by Palindromes(字符串区间dp) 题意:给出一个字符串,划分为若干字串,保证每个字串都是回文串,同时划分数目最小. 思路:dp[i]表示 ...
- C#将图片白色背景设置为透明
Image image = System.Drawing.Image.FromFile(@"C:\A.JPG"); Bitmap pbitmap = new Bitmap(imag ...
- git在IDEA中的使用
学习资料: http://blog.csdn.net/autfish/article/details/52513465 (关于提交的讲解) http://blog.csdn.net/ck443870 ...
- nfs共享存储
1.下载软件包 yum install nfs-utils nfs-utils-lib -y 2.编辑/etc/exports文件: 1.创建目录:mkdir -p /home/glance2.编辑e ...
- iframe与父窗口之间数据互相获取
Js/Jquery获取iframe中的元素 博客分类: jquery javascript jquery 在web开发中,经常会用到iframe,难免会碰到需要在父窗口中使用iframe中的元素.或 ...
- Hibernate_HelloWord
Hibernate操作步骤 1.新建项目 2.加jar包 3.写XML配置文件hibernate.cfg.xml 4.写log4j.properties日志文件 5.在MySql数据库中建studen ...
- 024_MapReduce中的基类Mapper和基类Reducer
内容提纲 1) MapReduce中的基类Mapper类,自定义Mapper类的父类. 2) MapReduce中的基类Reducer类,自定义Reducer类的父类. 1.Mapper类 API文档 ...
- 【HackerRank】Ice Cream Parlor
Sunny and Johnny together have M dollars which they intend to use at the ice cream parlour. Among N ...
- Android BlueDroid(蓝牙协议栈)
Android BlueDroid(一):BlueDroid概述 Android BlueDroid(二):BlueDroid蓝牙开启过程init Android BlueDroid(三):BlueD ...