Iterated Difference

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 786    Accepted Submission(s): 505

Problem Description
You
are given a list of N non-negative integers a(1), a(2), ... , a(N). You
replace the given list by a new list: the k-th entry of the new list is
the absolute value of a(k) - a(k+1), wrapping around at the end of the
list (the k-th entry of the new list is the absolute value of a(N) -
a(1)). How many iterations of this replacement are needed to arrive at a
list in which every entry is the same integer?

For example, let N = 4 and start with the list (0 2 5 11). The successive iterations are:

2 3 6 11
1 3 5 9
2 2 4 8
0 2 4 6
2 2 2 6
0 0 4 4
0 4 0 4
4 4 4 4
Thus, 8 iterations are needed in this example.

 
Input
The
input will contain data for a number of test cases. For each case,
there will be two lines of input. The first line will contain the
integer N (2 <= N <= 20), the number of entries in the list. The
second line will contain the list of integers, separated by one blank
space. End of input will be indicated by N = 0.
 
Output
For
each case, there will be one line of output, specifying the case number
and the number of iterations, in the format shown in the sample output.
If the list does not attain the desired form after 1000 iterations,
print 'not attained'.
 
Sample Input
4
0 2 5 11
5
0 2 5 11 3
4
300 8600 9000 4000
16
12 20 3 7 8 10 44 50 12 200 300 7 8 10 44 50
3
1 1 1
4
0 4 0 4
0
 
Sample Output
Case 1: 8 iterations
Case 2: not attained
Case 3: 3 iterations
Case 4: 50 iterations
Case 5: 0 iterations
Case 6: 1 iterations
 
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define maxn 100
const int inf=0x7fffffff; //无限大
ll n[maxn];
ll n2[maxn];
int N;
int main()
{
int cas=;
int N;
while(cin>>N)
{
if(N==)
break;
for(int i=;i<N;i++)
{
cin>>n[i];
n2[i]=n[i];
}
ll ans=;
int flag=;
int kiss=;
for(int i=;i<N;i++)
{
if(n[i]!=n[(i+)%N])
{
kiss=;
break;
}
if(i==N-)
kiss=;
}
while(kiss==&&ans<=)
{ for(int i=;i<N;i++)
{
n[i]=fabs(n2[i]-n2[(i+)%N]);
}
for(int i=;i<N;i++)
{
n2[i]=n[i];
}
ans++;
for(int i=;i<N;i++)
{
if(n[i]!=n[(i+)%N])
{
kiss=;
break;
}
if(i==N-)
kiss=;
}
}
if(kiss==)
printf("Case %d: %d iterations\n",cas,ans);
else
printf("Case %d: not attained\n",cas);
cas++;
}
return ;
}
 

HDU 3161 Iterated Difference 暴力的更多相关文章

  1. HDU - 5936: Difference(暴力:中途相遇法)

    Little Ruins is playing a number game, first he chooses two positive integers yy and KK and calculat ...

  2. HDU 6628 permutation 1 (暴力)

    2019 杭电多校 5 1005 题目链接:HDU 6628 比赛链接:2019 Multi-University Training Contest 5 Problem Description A s ...

  3. hdu 5461 Largest Point 暴力

    Largest Point Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid= ...

  4. hdu 5762 Teacher Bo 暴力

    Teacher Bo 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5762 Description Teacher BoBo is a geogra ...

  5. Smallest Difference(暴力全排列)

    Smallest Difference Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 10387   Accepted: 2 ...

  6. HDU 1333 基础数论 暴力

    定义一种数位simth数,该数的各位之和等于其所有质因子所有位数字之和,现给出n求大于n的最小该种数,n最大不超过8位,那么直接暴力就可以了. /** @Date : 2017-09-08 14:12 ...

  7. HDU 4618 Palindrome Sub-Array 暴力

    Palindrome Sub-Array 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=4618 Description A palindrome s ...

  8. HDU 2089 不要62 | 暴力(其实是个DP)

    题目: http://acm.hdu.edu.cn/showproblem.php?pid=2089 题解: 暴力水过 #include<cstdio> #include<algor ...

  9. HDU 6115 Factory LCA,暴力

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6115 题意:中文题面 分析:直接维护LCA,然后暴力枚举集合维护答案即可. #include < ...

随机推荐

  1. Codeforces Round #504 E. Down or Right

    Codeforces Round #504 E. Down or Right 题目描述:交互题. 有一个\(n \times n\)的方阵,有一些格子是障碍,从\((1, 1)\)出发,只能向右向下走 ...

  2. 【日记】NOIP2018

    day-2: 最后一次走出机房,刚下过几天的雨,感受到的是彻骨的寒意.下午离开教室,跟班主任请了接下来几天的假,班主任斜视了我一眼,哼了一声,确认了一下,不再理会我了.班里的同学或是忙着自己的作业,或 ...

  3. Django BoundField

    一.BoundField from django.forms.boundfield import BoundField BoundField是一个将字段添加数据的一个类,给对应的form字段封装上数据 ...

  4. 使用qshell备份七牛云存储文件

    qshell是利用七牛文档上公开的API实现的一个方便开发者测试和使用七牛API服务的命令行工具.我们可以利用它来将七牛云上存储的文件备份到本地. 它提供Mac OSX, Linux, Windows ...

  5. 洛谷P2661信息传递

    传送门啦 一个人要想知道自己的生日,就意味着信息的传递是成环的,因为每轮信息只能传递一个人,传递的轮数就等于环的大小 环的大小就等于环中的两个点到第三个点的距离之和加一,我们就可以在使用并查集时,维护 ...

  6. 四B象限图

  7. 20165203 预备作业3 Linux安装及学习

    一.安装虚拟机 1.下载问题:当自己在虚拟机上下载ubuntu时,总是下载好长时间,而且最后下载失败,这让我很苦恼. 解决方案:求助同学后,同学给了我一个中文版官网的网址http://cn.ubunt ...

  8. C#socket编程序(一)

    在讲socket编程之前,我们先看一下最常用的一些类和方法,相信这些能让你事半功倍. 一.IP地址操作类 1.IPaddress类 a.在该类中有一个 parse()方法,能够把点分十进制IP地址 转 ...

  9. InterSystems Ensemble学习笔记(一) Ensemble介绍及安装

    系列目录 InterSystems Ensemble学习笔记(一) Ensemble介绍及安装InterSystems Ensemble学习笔记(二) Ensemble创建镜像, 实现自动故障转移 一 ...

  10. Loadrunner参数化如何在记事本中将参数值显示超过100个参数值

    Loadrunner参数化如何在记事本中将参数值显示超过100个参数值 1.loadrunner的参数值没有最大的限度, 可以修改C:\Program Files\HP\LoadRunner\conf ...