If we define , do you know what function  means?

Actually,  calculates the total number of enclosed areas produced by each digit in . The following table shows the number of enclosed areas produced by each digit:

Digit Enclosed Area Digit Enclosed Area
0 1 5 0
1 0 6 1
2 0 7 0
3 0 8 2
4 1 9 1

For example, , and .

We now define a recursive function  by the following equations:

 

For example, , and .

Given two integers  and , please calculate the value of .

Input

There are multiple test cases. The first line of the input contains an integer  (about ), indicating the number of test cases. For each test case:

The first and only line contains two integers and  (). Positive integers are given without leading zeros, and zero is given with exactly one '0'.

<h4< dd="">Output

For each test case output one line containing one integer, indicating the value of .

<h4< dd="">Sample Input

6
123456789 1
888888888 1
888888888 2
888888888 999999999
98640 12345
1000000000 0

<h4< dd="">Sample Output

5
18
2
0
0
1000000000

这道题看第一眼,很容易想到暴力,然后就零分了。

不过仔细观察

观察一下0-9对应的值,很容易发现他们最后都指向了0,1

其余的数同理,最后都会指向1.0;

而0,1的值又是相互对应的。

我们就可以优化了--------------------

链接:不知道

---------------------------

 #include<iostream>
#include<cstdio>
using namespace std;
int n;
const long long maxn=1e6;
int head;
int x;
int k;
int deal1(int x);
long long f[maxn]={,,,,,,,,,};
void deal(int k,int x){
while(x>=&&k){
// cout<<"d"<<x<<endl;
x=deal1(x);
k--;
}
// cout<<x<<endl
if(!k)
{
cout<<x<<endl;
return ;
}
if(k%)
printf("%d\n",(!x));
else
printf("%d\n",x);
return ;
} int deal1(int x){
int ans=;
long long now;
while(x){
now=x%;
x/=;
ans+=f[now];
//cout<<now<<"dfsd"<<endl;
}
return ans;
}
int main(){
scanf("%d",&n);
for(int i=;i<=n;++i){
scanf("%d%d",&x,&k);
if(k==){
printf("%d\n",x);
}
else
deal(k,x);
}
return ;
}

Ac

