nyoj-130 相同的雪花 (哈希)

HCIA重点知识 华为认证ICT工程师,是华为认证体系中用于标识个人能力在某一技术领域达到工程师级别的证明,表示通过认证的人员具备安装、配置、运行 ICT 设备,并进行基础故障排除的能力。抽象语言 -----> 编码 -----> 二进制 -----> 电信号 -----> 处理电信号信号的转换标准:协议,是一种允许电子设备相互交流的一系列标准的规则。即开放系统参考模型OSI/RM,简称“OSI”。OSI参考模型将计算机网络分为七个层次,自上而下依次为:应用层,表示层,会话层,传输层,网络层,数据链路层,物理层。1、应用层: 阅读详情

相同的雪花

时间限制:1000 ms  |  内存限制:65535 KB
难度:4
描述
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.
输入
The first line of the input will contain a single interger T(0<T<10),the number of the test cases.
The first line of every test case 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.
输出
For each test case,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.
样例输入
1
2
1 2 3 4 5 6
4 3 2 1 6 5
样例输出
Twin snowflakes found.


思路:

        此题数据量很大, 如果是挨个枚举两朵雪花是否一致的话,肯定会超时. 但如果能先求出六条边的和,判断时只跟和相等的雪花进行比较,明显会好很多了。但是,需要注意的是这个和也可能很大。。所以,就可以先取余了~ 


代码:

#include <stdio.h>
#include <string.h>
#include <vector>
#define N 100000

using namespace std;

struct Node{
	int num[6];
	int s;				// 保存 num 数组所有数据的和,以提高效率 
};

bool CMP(int a[], int b[]){				// 比较函数 
	int start = -1, ok = 0;
	while(start < 6 && ok == 0){		// 找到一个相同点的位置(注意,某雪花的两条边可能相等) 
		for(start += 1; ; start ++){
			if(start >= 6){
				return 0;
			}
			if(a[start] == b[0]){
				break;	
			}
		}
		
		ok = 1;
		for(int i = 0, j = start; i < 6; i ++, j ++){				// 正向比较 
			if(b[i] != a[j % 6]){
				ok = 0;
				break;
			}
		}
		if(!ok){
			ok = 1;
			for(int i = 0, j = start + 6; i < 6; i ++, j --){		// 逆向比较 
				if(b[i] != a[j % 6]){
					ok = 0;
					break;
				}
			}
		}
	}
	
	return ok;
}

int main(){
	int loop, n;
	scanf("%d", &loop);
	while(loop --){
		Node nw, cur;
		vector<Node>p[N];		
		int ok = 0;
		
		scanf("%d", &n);
		while(n -- ){
			int s = 0;			// 记录和 
			for(int i = 0; i < 6; i ++){
				scanf("%d", &nw.num[i]);
				s += nw.num[i];
			}
			nw.s = s;			
			s %= N;				// 取余的原因是 s太大,数组开不了 
			
			if(!ok){
				for(int i = 0; i < p[s].size(); i ++){
					if(nw.s != p[s].at(i).s){			// 比较两朵雪花的边和是否一样 
						continue;
					}
					
					cur = p[s].at(i);
					ok = CMP(nw.num, cur.num);			// 比较边 
					if(ok){
						break;
					}
				}
				if(!ok){
					p[s].push_back(nw);
				}
			}
		}
		
		if(ok){
			printf("Twin snowflakes found.\n");
		}
		else{
			printf("No two snowflakes are alike.\n");
		}
	}
	
	return 0;
}


LDRA Testbed软件静态分析_操作指南 从本文起,将开始LDRA Testbed(TBrun)教程的系列文章,包括软件静态分析、单元测试、集成测试,以及基于Testbed的自动化工具开发、持续集成、常见问题解答等。LDRA公司是专业的软件测试工具与测试技术、咨询服务提供者,其总部位于英国利物浦。其旗舰产品Testbed/TBrun功能全面、易于使用,不仅适合于主机平台软件测试,同时适合于嵌入式软件测试。不仅能进行软件静态测试,还能进行软件单元测试、软件集成测试,在白盒测试领域运用比较广泛。 阅读详情

相关推荐

Elasticsearch连接中断:深入解析Connection reset by peer问题及优化策略

本文深入解析Elasticsearch连接中断问题,特别是Connection reset by peer错误的成因与解决方案。从TCP层的心跳机制到客户端与服务端的配置差异,详细介绍了网络不稳定、防火墙拦截等常见原因,并提供了六种优化策略,包括KeepAlive调整、TCP参数调优和智能重试机制等,帮助提升Elasticsearch连接的稳定性。

weixin_42546392的博客 410

poj3349找相同的雪花(哈希)

题目传送门题目大意:给你n个雪花,每个雪花的六个棱都有各自的长度,如果存在两片雪花的每条棱长度对应相同,则输出一句英文,如果不存在就输出另外一句英文,n和长度都比较大。思路:第一次真正接触哈希,查了题解,还没能通过这道题get到哈希的精髓。这道题是把雪花的六个长度加起来取模的值作为哈希值,然后把拥有相同哈希值的雪花归为一类,每一次输入新的雪花,就先找到它...

