博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
IEEEXtreme Practice Community Xtreme9.0 - Digit Fun!
阅读量:7236 次
发布时间:2019-06-29

本文共 2686 字,大约阅读时间需要 8 分钟。

Xtreme9.0 - Digit Fun!

题目连接:

Description

An editorial, providing an approach to solve this problem, is presented at the bottom of this page.

Recurrence relations are an important tool for the computer scientist. Many algorithms, particularly those that use divide and conquer, have time complexities best modeled by recurrence relations. A recurrence relation allows us to recursively define a sequence of values by defining the nth value in terms of certain of its predecessors.

Many natural functions, such as factorials and the Fibonacci sequence, can easily be expressed as recurrences. The function of interest for this problem is described below.

Let |An| denote the number of digits in the decimal representation of An. Given any number A0, we define a sequence using the following recurrence:

Ai = |Ai-1| for i > 0

The goal of this problem is to determine the smallest positive i such that Ai = Ai-1.

Input

Input consists of multiple lines, each terminated by an end-of-line character. Each line (except the last) contains a value for A0, where each value is non-negative and no more than a million digits. The last line of input contains the word END.

Output

For each value of A0 given in the input, the program should output one line containing the smallest positive i such that Ai = Ai-1.

Sample Input

9999

0
1
9999999999
END

Sample Output

3

2
1
4

Hint

The first input value is A0 = 9999, resulting in A1 = |9999| = 4. Because 4 does not equal 9999, we find A2 = |A1| = |4| = 1. Since 1 is not equal to 4, we find A3 = |A2| = |1| = 1. A3 is equal to A2, making 3 the smallest positive i such that Ai = Ai-1.

The second input value is A0 = 0, resulting in A1 = |0| = 1. Because 0 does not equal 1, we find A2 = |A1| = |1| = 1. A2 is equal to A1, making 2 the smallest positive i such that Ai = Ai-1.

The third input value is A0 = 1, resulting in A1 = |1| = 1. A1 is equal to A0, making 1 the smallest positive i such that Ai = Ai-1.

The last input value is A0 = 9999999999, resulting in A1 = |9999999999| = 10. Because 10 does not equal 9999999999, we find A2 = |A1| = |10| = 2. Since 2 is not equal to 10, we find A3 = |A2| = |2| = 1. Since 1 is not equal to 2, we find A4 = |A3| = |1| = 1. A4 is equal to A3, making 4 the smallest positive i such that Ai = Ai-1.

题意

输入A[0]

定义F(x)=strlen(x)

A[i]=F(A[i-1])

求最小的i,使得A[i]=A[i-1]

题解

暴力水题

详细看代码

代码

#include
using namespace std;int last;string s;string get(string ss){ string tmp; int p=ss.size(); while(p) { tmp+=p%10+'0'; p/=10; } reverse(tmp.begin(),tmp.end()); return tmp;}int main(){ while(cin>>s) { if(s[0]=='E')break;//读到EOF时,break last=0; for(int i=0;i

转载地址:http://qnlfm.baihongyu.com/

你可能感兴趣的文章
常见浏览器兼容性问题与解决方式
查看>>
pfsense 2.2RC版本应用
查看>>
图像处理与机器视觉网络资源收罗——倾心大放送
查看>>
超过响应缓冲区限制
查看>>
Fiddler 实现手机的抓包
查看>>
浅谈C++多态性
查看>>
[翻译] GVUserDefaults
查看>>
Openlayer跨域问题解决
查看>>
Windows7下的免费虚拟机(微软官方虚拟机)
查看>>
shell中判断用法
查看>>
js的 new image()---转
查看>>
Hibernate Criterion
查看>>
AFNetworking 使用方法(2.0)
查看>>
React Canvas:高性能渲染 React 组
查看>>
Mono产品生命周期
查看>>
FetchType与FetchMode的区别
查看>>
GCD && Run Loops学习笔记
查看>>
SQLite Learning、SQL Query Optimization In Multiple Rule
查看>>
文件编码格式(转)
查看>>
开机黑屏 仅仅显示鼠标 电脑黑屏 仅仅有鼠标 移动 [已成功解决]
查看>>