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 <set>
 9 #include <cctype>
10 #include <algorithm>
11 #include <cmath>
12 #include <deque>
13 #include <queue>
14 #include <map>
15 #include <stack>
16 #include <list>
17 #include <iomanip>
18
19 using namespace std;
20 #define INF 0x7fffffff
21 #define eps 1e-5
22 const int maxn = 20;
23 const int maxl = 1010;
24 int a[maxn], vis[maxn];
25 int n;
26 bool Judge(int k)
27 {
28     bool zero = false;
29     for(int i = 1; i <= n; i++)
30     {
31         if(a[i] && a[i] != k)
32             return 0;
33         if(!a[i])   zero = true;
34 //        printf("%d ", a[i]);
35     }
36     if(zero)    return 1;
37     else return 0;
38 }
39
40 int main()
41 {
42     int T;
43     scanf("%d", &T);
44     while(T--)
45     {
46         memset(vis, 0, sizeof(vis));
47         memset(a, 0, sizeof(a));
48         int cnt = 0;
49         scanf("%d", &n);
50         for(int i = 1; i <= n; i++)
51             scanf("%d", &a[i]);
52         a[n+1] = a[1];
53         int cur = 1, zero = 0;
54         while(cur <= 200)
55         {
56 //            cout << "----" <<endl;
57
58             for(int i = 1; i <= n; i++)
59             {
60                 a[i] = abs(a[i]-a[i+1]);
61             }
62             a[n+1] = a[1];
63             //cout << num << endl;
64             zero = 0;
65             for(int i = 1; i <= n; i++)
66                 if(!a[i])
67                     zero++;
68
69 //            cout << num << endl;
70             if(zero == n)
71             {
72                 printf("ZERO\n");
73                 zero = -1;
74                 break;
75             }
76             cur++;
77         }
78
79         if(zero != -1)     printf("LOOP\n");
80     }
81     return 0;
82 }
时间: 2024-12-08 17:44:46

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

没看清题号,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

uva 1594 Ducci Sequence 哈希

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

hdu 5641 King&#39;s Phone(暴力模拟题)

Problem Description In a military parade, the King sees lots of new things, including an Andriod Phone. He becomes interested in the pattern lock screen. The pattern interface is a 3×3 square lattice, the three points in the first line are labeled as

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

uva 467 - Synching Signals(暴力+数学)

题目连接:uva 467 - Synching Signals 题目大意:有n个红绿灯,给出红灯的时间t,那么该灯从0时刻开始就以2*t为周期绿黄红三灯交替,时间分别为t-5,5,t.问所这n个等从第一变为有一个灯不为绿灯开始,要多久才能变成所有的灯刚好都为绿灯.时间超过1小时输出unable to synch after one hour. 解题思路:一小时才3600秒,枚举秒数判断即可. #include <cstdio> #include <cstring> #include

uva 618 - Doing Windows(暴力+数学)

题目链接:uva 618 - Doing Windows 题目大意:给出电脑桌面的大小W和H,现在在桌面上有4个窗口,给出窗口的初始大小,问说能不能通过调整各个窗口的大小(长宽比例不能变)使得4个屏幕刚好占满整个屏幕,并且互相不覆盖. 解题思路:其实可以直接暴力出所有情况,不过细节比较多,而且要考虑所有的细节. 我的做法的是先将4个窗口缩小至最小的状态,然后枚举左下角的窗口, 有四种可能 蓝色部分为另外枚举的窗口,3,4种情况要分别保证说长.宽相等,然后S部分就是子问题. 所以用一个二进制数来表

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 ***************

HDU 4831 Scenic Popularity 暴力模拟

Scenic Popularity Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 340    Accepted Submission(s): 110 Problem Description 临近节日,度度熊们最近计划到室外游玩公园,公园内部包括了很多的旅游景点区和休息区,由于旅游景点很热门,导致景点区和休息区都聚集了很多人.所以度度熊