weixin_30622107的博客 486

详解岭回归与L2正则化

最小二乘法存在不可逆和病态问题,导致解析解不可计算或不稳定,岭回归是一种有效的解决方法,以损失无偏性来换取稳定解, 本文介绍详细介绍了岭回归的基本原理,并从L2正则化角度来进行了解释。

Luoyingfeng的博客 1万+

相同的雪花//和poj3349差不多

相同的雪花 时间限制:1000 ms | 内存限制:65535 KB 难度:4 描述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 re...

weixin_30553777的博客 265

Cesium 模拟飞机坠毁功能

Cesium 模拟飞机坠毁功能,粒子模拟

QQhelphelp的博客 1068

保姆级教程:用YOLOv8/9/10搞定仪表盘指针识别,附完整数据集和Python环境配置

本文提供了一份基于YOLOv8/v9/v10的仪表盘指针检测全流程指南,涵盖环境配置、数据集构建、模型选型、训练调优和部署落地等关键步骤。通过详细的代码示例和实战经验,帮助开发者高效解决工业视觉中的仪表盘检测难题,特别适合电力巡检、智能监控等应用场景。

weixin_29031057的博客 1335

NYOJ 130相同的雪花(哈希)

相同的雪花 时间限制:1000 ms  |  内存限制:65535 KB 难度:4 描述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 w

Merry_hj的博客 595

YOLOv13添加WDBB模块,map提升5.34!!,召回率提升6.55,准确率提升3.23

本文提出了一种基于YOLOv13改进的目标检测模型,通过引入WDBB模块显著提升了检测性能。实验结果表明,添加WDBB模块后,mAP提升11.34,召回率提升14.55,准确率提升3.23。文章详细介绍了模型移植方法,包括创建新的yaml配置文件、修改tasks.py和__init__.py文件,以及实现rep_block.py中的核心转换函数。改进后的模型通过深度卷积、通道注意力等模块优化了特征提取能力,同时保持了轻量化的特点。该工作为YOLO系列模型的性能提升提供了新的思路和技术实现。

FJN110的博客 2623

相同的雪花(哈希)

#include #include #include #include using namespace std; const int N=19373; const int M=100; int a[6]; int l[N]; int hash[N][M][6]; bool Judge(int *a, int *b) //判断雪花形状是否相同(即可以将对应的棱角重合) { int i

???的博客 835

【2026OD新机考】【不定滑窗】20260415-API请求日志去重分析【Py/Java/C++/C/JS/Go六种语言OD真题】【欧弟算法】全网注释最详细分类最全的华子OD真题题解

中找到所有的连续的相同元素,同时统计对应的连续相同元素对应的值的平均值。:当右指针为第一个元素(没有前一个元素),或者右指针对应的元素。某微服务系统的日志监控平台需分析API调用记录,日志含大量。相等,说明当前元素仍然属于同一个相同元素窗口,将当前元素值。中的所有元素均相等,并且计算窗口和情况即可。请实现一个函数,对给定的日志数据去重合并处理。位置,表示开启一个新的窗口,此时需要重置窗口和。,为了优化重复的请求记录,存储和后续分析需对。:对应的响应时间数组(毫秒)。重新置为当前右指针的元素值。

weixin_48157259的博客 111

Open3D 点到面的ICP配准算法【2025最新版】

点到面的ICP(python版本)博客长期更新,本文最近一次更新时间为:2025年2月2日,代码已更新至Open3D 0.18.0版本。

点云侠的博客 38万+

nyoj 130相同的雪花

题目大意:有多组测试数据,每组有多组数组,每组有六个数,判断是否含有两组一样的数据(六个数围成圈,看看能否重合)   思路:由于是判断一个集合中是否存在相同的元素,很容易就想到了SET:集合,而java里面给我们提供了HashSet这种数据 结构,HashSet也是依据hash表的思想设计的,不清楚的可以上网了解一下HashSet的用法,在判断是否含有两个相同的雪花的时候, 用一个for循

ghw_study的专栏 750

ADAS工作原理解析:如何通过智能技术提升驾驶安全

ADAS通过集成传感器、摄像头、雷达、SoC计算单元以及高效的数据融合技术,提供了一系列主动和被动安全功能,如自动刹车、车道保持、自适应巡航控制等。这些功能共同作用,不仅减少了交通事故的发生,还大幅提升了驾驶员的驾驶体验和安全性。随着技术的进步,ADAS的功能将越来越智能,最终迈向全自动驾驶的未来🚗💨。

weixin_43199439的博客 1148

nyoj 130 相同的雪花 【哈希】

相同的雪花 时间限制:1000 ms  |  内存限制:65535 KB 难度:4 描述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 w

shengweisong 1475

