UVA - 1594 :Ducci Sequence (set应用)
给定n元组(a1,a2,...,an),ai均为整数,得到下一个序列为(|a1-a2|,|a2-a3|,...,|an-a1|),如此循环下去,必定会出现全零序列或重复序列。
现要求判断给定序列是全零序列还是重复序列(有趣的Ducii结果)
思路分析
用vector模拟元组序列,set<vector<int>>用于元组序列判重,完成重复序列发现
#include<bits/stdc++.h>
using namespace std;
int main() {
freopen("in.txt", "r", stdin);
int t, n;
cin >> t;
while (t--) {
cin >> n;
vector<int>a(n), b(n), zero(n, 0);
for (int i = 0; i < n; ++i) cin >> a[i];
set<vector<int>>_set;
int flag = 0;
while (!flag) {
if (a == zero) flag = 1;
else if (_set.find(a) != _set.end()) flag = 2;
else {
_set.insert(a);
for (int i = 0; i < n; i++) b[i] = abs(a[i] - a[(i + 1) % n]); // ducci下一个序列
a = b;
}
}
cout << (flag == 1 ? "ZERO\n" : "LOOP\n");
}
return 0;
}
UVA - 1594 :Ducci Sequence (set应用)的更多相关文章
- UVA 1594 Ducci Sequence(两极问题)
Ducci Sequence Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu D ...
- uva 1594 Ducci Sequence <queue,map>
Ducci Sequence Description A Ducci sequence is a sequence of n-tuples of integers. Given an n-tupl ...
- UVA 1594 Ducci Sequence(紫书习题5-2 简单模拟题)
A Ducci sequence is a sequence of n-tuples of integers. Given an n-tuple of integers (a1, a2, · · · ...
- Uva - 1594 - Ducci Sequence
水题,算出每次的结果,比较是否全0,循环1000次还不是全0则LOOP AC代码: #include <iostream> #include <cstdio> #include ...
- 【暴力模拟】UVA 1594 - Ducci Sequence
想麻烦了.这题真的那么水啊..直接暴力模拟,1000次(看了网上的200次就能A)后判断是否全为0,否则就是LOOP: #include <iostream> #include <s ...
- 【UVA】1594 Ducci Sequence(纯模拟)
题目 题目 分析 真的快疯了,中午交了一题WA了好久,最后发现最后一个数据不能加\n,于是这次学乖了,最后一组不输出\n,于是WA了好几发,最后从Udebug发现最后一组是要输出的!!! ...
- UVa----------1594(Ducci Sequence)
题目: 1594 - Ducci Sequence Asia - Seoul - 2009/2010A Ducci sequence is a sequence of n-tuples of inte ...
- Ducci Sequence UVA - 1594
A Ducci sequence is a sequence of n-tuples of integers. Given an n-tuple of integers (a1,a2,···,an ...
- UVa 1584 Circular Sequence --- 水题
UVa 1584 题目大意:给定一个含有n个字母的环状字符串,可从任意位置开始按顺时针读取n个字母,输出其中字典序最小的结果 解题思路:先利用模运算实现一个判定给定一个环状的串以及两个首字母位置,比较 ...
- Ducci Sequence
Description A Ducci sequence is a sequence of n-tuples of integers. Given an n-tuple of integers ( ...
随机推荐
- ABAP 自定义附件
SWO1 关键字 *------------------------------------------------------------* REPORT ZTEST_CSW1. *TABLES ...
- 如何用MySQL快速导入sql数据?
在 MySQL 中,可以使用多种方法来快速导入 SQL 数据.以下是一些常用的方法和技巧,以帮助你在 MySQL 中快速导入大量的 SQL 数据. 1. 使用 mysql 命令行工具 - 将 SQL ...
- jmeter编写java脚本
jmeter开发java脚本主要的依赖包有三个如下图 步骤1 :打开idea,创建一个project,导入上图依赖包 步骤2:创建一个类,继承AbstractJavaSamplerClient类,并实 ...
- springcloud 实体类使用@Builder@AllArgsConstructor两个注解后查询执行操作时报数据转换异常
异常日志如下: org.springframework.jdbc.UncategorizedSQLException: Error attempting to get column 'DATA_SOU ...
- 图扑物联 | WEB组态可视化软件
01什么是组态? 组态的概念来自于20世纪70年代中期出现的第一代集散控制系统(Distributed Control System),可理解为"配置"."设置" ...
- 【scikit-learn基础】--『监督学习』之 岭回归
岭回归(Ridge Regression)是一种用于处理共线性数据的线性回归改进方法.和上一篇用基于最小二乘法的线性回归相比,它通过放弃最小二乘的无偏性,以损失部分信息.降低精度为代价来获得更实际和可 ...
- Centos8 硬盘挂载
查看硬盘分区状况 fdisk -l 可以看到数据盘 /dev/vdb 大小为 10Gb,目前还没有进行分区. 对 /dev/vdb 资源盘进行分区 fdisk /dev/vdb //根据提示输入信息: ...
- STM32CubeMX教程2 GPIO输出 - 点亮LED灯
1.准备材料 开发板(STM32F407G-DISC1) ST-LINK/V2驱动 STM32CubeMX软件(Version 6.10.0) keil µVision5 IDE(MDK-Arm) 2 ...
- 听说生鲜领军企业k8s集群都上云了,鱼会飞了?
在这个中秋都和国庆在一起的双节里,我们的小明还在辛辛苦苦的找工作,听说他经历了一段"难忘"的面试. 小明面对着面试官的"层层拷问",游刃有余的化解了这些难题. ...
- Netty 组件介绍
BootStrap Netty 中的 BootStrap 分为两种:一种是客户端的 BootStrap:一种是服务端的 ServerBootStrap. 客户端的 BootStrap 初始化客户端,该 ...