• UVA


    /*
      做这题时的心路历程其实挺有趣的
      
      一开始看到说Ducci序列最终要么全0,要么循环,我在想:
      
      要怎么判断循环呢?是不是还得记录下循环节什么的?是该用数组记录循环节吗?还是想要让我们利用STL来记录?
      
      后来又读了一次题,发现自己真是跑偏了,既然说全0或者循环,只要不是全0,最终就一定是循环嘛...我究竟是在纠结些什么 T^T 判断全0可不是比判断循环容易多了么?...
      
      此题其实没什么难度,但我当时有些一根筋...唉
    */


       

    #include <iostream>
    #include <cmath>
    #include <cstring>
    using namespace std;
    const int maxn = 20;
    int a[maxn];
    int n;
    
    bool all_zero()
    {
    	for (int i = 1; i <= n; i++)
    	if (a[i]) return 0;
    	return 1;
    }
    
    int solve() //全0返回0,循环返回1 
    {
    	int k, b[maxn]; // k 为循环次数 
    	for (k = 0; k <= 1000; k++)
    	{
    		for (int i = 1; i < n; i++)
    		{
    			b[i] = abs(a[i] - a[i + 1]);
    		}
    		b[n] = abs(a[n] - a[1]);
    		
    		memcpy(a + 1, b + 1, sizeof(int) * n);
    		
    		if (all_zero()) return 0;
    	}
    	return 1;
    }
    
    int main()
    {
    	int t;
    	cin >> t;
    	while (t--)
    	{
    		cin >> n;
    		for (int i = 1; i <= n; i++) cin >> a[i];
    		if (solve()) cout << "LOOP" << endl;
    		else cout << "ZERO" << endl;
    	}
    	return 0;
    }


  • 相关阅读:
    (四)rsync未授权访问
    (前言一)HTTP报文
    (一)会话固定攻击
    使用Burp、PhantomJS进行XSS检测
    win10配置环境变量
    java学习网站http://how2j.cn/
    镜像下载
    jQuery
    jQuery
    jQuery
  • 原文地址:https://www.cnblogs.com/mofushaohua/p/7789433.html
Copyright © 2020-2023  润新知