HDU 3161 Iterated Difference 暴力
Iterated Difference
Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 786    Accepted Submission(s): 505
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 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.
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'.
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
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 暴力的更多相关文章
- HDU - 5936: Difference(暴力:中途相遇法)
		Little Ruins is playing a number game, first he chooses two positive integers yy and KK and calculat ... 
- HDU 6628 permutation 1 (暴力)
		2019 杭电多校 5 1005 题目链接:HDU 6628 比赛链接:2019 Multi-University Training Contest 5 Problem Description A s ... 
- hdu 5461 Largest Point 暴力
		Largest Point Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid= ... 
- hdu 5762 Teacher Bo 暴力
		Teacher Bo 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5762 Description Teacher BoBo is a geogra ... 
- Smallest Difference(暴力全排列)
		Smallest Difference Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 10387 Accepted: 2 ... 
- HDU 1333 基础数论 暴力
		定义一种数位simth数,该数的各位之和等于其所有质因子所有位数字之和,现给出n求大于n的最小该种数,n最大不超过8位,那么直接暴力就可以了. /** @Date : 2017-09-08 14:12 ... 
- HDU 4618 Palindrome Sub-Array 暴力
		Palindrome Sub-Array 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=4618 Description A palindrome s ... 
- HDU 2089 不要62 | 暴力(其实是个DP)
		题目: http://acm.hdu.edu.cn/showproblem.php?pid=2089 题解: 暴力水过 #include<cstdio> #include<algor ... 
- HDU 6115 Factory LCA,暴力
		题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6115 题意:中文题面 分析:直接维护LCA,然后暴力枚举集合维护答案即可. #include < ... 
随机推荐
- git summary
			Git 使用经验 缘起 一直想写一篇博文,记录我在使用git时遇到的问题以及解决办法.由于项目忙,偶尔的记录不连续,不成系统.今天有时间记录下来,方便自己以后查看. git 简介及其优势 简单来说,g ... 
- Windows 8 应用程序前后台切换事件监听
			在一些情况下,我们需要监听应用程序切换到后台或者从后台切换至前台的事件,从而进行相关处理操作.支付宝应用锁屏(IOS,Android平台)的处理中就需要监听此事件,在用户将应用切换至后台一段时间后再切 ... 
- Bugfree3.0.4 Linux环境安装指南
			一. 安装apache服务器 1. 检查apache服务器是否安装 service httpd status 2. 如提示未被识别的服务,则表明组件未安装,需手动安装 yum install http ... 
- maven学习--生命周期
			clean --清理项目 default --构建项目(最核心) ===========compile , test , package , install site --生成项目站点 
- python之uinttest单元测试框架
			unittest,是python中针对单元测试的一个测试框架 相当于python版的junit 简单举个例子: 如图,使用时,测试类需要继承单元测试TestCase这个类 必须要有setUp()和te ... 
- git —— Feature分支
			添加新功能时,新建feature分支 分支上开发完成后,再进行合并.最后删除feature分支 $ git checkout -b feature-vulcan 开发完毕后,切换回添加的分支,进行合并 ... 
- 使用html+css+js实现3D相册
			使用html+css+js实现3D相册,快来上传的照片吧 效果图: 代码如下,复制即可用: <!DOCTYPE html> <html lang="en"> ... 
- 详解MySQL大表优化方案
			单表优化 除非单表数据未来会一直不断上涨,否则不要一开始就考虑拆分,拆分会带来逻辑.部署.运维的各种复杂度,一般以整型值为主的表在千万级以下,字符串为主的表在五百万以下是没有太大问题的.而事实上很多时 ... 
- PreparedStatement 查询 In 语句 setArray 等介绍。
			ps = conn.prepareStatement("SELECT tid,jdp_response FROM jdp_tb_trade WHERE tid IN (?) ORDER BY ... 
- Eclipse 配置语言环境
			一.打开https://www.eclipse.org/babel/downloads.php 选择一下版本的Bable(通天塔) 选择 解压 打开Eclipse 软件 选择Help->inst ... 