霍尼韦尔SoftMaster使用说明

霍尼韦尔SoftMaster使用说明

lwip-2.0.3

lwip是瑞典计算机科学院(SICS)的Adam Dunkels 开发的一个小型开源的TCP/IP协议栈。实现的重点是在保持TCP协议主要功能的基础上减少对RAM 的占用。

NYOJ 130 相同的雪花 (Hash)

题目130 题目信息 运行结果 本题排行 讨论区 相同的雪花 时间限制:1000 ms  |  内存限制:65535 KB 难度:4 描述You may have heard that no two snowflakes are alike. Your task is to write a program to determine wheth

MADE_Y 636

win10 跳过U8环境检测的IE WebControls.rar

win10 安装u8的时候 提示IE WebControls 不通过,这个工具可以欺骗u8的检查。 跳过U8环境检测的IE WebControls。提示导入失败后,重新检测通过。

nyoj130 相同的雪花(hash)

相同的雪花 时间限制:1000 ms | 内存限制:65535 KB 难度:4 描述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 progra...

angtongyou1893的博客 210

Data-Structures-and-Algorithm-Analysis-in-Java.pdf

作者: Weiss, Mark A. 出版社: Addison Wesley Data Structures and Algorithm Analysis in Java is an “advanced algorithms” book that fits between traditional CS2 and Algorithms Analysis courses. In the old ACM Curriculum Guidelines, this course was known as CS7. This text is for readers who want to learn good programming and algorithm analysis skills simultaneously so that they can develop such programs with the maximum amo...

NYOJ 130 相同的雪花(哈希)

思路:以每组的和为key对每片雪花进行哈希,然后从和相等的雪花里进行匹配。 注意雪花的匹配顺序可以顺时针也可以逆时针 #include #include #include #include using namespace std; const int MAXN = 100001;//最大数量 const int MOD = 100000;//最大编号 struct snow{

qq_35562816的博客 539

nyoj130 相同的雪花 排序 哈希表

相同的雪花时间限制:1000 ms  |  内存限制:65535 KB难度:4描述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 informati...

popcjz的博客 1443

NYOJ 题目130 相同的雪花 (哈希表)

相同的雪花 时间限制:1000 ms  |  内存限制:65535 KB 难度:4 描述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 w

LiQiyao的博客 847

NYOJ130 相同的雪花 【Hash】

相同的雪花 时间限制:1000 ms  |  内存限制:65535 KB 难度:4 描述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 w

长风的专栏 1781

nyoj-130-相同的雪花(hash)

题目链接 /* Name:NYOJ-130-相同的雪花 Copyright: Author: Date: 2018/4/14 15:13:39 Description: 将雪花各个分支上的值加起来,hash */ #include <iostream> #include <vector> #inc...

weixin_30746117的博客 189

nyoj 130 相同的雪花

存储雪花时可以把雪花的长度和一并存储起来,然后根据雪花的长度和做一个hash表。 判断2个雪花是否相同,就需要从雪花a和雪花b中找到雪花臂长度相同的2个位置。然后从这2个位置开始正序,逆序比较看是否能得到相同的序列。如果得不到,就从下一次长度相同的2个位置开始正序,倒序比较。 #include #include using namespace std; #define max_n 1000

q1916569889的博客 438

NYOJ130 相同的雪花

题目链接:http://acm.nyist.net/JudgeOnline/problem.php?pid=130 题目分析: 很明显这道题的数据量很大,所以不可能进行两两的判断,所以需要将可能相同的数据映射到一个集合中,然后在可能相同的数据集合中进行两两比较。如果两组数据六个数的和相同,那么就有可能是相同的雪花。但是六个数的和可能比较大,怎么把它们分开呢,那只能建立一个hash表,然后通过m

kay_zhyu的专栏 994

NYOJ 130 相同的雪花

相同的雪花 时间限制:1000 ms  |  内存限制:65535 KB 难度:4 描述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 w

柚的个人技术博客 1196

nyoj130 相同的雪花

相同的雪花 时间限制:1000ms | 内存限制:65535KB 难度:4 描述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 wil...

weixin_30542079的博客 125

nyoj 130 相同的雪花 || poj 3349 Snowflake Snow Snowflakes

题意:给定n片雪花(0 注意事项 1->雪花可以翻转、向左(右)移动,例如 1 2 3 4 5 6 4 3 2 1 6 5 是符合的。 2->直接枚举会超时,可以利用哈希表雪花离散化,不必一个一个查之前的雪花。 3->先查找,确定该雪花不存在再把该雪花插入哈希表,有两种方案,第一,把每个雪花转六下,分别在哈希里面找,然后翻转,把每个雪花转六下,分别在哈希里面找,最后在两种状态插

chen_lin111的专栏 849
上一篇: Win32API编程: 绘图练习--模拟时钟
下一篇: qduoj-36 自然数拆分 (高效深搜)
tbl00c
博客等级 码龄13年 21粉丝 91原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值