【暴力模拟】UVA 1594 - Ducci Sequence
想麻烦了。这题真的那么水啊。。直接暴力模拟,1000次(看了网上的200次就能A)后判断是否全为0,否则就是LOOP;
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <string>
#include <vector>
#include <set>
#include <cctype>
#include <algorithm>
#include <cmath>
#include <deque>
#include <queue>
#include <map>
#include <stack>
#include <list>
#include <iomanip> using namespace std;
#define INF 0x7fffffff
#define eps 1e-5
const int maxn = ;
const int maxl = ;
int a[maxn], vis[maxn];
int n;
bool Judge(int k)
{
bool zero = false;
for(int i = ; i <= n; i++)
{
if(a[i] && a[i] != k)
return ;
if(!a[i]) zero = true;
// printf("%d ", a[i]);
}
if(zero) return ;
else return ;
} int main()
{
int T;
scanf("%d", &T);
while(T--)
{
memset(vis, , sizeof(vis));
memset(a, , sizeof(a));
int cnt = ;
scanf("%d", &n);
for(int i = ; i <= n; i++)
scanf("%d", &a[i]);
a[n+] = a[];
int cur = , zero = ;
while(cur <= )
{
// cout << "----" <<endl; for(int i = ; i <= n; i++)
{
a[i] = abs(a[i]-a[i+]);
}
a[n+] = a[];
//cout << num << endl;
zero = ;
for(int i = ; i <= n; i++)
if(!a[i])
zero++; // cout << num << endl;
if(zero == n)
{
printf("ZERO\n");
zero = -;
break;
}
cur++;
} if(zero != -) printf("LOOP\n");
}
return ;
}
【暴力模拟】UVA 1594 - Ducci Sequence的更多相关文章
- UVA 1594 Ducci Sequence(紫书习题5-2 简单模拟题)
A Ducci sequence is a sequence of n-tuples of integers. Given an n-tuple of integers (a1, a2, · · · ...
- UVA 1594 Ducci Sequence(两极问题)
Ducci Sequence Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu D ...
- uva 1594 Ducci Sequence <queue,map>
Ducci Sequence Description A Ducci sequence is a sequence of n-tuples of integers. Given an n-tupl ...
- Uva - 1594 - Ducci Sequence
水题,算出每次的结果,比较是否全0,循环1000次还不是全0则LOOP AC代码: #include <iostream> #include <cstdio> #include ...
- 【UVA】1594 Ducci Sequence(纯模拟)
题目 题目 分析 真的快疯了,中午交了一题WA了好久,最后发现最后一个数据不能加\n,于是这次学乖了,最后一组不输出\n,于是WA了好几发,最后从Udebug发现最后一组是要输出的!!! ...
- UVa----------1594(Ducci Sequence)
题目: 1594 - Ducci Sequence Asia - Seoul - 2009/2010A Ducci sequence is a sequence of n-tuples of inte ...
- Ducci Sequence UVA - 1594
A Ducci sequence is a sequence of n-tuples of integers. Given an n-tuple of integers (a1,a2,···,an ...
- [刷题]算法竞赛入门经典(第2版) 5-2/UVa1594 - Ducci Sequence
书上具体所有题目:http://pan.baidu.com/s/1hssH0KO 代码:(Accepted,20 ms) //UVa1594 - Ducci Sequence #include< ...
- UVa 1584 Circular Sequence --- 水题
UVa 1584 题目大意:给定一个含有n个字母的环状字符串,可从任意位置开始按顺时针读取n个字母,输出其中字典序最小的结果 解题思路:先利用模运算实现一个判定给定一个环状的串以及两个首字母位置,比较 ...
随机推荐
- 设备扩展(DEVICE_EXTENSION)
原文链接:http://blog.csdn.net/hazy/article/details/481705 WDM中的结构 ---设备扩展 设备扩展(DEVICE_EXTENSION)是与设备对象 ...
- KMP算法详解 --从july那学的
KMP代码: int KmpSearch(char* s, char* p) { ; ; int sLen = strlen(s); int pLen = strlen(p); while (i &l ...
- codeforce 605B. Lazy Student
题意:n点,m条边.m条边里面标记为1的最小生成树的边,0为非最小生成树的边.给了每条边的权,如果能构成一个最小生成树则输出图,否则-1. 思路:先按权值小,为生成数边的顺序排序.(根据kruskal ...
- BNUOJ-26476 Doorman 贪心
题目链接:http://www.bnuoj.com/bnuoj/problem_show.php?pid=26476 题意:给一个字符序列,比如MWMMW,每次可以取前面两个中的一个,取出来后,取出来 ...
- eclipse配置struts.xml自动提示
a)window – preferences – xml - xml catalog –> add b)选择key type为URI c)key: http://struts.apache.o ...
- thinking in java Generics Latent typing
The beginning of this chapter introduced the idea of writing code that can be applied as generally a ...
- ORA-01078, LRM-00123错误处理
创建spfile时, 或者在nomount时, 出现下面的问题: SQL> create spfile from pfile; create spfile from pfile * ERROR ...
- Android 添加、移除和判断 桌面快捷方式图标
思路: Launcher为了应用程序能够定制自己的快捷图标,就注册了一个 BroadcastReceiver 专门接收其他应用程序发来的快捷图标定制信息.所以只需要根据该 BroadcastRecei ...
- 磐石加密狗NT88管理层API
磐石加密狗NT88管理层API 直接贴代码了 1 using System; 2 using System.Collections.Generic; 3 using System.Text; 4 ...
- JS单词形式的运算符
1.void 运算表达式并忽略其返回值,比如void (1+2),void (0) <html> <head> <meta http-equiv="conten ...