A. Reachable Numbers

Let's denote a function f(x)f(x) in such a way: we add 11 to xx, then, while there is at least one trailing zero in the resulting number, we remove that zero. For example,

  • f(599)=6f(599)=6: 599+1=600→60→6599+1=600→60→6;
  • f(7)=8f(7)=8: 7+1=87+1=8;
  • f(9)=1f(9)=1: 9+1=10→19+1=10→1;
  • f(10099)=101f(10099)=101: 10099+1=10100→1010→10110099+1=10100→1010→101.

We say that some number yy is reachable from xx if we can apply function ff to xx some (possibly zero) times so that we get yy as a result. For example, 102102 is reachable from 1009810098 because f(f(f(10098)))=f(f(10099))=f(101)=102f(f(f(10098)))=f(f(10099))=f(101)=102; and any number is reachable from itself.

You are given a number nn; your task is to count how many different numbers are reachable from nn.

Input

The first line contains one integer nn (1≤n≤1091≤n≤109).

Output

Print one integer: the number of different numbers that are reachable from nn.

 #include<bits/stdc++.h>
#include<set>
using namespace std;
typedef long long ll;
int f(int x) {
while((x+)%==) {
x=(x+)/-;
}
x=x+;
return x;
}
int main() {
ll n,cnt=;
bool flag=true;
set <int > d;
cin>>n;
ll a=n;
d.insert(a);
while(flag) {
a=f(a);
cnt++;
for(set<int>::iterator it=d.begin(); it!=d.end(); it++) {
if(*it==a) {
cout<<cnt;
return ;
}
}
d.insert(a);
}
}

思路分析:先编写去尾数0的函数,然后将每次调用函数后的值存入集合,遍历集合,要新加入集合的数等于集合内有的数就退出并同时输出集合元素个数。

Codeforces1157A(A题)Reachable Numbers的更多相关文章

  1. 【转】POJ百道水题列表

    以下是poj百道水题,新手可以考虑从这里刷起 搜索1002 Fire Net1004 Anagrams by Stack1005 Jugs1008 Gnome Tetravex1091 Knight ...

  2. 老年OIer的Python实践记—— Codeforces Round #555 (Div. 3) solution

    对没错下面的代码全部是python 3(除了E的那个multiset) 题目链接:https://codeforces.com/contest/1157 A. Reachable Numbers 按位 ...

  3. Codeforces Round #555 (Div. 3)[1157]题解

    不得不说这场div3是真的出的好,算得上是从我开始打开始最有趣的一场div3.因为自己的号全都蓝了,然后就把不经常打比赛的dreagonm的号借来打这场,然后...比赛结束rank11(帮dreago ...

  4. Codeforces Round #555 (Div. 3) 解题报告

    A.Reachable Numbers 题意: 给定操作f(x):将x加1,删去得到的数的所有末尾0,如f(10099)=10099+1=10100→1010→101.现在给定一个数n,对n进行无限次 ...

  5. ACM学习

    转:ACM大量习题题库   ACM大量习题题库 现在网上有许多题库,大多是可以在线评测,所以叫做Online Judge.除了USACO是为IOI准备外,其余几乎全部是大学的ACM竞赛题库.   US ...

  6. ACM竞赛常用STL(一)

    全排列函数next_permutation STL 中专门用于排列的函数(可以处理存在重复数据集的排列问题) 头文件:#include <algorithm> using namespac ...

  7. POJ题目细究

    acm之pku题目分类 对ACM有兴趣的同学们可以看看 DP:  1011   NTA                 简单题  1013   Great Equipment     简单题  102 ...

  8. CodeForces Round #555 Div.3

    A. Reachable Numbers 代码: #include <bits/stdc++.h> using namespace std; ; int N; set<int> ...

  9. (转载)ACM训练计划,先过一遍基础再按此拼搏吧!!!!

    ACM大量习题题库 ACM大量习题题库 现在网上有许多题库,大多是可以在线评测,所以叫做Online Judge.除了USACO是为IOI准备外,其余几乎全部是大学的ACM竞赛题库. USACO ht ...

随机推荐

  1. Linux 高 wio 分析

    High IO wait Table of Contents 1. 现象 2. 分析 2.1. iotop或者pidstat 2.1.1. iotop 2.1.2. pidstat 2.2. 脚本 2 ...

  2. java中FutureTask的使用

    文章目录 FutureTask简介 Callable和Runnable的转换 以Runnable运行 java中FutureTask的使用 FutureTask简介 FutureTask是java 5 ...

  3. Scala教程之:Enumeration

    Enumeration应该算是程序语言里面比较通用的一个类型,在scala中也存在这样的类型, 我们看下Enumeration的定义: abstract class Enumeration (init ...

  4. 利用requests, beautifulsoup包爬取股票信息网站

    这是第一次用requests, beautifulsoup实现爬虫,此次爬取的是一个股票信息网站:http://www.gupiaozhishi.net.cn. 实现非常简单,只是为了demo使用的数 ...

  5. varnish4.0缓存代理配置

    防伪码:你必须非常努力,才能看起来毫不费力. 一.varnish原理: 1)Varnish简介: varnish缓存是web应用加速器,同时也作为http反向缓存代理.你可以安装varnish在任何h ...

  6. Netty随记之ChannelInboundHandlerAdapter、SimpleChannelInboundHandler

    ChannelInboundHandlerAdapter ChannelInboundHandlerAdapter是ChannelInboundHandler的一个简单实现,默认情况下不会做任何处理, ...

  7. showModalDialog使用讲解

    基本介绍:          showModalDialog()                              (IE 4+ 支持)          showModelessDialog ...

  8. 一个简单的wed服务器SHTTPD(1)————命令行和文件配置解析

    开始学习<LInux网络编程>中的综合案例,虽然代码书上有,还是自己打一下加深理解和印象. 主要有两个函数,完成命令行的解析,另一个实现配置文件的解析,注释还是比较丰富的哦. //star ...

  9. VUE简单整理

    在用 Vue.js 构建大型应用时推荐使用 NPM 安装: # 最新稳定版 $ cnpm install vue 命令行工具 Vue.js 提供一个官方命令行工具,可用于快速搭建大型单页应用. # 全 ...

  10. 《新版阿里巴巴Java开发手册》提到的三目运算符的空指针问题到底是个怎么回事?

    最近,阿里巴巴Java开发手册发布了最新版--泰山版,这个名字起的不错,一览众山小. 新版新增了30+规约,其中有一条规约引起了作者的关注,那就是手册中提到在三目运算符使用过程中,需要注意自动拆箱导致 ...