给定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. .net 温故知新【13】:Asp.Net Core WebAPI 缓存

    一.缓存 缓存指在中间层中存储数据的行为,该行为可使后续数据检索更快. 从概念上讲,缓存是一种性能优化策略和设计考虑因素. 缓存可以显著提高应用性能,方法是提高不常更改(或检索成本高)的数据的就绪性. ...

  2. CSS+HTML初学跟踪项目记录笔记【防丢失】(文章发布系统)二【鸽了】

    贴上源代码 <%@ page language="java" contentType="text/html; charset=UTF-8" pageEnc ...

  3. 黑客玩具入门——5、继续Metasploit

    1.利用FTP漏洞并植入后门 实验靶机:Metasploitable2. 实践: 使用nmap扫描目标靶机 nmap -sV xxx.xxx.xxx.xxx(目标ip) 生成linux系统后门 msf ...

  4. iframe嵌入报表滚动条问题

    当在iframe中嵌入报表时,可能会遇到滚动条的问题.下面是一个详细的介绍 1. 了解iframe: - iframe是HTML中的元素,用于在当前页面中嵌入另一个页面. - 嵌入报表时常使用ifra ...

  5. httpclients 和 okhttp 区别

    HttpClient使用介绍使用HttpClient发送请求主要分为以下几步骤: 创建 CloseableHttpClient对象或CloseableHttpAsyncClient对象,前者同步,后者 ...

  6. java-图片添加水印

    前言:    需求:需要在图片中添加水印,防止盗用   优缺点:     优点:保护版权,防止盗用     缺点 可能会影响图片的视觉效果:如果水印过大或过醒目,可能会影响图片的视觉效果. 可能会增加 ...

  7. 数据库的连接用Java

    第一步注册驱动 Class.forName("com.mysql.cj.jdbc.Driver"); 第二步创建用户密码,和具体的url static String name = ...

  8. vue-project-------(模板语法,属性绑定)

    <template> <h3>模板语法</h3> <p>{{msg}}</p> <p>{{number+1}}</p> ...

  9. 这些 git 高级命令你知道几个

    大家好,我是 dom 哥.今天给大家分享几个 git 的高级应用. git 是目前最流行的版本控制工具.git 玩的 6 不 6,轻则影响自己的开发幸福指数 ,重则影响下班时间 .本文介绍一些日常开发 ...

  10. windows10更新文件存在哪里

    windows10更新文件存在哪里windows10更新文件存在哪里 电脑系统每次更新都会有相应的更新文件,很多win10用户都想知道电脑更新文件存在哪里,其实这个很好找的. 你先双击此电脑进入,然后 ...