Uva1594——Ducci Sequence
2015-11-07 23:11
274 查看
#include <iostream> #include <cmath> #include <cstring> using namespace std; int num[1005][20]; int n, m; bool zero, loop; bool check() { int i, j; for(i = 0; i < n; i++) { if(num[m][i] == 0) zero = true; else { zero = false; break; } } for(i = 0; i < m; i++) { for(j = 0; j < n; j++) { if(num[i][j] == num[m][j]) loop = true; else { loop = false; break; } } if(loop) break; } return (zero || loop); } int main() { int t, i; cin >> t; while(t--) { memset(num, 0, sizeof(num)); m = 0; zero = loop = false; cin >> n; for(i = 0; i < n; i++) cin >> num[m][i]; while(!check()) { m++; for(i = 0; i < n - 1; i++) num[m][i] = abs(num[m - 1][i] - num[m - 1][i + 1]); num[m][n - 1] = abs(num[m - 1][n - 1] - num[m - 1][0]); } if(zero) cout << "ZERO" << endl; else if(loop) cout << "LOOP" << endl; } return 0; }
相关文章推荐
- hdu5301Buildings
- LeetCode题解——Unique Binary Search Trees II
- UEFI下装Ubuntu Win10 双系统
- 【译】RabbitMQ:工作队列(Work Queue)
- IOS UIFont
- IOS开发UI篇--使用UICollectionView实现一个无限轮播的案例
- Android 系统UI状态栏设置
- java String / StringBuilder / StringBuffer 的使用
- Machine Learning week 1 quiz: Linear Algebra
- Machine Learning week 1 quiz: Linear Regression with One Variable
- UIDate详解
- Machine Learning week 1 quiz: Linear Regression with One Variable
- 【Codeforces Round 328 (Div 2)B】【找规律】The Monster and the Squirrel 正多边形连边分割块数
- uilongPressGestureRecognizer 的两次(多次)触发
- Machine Learning week 1 quiz: Introduction
- IOS7以上的UITableView顶部空白的问题
- [ecshop调试]ecshop 数据库查询缓存详解 有三种缓存,query_cache(数据库查询缓存)、static_cache(静态缓存)和cache(普通的缓存)
- 去掉 UITableView 顶部的多余空间
- [POJ1679]The Unique MST 次小生成树
- IOS UITextView