Function and Function的更多相关文章

  1. function,new function,Function,new Function 之间的区别

    测试一: var fud01 = function()  { var temp = 100; this.temp = 200; return temp + this.temp; } alert(typ ...

  2. (function(){...}())与(function(){...})()

    (function(){         ......   }())  或   (function(){            ......   })()  匿名函数自调用,也就是说,定义一个匿名函数 ...

  3. 浅析jQuery(function(){})与(function(){})(jQuery)之间的区别

    本篇文章主要是对jQuery(function(){})与(function(){})(jQuery)之间的区别进行了介绍,需要的朋友可以过来参考下,希望对大家有所帮助 Jquery是优秀的Javas ...

  4. jQuery中$(function(){})与(function($){})(jQuery)、$(document).ready(function(){})等的区别详细讲解

    1.(function($) {…})(jQuery); 1).原理: 这实际上是匿名函数,如下: function(arg){…} 这就定义了一个匿名函数,参数为arg 而调用函数时,是在函数后面写 ...

  5. (function($){}) 和$(function(){}) 和$(function($){}) 区别

    请问下(function($){}) 和$(function(){}) 和$(function($){}) 有什么区别 谢谢 一.先看 jQuery(function(){ }); 全写为 jQuer ...

  6. function foo(){}、(function(){})、(function(){}())等函数区别分析

    前面一段时间,看到(function(){}),(function(){}())这些函数就犯晕,不知道它到底是什么意思,为什么函数外要加小括号,函数后要加小括号,加和不加到底有什么区别……一直犯迷糊, ...

  7. $(document).ready(function (){}) , $(function(){}) , $().ready(function(){}) , jquery(function(){}) , (function($){})(jquery)有什么区别

    $(document).ready(function(){...}) , $().ready(function(){...}) ,  $(function(){...}) , jquery(funct ...

  8. $(function(){})与 (function(){})() (function($){})() 的区别

    1. $(function(){ }) 或 jQuery(function(){ }) 此函数也可以写成 jQuery(function(){ }), 用于存放操作DOM对象的代码,执行其中代码时DO ...

  9. (function ( ){})( ) 与 (function ( ){}( )) 有什么区别?

    js立即执行函数: (function ( ){})( ) 与 (function ( ){}( )) 有什么区别? 转自:http://www.jb51.net/article/75089.htm ...

  10. Javacript中(function(){})() 与 (function(){}()) 区别 {转}

    这个问题可以从不同的角度来看,但从结果上来说 :他们是一样的.首先,如果从AST(抽象语法树)的角度来看,两者的AST是一模一样的,最终结果都是一次函数调用.因此,就解析器产生的结果论而言,两者是没有 ...

随机推荐

  1. 1、通过CP数据文件的方式恢复MySQL 从库 启动后报错:Last_IO_Errno: 1236:A slave with the same server_uuid/server_id as this slave has connected to the master;

    1.问题: MySQL从库中查看主从状态: show slave status\G,发现出现IO的报错: Last_IO_Errno: Last_IO_Error: Got fatal error f ...

  2. 暑假第四周总结(HDFS编程实践,安装HBASE)

    本周根据书上以及教程的提示,对HDFS进行了编程实践,将教程所给的代码(判断文件是否存在,创建文件,读取文件)进行了应用,根据视频的讲解,对一些简单的语句有了一定的了解,但还是比较生疏.另外还根据提示 ...

  3. javaIO编码详解

    原创 输出流 有哪些构造方法可以在参数上设置编码格式 PrintStream(File file, String csn) PrintStream(String fileName, String cs ...

  4. 时序数据库 Apache-IoTDB 源码解析之系统架构(二)

    上一章聊到时序数据是什么样,物联网行业中的时序数据的特点:存量数据大.新增数据多(采集频率高.设备量多).详情请见: 时序数据库 Apache-IoTDB 源码解析之前言(一) 打一波广告,欢迎大家访 ...

  5. C语言宏的神奇写法:语句块作为参数,算半个函数式编程?

    我想要写几个循环做测试代码,每次都写 `for(size_t i = 0; i < n; i++)` 很烦人,然后就灵机一动,能不能用宏实现,然后就写出了: #define repeat(n, ...

  6. 国外大神制作的一个很棒的matplotlib 可视化教程

    国外大神制作的一个很棒的matplotlib 可视化教程 参考:https://www.machinelearningplus.com/plots/top-50-matplotlib-visualiz ...

  7. 使用ClouderaManager管理的HBase的RegionServer无法启动(启动失败)的问题

    问题概述 "新冠期间"远程办公,需要重新搭建一套ClouderaManager(CM)开发环境,一位测试同事发现HBase的RegionServer无法启动,在CM界面上启动总是失 ...

  8. C语言实现matlab的interp2()函数

    项目要用到matlab中的Vq = interp2(X,Y,V,Xq,Yq)函数,即把一个已知经纬度和对应值的矩阵,插值变换到一个给定经纬度网格中,也就是对给定网格填值,需要用到插值,这里使用双线性内 ...

  9. UI自动化框架搭建

    1.目录结构 大概分为以下几个文件 common :主要是用来放一些封装的公共函数 outputs :主要是输出一些文件,失败截图.用例执行完的测试报告 pagelocate :主要是元素的定位 pa ...

  10. GPU 版 TensorFlow failed to create cublas handle: CUBLAS_STATUS_ALLOC_FAILED

    原因: 使用 GPU 版 TensorFlow ,并且在显卡高占用率的情况下(比如玩游戏)训练模型,要注意在初始化 Session 的时候为其分配固定数量的显存,否则可能会在开始训练的时候直接报错退出 ...