Uva - 1594 - Ducci Sequence
2015-06-12 23:16
459 查看
水题,算出每次的结果,比较是否全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
- 【安全】requests和BeautifulSoup小试牛刀
- 文顶顶 iOS开发UI篇—手写控件,frame,center和bounds属性 iOS开发UI基础—手写控件,frame,center和bounds属性
- JDBC中PreparedStatement接口提供的execute、executeQuery和executeUpdate之间的区别及用法
- Using JavaFX UI Controls 12 Table View
- White spaces are required between publicId and systemId.异常
- Leetcode[96]-Unique Binary Search Trees
- CodedUI自动化测试及脱离VS独立运行
- QuickNewsLibs
- Marquee 跑马效果
- Linguist API 语言专家
- ios开发-UI进阶-核心动画-时钟动画小案例
- WordSequence API
- poj 2299 Ultra-QuickSort
- UITabBarController用法详解 - iOS - UI基础知识总结15
- Android异步处理三:Handler+Looper+MessageQueue深入详解
- Quick Reference:php5 Xdebug 生成Profiles
- Android异步处理二:使用AsyncTask异步更新UI界面
- Android异步处理一:使用Thread+Handler实现非UI线程更新UI界面
- iOS开发UI篇—0408控制器View的生命周期方法