水题,算出每次的结果,比较是否全0,循环1000次还不是全0则LOOP

AC代码:

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <string>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <stack>
#include <queue>

using namespace std;

int ducci[20];

int main()
{
	int T;
	cin >> T;
	while (T--) {
		int n;
		cin >> n;
		// 记得清0
		memset(ducci, 0, sizeof(ducci));
		for (int i = 0; i < n; i++) {
			cin >> ducci[i];
		}
		int zero = 0, q = 0;
		// 循环1000次
		for (int i = 0; i < 1000; i++) {
			zero = 0;
			// 最后一个减去第一个的时候第一个已经改变了,所以先存储下来
			int t = ducci[0];
			for (int j = 0; j < n - 1; j++) {
				ducci[j] = abs(ducci[j] - ducci[j + 1]);
			}
			ducci[n - 1] = abs(ducci[n - 1] - t);
			// 判断是否全0
			for (int j = 0; j < n; j++) {
				if (ducci[j] == 0) {
					zero++;
				}
			}
			if (zero == n) {
				printf("ZERO\n");
				break;
			}
			if (i == 999) {
				printf("LOOP\n");
			}
		}

	}

	return 0;
}

Uva - 1594 - Ducci Sequence的更多相关文章

  1. uva 1594 Ducci Sequence <queue,map>

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

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

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

  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

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

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

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

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

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

  7. Ducci Sequence UVA - 1594

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

  8. LIS UVA 10534 Wavio Sequence

    题目传送门 题意:找对称的,形如:123454321 子序列的最长长度 分析:LIS的nlogn的做法,首先从前扫到尾,记录每个位置的最长上升子序列,从后扫到头同理.因为是对称的,所以取较小值*2-1 ...

  9. uva 10534 Wavio Sequence LIS

    // uva 10534 Wavio Sequence // // 能够将题目转化为经典的LIS. // 从左往右LIS记作d[i],从右往左LIS记作p[i]; // 则最后当中的min(d[i], ...

随机推荐

  1. SecureFX连接Linux后文件夹中文乱码问题解决(转)

    在使用SecureFX 连接Linux 时,发现文件夹显示乱码,一直尝试各种配置,现将方法整理一下!供大家参考! 首先在选项中设置字符编码为UTF-8 然后在全局选项中找到Securefx的配置文件 ...

  2. jquery easyui datagrid数据自动换行 panel用法

    nowrap:false 初始化panel $('#txtLeftPercent').panel({ title: '剩余权重:' + percent, height: 10, width: 180, ...

  3. FastDFS+Nginx安装配置

    下载相关包: libevent-2.0.22-stable.tar.gz => https://github.com/libevent/libevent/releases/download/re ...

  4. discuz全新安装升级,导入旧数据过程,顺便gbk转utf8

    由于discuz官方已经不更新了,现在又只有现成的utf8版本,没有gbk版本.我们原来使用的是gbk编码的,最近想改版,顺便升级一下,就索性把gbk也换成utf8吧,这样以后也方便,国际化嘛! 第一 ...

  5. Java8 按照类属性去重

    测试po package com.shiwulian.test.po; public class Person {private String id;private String name;priva ...

  6. 初步配置阿里云ECS服务器

    阿里云服务器配置记录01 购买阿里云学生服务器9.9元每月 创建ubuntu64位实例系统,注意必须添加安全组设置才可远程登入(设置课访问端口及IP范围 putty 软件在windows10下远程登入 ...

  7. django+uwsgi+nginx+postgresql备忘

    安装pg创建数据库xxx设置用户密码111111 apt-get install postgresql su - postgres psql create database xxx; alter us ...

  8. 安卓高级Fresco图片框架的时候

    Fresco:2015FaceBook推出的 及其强大 支持webp图片格式 和渐进式图片加载 中文文档 使用方法 引入依赖 点击查看具体教程 基本使用步骤 在布局中使用其标签 <com.fac ...

  9. 给PLSQL插上飞翔的翅膀-PLSQL优化

    60-80% of database performance issues are related to poorly performing SQL,60-80%的数据库性能问题要归结于生产中糟糕的S ...

  10. self关键字

    self关键字 self:当前类/对象的指针(指向当前对象/方法调用者) 作用1 当类里有变量名和成员变量名一样的时候,可以使用self区分 例: 我们写一个人的类,有一个年龄属性,在get方法里,我 ...