Function and Function
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的更多相关文章
- function,new function,Function,new Function 之间的区别
测试一: var fud01 = function() { var temp = 100; this.temp = 200; return temp + this.temp; } alert(typ ...
- (function(){...}())与(function(){...})()
(function(){ ...... }()) 或 (function(){ ...... })() 匿名函数自调用,也就是说,定义一个匿名函数 ...
- 浅析jQuery(function(){})与(function(){})(jQuery)之间的区别
本篇文章主要是对jQuery(function(){})与(function(){})(jQuery)之间的区别进行了介绍,需要的朋友可以过来参考下,希望对大家有所帮助 Jquery是优秀的Javas ...
- jQuery中$(function(){})与(function($){})(jQuery)、$(document).ready(function(){})等的区别详细讲解
1.(function($) {…})(jQuery); 1).原理: 这实际上是匿名函数,如下: function(arg){…} 这就定义了一个匿名函数,参数为arg 而调用函数时,是在函数后面写 ...
- (function($){}) 和$(function(){}) 和$(function($){}) 区别
请问下(function($){}) 和$(function(){}) 和$(function($){}) 有什么区别 谢谢 一.先看 jQuery(function(){ }); 全写为 jQuer ...
- function foo(){}、(function(){})、(function(){}())等函数区别分析
前面一段时间,看到(function(){}),(function(){}())这些函数就犯晕,不知道它到底是什么意思,为什么函数外要加小括号,函数后要加小括号,加和不加到底有什么区别……一直犯迷糊, ...
- $(document).ready(function (){}) , $(function(){}) , $().ready(function(){}) , jquery(function(){}) , (function($){})(jquery)有什么区别
$(document).ready(function(){...}) , $().ready(function(){...}) , $(function(){...}) , jquery(funct ...
- $(function(){})与 (function(){})() (function($){})() 的区别
1. $(function(){ }) 或 jQuery(function(){ }) 此函数也可以写成 jQuery(function(){ }), 用于存放操作DOM对象的代码,执行其中代码时DO ...
- (function ( ){})( ) 与 (function ( ){}( )) 有什么区别?
js立即执行函数: (function ( ){})( ) 与 (function ( ){}( )) 有什么区别? 转自:http://www.jb51.net/article/75089.htm ...
- Javacript中(function(){})() 与 (function(){}()) 区别 {转}
这个问题可以从不同的角度来看,但从结果上来说 :他们是一样的.首先,如果从AST(抽象语法树)的角度来看,两者的AST是一模一样的,最终结果都是一次函数调用.因此,就解析器产生的结果论而言,两者是没有 ...
随机推荐
- vue中如何在本地导入js文件
import {setStore,setUser,getStore,removeStore} from "../../../public/localstory" 在导入js文件时, ...
- SpringMVC 参数映射与文件上传
handler参数映射: 接下来就是Spring的各个处理细节了,无论框架如何疯转其实我们处理请求的流程是不变的,设计到的操作也是固定的,举个例子,当我们要实现一个登陆功能时: 创建一个用于处理登录请 ...
- 全国疫情精准定点动态更新(.net core)
前言 疫情远比我们在年初想的发展迅速,在过年前还计划着可以亲戚聚聚,结果都泡汤了,开始了自家游. 在初三的时候,看到那个丁香医生,觉得不够详细,比如说我想看下周边城市的疫情情况,但是我地理不好,根本不 ...
- centos7中搭建ftp服务
博客搬家: centos7中搭建ftp服务 最近想和同学共享一些文件资源,于是在实验室服务器上搭建个ftp服务,本博客记录一下配置的流程.过程基本是参照别人的方法来做的,博客也是在别人博客基础上修改的 ...
- ARTS Week 7
Dec 9, 2019 ~ Dec 15, 2019 Algorithm Problem 38.Count And Say 外观数列 题目链接 题目描述: 外观数列 是一个整数序列,从数字 1 开始, ...
- 用例建模Use Case Modeling——传感器智能分析引擎
系统用例分析 我的工程实践小组做的课题主要是实现传感器数据采集平台的设计与开发.该搜索引擎完成对传感器数据的采集和发布,企业可以在平台上上传自己的传感器数据信息,同时也能够浏览市面上其他传感器信息,以 ...
- 见异思迁:K8s 部署 Nginx Ingress Controller 之 kubernetes/ingress-nginx
前天才发现,区区一个 nginx ingress controller 竟然2个不同的实现.一个叫 kubernetes/ingress-nginx ,是由 kubernetes 社区维护的,对应的容 ...
- Nexus 安装
Windows下安装Nexus OSS 3.12.1 1. Nexus 下载 到sonatype官网下载开源免费的OSS版本.OSS即为Open Source Software. 下载地址:https ...
- mac下搭建http服务器(apache+php),使用homebrew升级php
新版mac依旧预装了 Apache ,但是已经不能在 「系统偏好设置」中的「Web 共享」来开启了,需要手动通过命令行开启. 启动Apache 启动:sudo apachectl start 停止:s ...
- Python常用库 - os库
os简单介绍 os 模块提供了非常丰富的方法用来处理文件和目录 os关于目录路径的方法 # 获取当前路径 path = os.getcwd() # 获取当前绝对路径 os.path.abspath(p ...