UVa 1594 - Ducci Sequence

没看清题号,TimeLimit。啊。  直接计算次数即可。

代码 :

import java.util.*;

public class Main1954 {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int t = scan.nextInt();
		while(t-- > 0) {
			int[] a = new int[16];
			int n = scan.nextInt();
			for(int i=0; i<n; i++) {
				a[i] = scan.nextInt();
			}
			int flag = 0;
			for(int k=0; k<200; k++) {
				int cnt = 0;
				int[] b = new int[16];
				for(int i=0; i<n; i++) {
					if(i == n-1)
						b[i] = Math.abs(a[n-1]-a[0]);
					else
					    b[i] = Math.abs(a[i] - a[i+1]);
					if(b[i] == 0)
						cnt ++;
				}
				if(cnt == n) {
                	flag = 1;
                	break;
                }
				a = b;
				//System.out.println(a[0] + " " + a[1] + " " + a[2] + " " + a[3]);
			}
			if(flag == 1)
				System.out.println("ZERO");
			else
				System.out.println("LOOP");

		}

	}

}
时间: 2024-11-06 19:53:07

UVa 1594 - Ducci Sequence的相关文章

紫书第五章训练 uva 1594 Ducci Sequence by crq

Description A Ducci sequence is a sequence of n-tuples of integers. Given an n-tuple of integers (a1, a2, ... , an), the next n-tuple in the sequence is formed by taking the absolute differences of neighboring integers: ( a1, a2, ... , an)  (| a1 - a

UVA 1594 - Ducci Sequence(暴力模拟)

想麻烦了.这题真的那么水啊..直接暴力模拟,1000次(看了网上的200次就能A)后判断是否全为0,否则就是LOOP: 1 #include <iostream> 2 #include <sstream> 3 #include <cstdio> 4 #include <cstring> 5 #include <cmath> 6 #include <string> 7 #include <vector> 8 #include

uva 1594 Ducci Sequence 哈希

用了一个滚动数组 转化为字符串哈希问题 复杂度不是很大所以用set直接搞 如果数据规模大一点的话考虑用vector实现链地址法 #include <cstdio> #include <cstring> #include <cstdlib> #include <iostream> #include <algorithm> #include <cmath> #include <set> #include <queue&g

Ducci Sequence解题报告

A Ducci sequence is a sequence of n-tuples of integers. Given an n-tuple of integers (a1, a2, ... , an), the next n-tuple in the sequence is formed by taking the absolute differences of neighboring integers: ( a1, a2, ... , an)  (| a1 - a2|,| a2 - a3

LIS UVA 10534 Wavio Sequence

题目传送门 1 /* 2 LIS:应用,nlogn的做法,首先从前扫到尾,记录每个位置的最长上升子序列,从后扫到头同理. 3 因为是对称的,所以取较小值*2-1再取最大值 4 */ 5 /************************************************ 6 * Author :Running_Time 7 * Created Time :2015-8-5 21:38:32 8 * File Name :UVA_10534.cpp 9 ***************

UVa 1584 Circular Sequence --- 水题

UVa 1584 题目大意:给定一个含有n个字母的环状字符串,可从任意位置开始按顺时针读取n个字母,输出其中字典序最小的结果 解题思路:先利用模运算实现一个判定给定一个环状的串以及两个首字母位置,比较二者字典序大小的函数, 然后再用一层循环,进行n次比较,保存最小的字典序的串的首字母位置,再利用模运算输出即可 /* UVa 1584 Circular Sequence --- 水题 */ #include <cstdio> #include <cstring> //字符串s为环状,

uva 10706 Number Sequence(找规律)

uva 10706 Number Sequence A single positive integer iis given. Write a program to find the digit located in the position iin the sequence of number groups S1S2-Sk. Each group Skconsists of a sequence of positive integer numbers ranging from 1 to k, w

Ducci Sequence

Ducci Sequence Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Description A Ducci sequence is a sequence of n-tuples of integers. Given an n-tuple of integers (a1, a2, ... , an), the next n-tuple in the sequence is formed by t

uva 1406 - A Sequence of Numbers(树状数组)

题目链接:uva 1406 - A Sequence of Numbers 题目大意:给定n个数,有两种操作: Q x:计算与2x取且不为0的数的个数 C x:每个数加上x 输出所有Q操作的和. 解题思路:因为x最大为15,所以开16个树状数组,fenx[x]记录的是每个数取模2x+1的情况,然后有一个add值标记总共加了多少.根据add值确定原先数的范围. #include <cstdio> #include <cstring> #include <algorithm>