给定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应用)的更多相关文章

  1. UVA 1594 Ducci Sequence(两极问题)

           Ducci Sequence Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu   D ...

  2. uva 1594 Ducci Sequence <queue,map>

    Ducci Sequence Description   A Ducci sequence is a sequence of n-tuples of integers. Given an n-tupl ...

  3. 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, · · · ...

  4. Uva - 1594 - Ducci Sequence

    水题,算出每次的结果,比较是否全0,循环1000次还不是全0则LOOP AC代码: #include <iostream> #include <cstdio> #include ...

  5. 【暴力模拟】UVA 1594 - Ducci Sequence

    想麻烦了.这题真的那么水啊..直接暴力模拟,1000次(看了网上的200次就能A)后判断是否全为0,否则就是LOOP: #include <iostream> #include <s ...

  6. 【UVA】1594 Ducci Sequence(纯模拟)

    题目 题目     分析 真的快疯了,中午交了一题WA了好久,最后发现最后一个数据不能加\n,于是这次学乖了,最后一组不输出\n,于是WA了好几发,最后从Udebug发现最后一组是要输出的!!!   ...

  7. UVa----------1594(Ducci Sequence)

    题目: 1594 - Ducci Sequence Asia - Seoul - 2009/2010A Ducci sequence is a sequence of n-tuples of inte ...

  8. Ducci Sequence UVA - 1594

      A Ducci sequence is a sequence of n-tuples of integers. Given an n-tuple of integers (a1,a2,···,an ...

  9. UVa 1584 Circular Sequence --- 水题

    UVa 1584 题目大意:给定一个含有n个字母的环状字符串,可从任意位置开始按顺时针读取n个字母,输出其中字典序最小的结果 解题思路:先利用模运算实现一个判定给定一个环状的串以及两个首字母位置,比较 ...

  10. Ducci Sequence

    Description   A Ducci sequence is a sequence of n-tuples of integers. Given an n-tuple of integers ( ...

随机推荐

  1. CART算法解密:从原理到Python实现

    本文深入探讨了CART(分类与回归树)算法的核心原理.实现方法以及应用场景.文章首先介绍了决策树的基础知识,然后详细解析了CART算法的工作机制,包括特征选择和树的构建.接着,通过Python和PyT ...

  2. mongodb c driver bson的嵌套访问与层次结构

    使用c访问mongodb,需要用到mongodb c driver.c++的driver也是基于c driver封装的. 在使用c driver访问mongodb时,需要与bson打交道,不过c dr ...

  3. 使用reposync工具将yum安装包保存到本地的方法

    使用reposync工具将yum安装包保存到本地的方法 版权声明:原创作品,谢绝转载!否则将追究法律责任. ----- 作者:kirin Anolis7/centos7 1.reposync 1.1. ...

  4. # [AI]多模态聚类能力助力AI完成自主意识测试

    引言 探讨人工智能是否能形成自我意识,是一个当前AI领域一个重要而又复杂的问题.随着深度学习和强化学习技术的不断进步,计算机在视觉识别.语音识别和控制机器人等方面都已取得长足的进展,模拟和超越人类的一 ...

  5. STM32外设:最小系统、低功耗模式

    最小系统 启动引脚 BOOT0.BOOT1:用于设置系统的启动方式 下载引脚 JTAG的IO:JTMS.JTCK.JTDI.JTDO.NJTRST SW的IO:SWDIO.SWCLK 硬件设计 NUC ...

  6. lua面向对象(类)和lua协同线程与协同函数、Lua文件I/O

    -- create a class Animal={name = "no_name" , age=0 } function Animal:bark(voice) print(sel ...

  7. [USACO2007FEB S] The Cow Lexicon S

    题目描述 Few know that the cows have their own dictionary with W (1 ≤ W ≤ 600) words, each containing no ...

  8. 【matlab混沌理论】1.2.洛伦兹吸引子

    ​Lorenz洛伦兹吸引子定义洛伦兹函数组后,通过ode45函数求解此微分方程方程. input: % Lorenz函数的洛伦兹吸引子 % 2.定义模型参数 sigma = 10; beta = 8/ ...

  9. 记录一下Stream流的一个坑

    List<String> list = new ArrayList<>(); boolean a = list.stream().anyMatch("a": ...

  10. LeetCode15:三数之和(双指针)

     解题思路:常规解法很容易想到O(n^3)的解法,但是,n最大为1000,很显然会超时. 如何优化到O(n^2),a+b+c =0,我们只需要判断 a+b的相反数是否在数组中出现,而且元素的取值范围在 ...