给定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. 基于Python下MySQL数据库驱动

    由于MySQL服务器以独立的进程运行,并通过网络对外服务,所以,需要支持Python的MySQL驱动来连接到MySQL服务器. 1.mysql-connector-python ​ mysql-con ...

  2. windows server 2019 2012 server 2022 无线网卡驱动安装报错,无线网卡驱动不能安装, inf服务安装段落无效

    windows server 2019 无线网络 服务安装段落无效 windows server 2019 无线网卡驱动安装报错,无线网卡驱动不能安装, inf服务安装段落无效 indows serv ...

  3. idea配置servlet项目找不到servlet jar包爆红【解决办法】

    1.看你的implements 后面的Servlet是否大写了 2.大部分原因就是缺少servlet-api jar包或者idea找不到jar包 如果你是爆红的,那么问题就在这里,点击-号,重新添加这 ...

  4. Codeforces Round 906 (Div. 2)A-E1

    A. Doremy's Paint 3 记数组中数的种类数为\(k\),当\(k=1\)时,答案为\(yes\):当\(k=2\)时,记两个种类的数的个数差为\(d\),当\(d≤1\)时,答案为\( ...

  5. Gradle构建微服务项目

    先说一下初衷把:为啥突然要用Gradle,公司后期自研项目都使用Gradle构建...... 1.下载安装 这个就不说了,网上大家搜索一下,配置一下环境变量即可 2.Groovy的一些语法Gradle ...

  6. Elasticsearch安装ik分词器,并配置扩展词典

    1.首先安装好elasticsearch,这里我用的是docker安装 2.去GitHub下载ik分词器,GitHub地址 3.下好了解压 4.使用远程客户端工具(我用的是finalShell)将整个 ...

  7. 从零玩转Yaip使用-cong-ling-wan-zhuan-yaip-shi-yong

    title: 从零玩转Yaip使用 date: 2021-07-16 15:47:17.624 updated: 2021-12-26 17:43:12.255 url: https://www.yb ...

  8. .NET周刊 【12月第3期 2023-12-24】

    国内文章 CAP 8.0 版本发布通告 - CAP 7岁生日快乐! https://www.cnblogs.com/savorboard/p/cap-8-0.html 今天宣布CAP 8.0版本正式发 ...

  9. 聊聊ChatGLM中P-tuning v2的应用

    论文PDF地址:https://arxiv.org/pdf/2110.07602.pdf 转载请备注出处:https://www.cnblogs.com/zhiyong-ITNote/ P-Tunin ...

  10. 文心一言 VS 讯飞星火 VS chatgpt (177)-- 算法导论13.3 6题

    六.用go语言,说明如果红黑树的表示中不提供父指针,应当如何有效地实现 RB-INSERT. 文心一言: 红黑树是一种自平衡的二叉搜索树,其中每个节点都包含一个颜色属性(红色或黑色),并且满足以下性质 ...