题目链接:http://acm.zju.edu.cn/onlinejudge/showContestProblem.do?problemId=5840

Time Limit: 1 Second  Memory Limit: 65536 KB

If we define $f(0)=1,f(1)=0,f(4)=1,f(8)=2,f(16)=1 \cdots$, do you know what function $f$ means?

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

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

For example, $f(1234)=0+0+0+1=1$, and $f(5678)=0+1+0+2=3$.

We now define a recursive function  by the following equations:

 

For example, $g^2(1234)=f(f(1234))=f(1)=0$, and $g^2(5678)=f(f(5678))=f(3)=0$.

Given two integers $x$ and $k$, please calculate the value of $g^k(x)$.

题解:

(浙大出题就是良心,又稳又好。)

求 $k$ 层嵌套的 $f(x)$,因为几层 $f(x)$ 下去 $x$ 很快就变成 $0$ 或者 $1$ 了,这个时候,可以根据 $x$ 外面还剩下多少层 $f$ 直接返回 $0$ 或者 $1$。

AC代码:

#include<bits/stdc++.h>
using namespace std;
int fx[]={,,,,,,,,,};
int x,k;
int f(int x)
{
int res=;
do{
res+=fx[x%];
x/=;
}while(x);
return res;
}
int g(int k,int x)
{
while(k--)
{
x=f(x);
if(x==) return k%;
if(x==) return -k%;
}
return x;
}
int main()
{
int T;
cin>>T;
while(T--)
{
scanf("%d%d",&x,&k);
printf("%d\n",g(k,x));
}
}

ZOJ 4070 - Function and Function - [签到题][2018 ACM-ICPC Asia Qingdao Regional Problem M]的更多相关文章

  1. ZOJ 4060 - Flippy Sequence - [思维题][2018 ACM-ICPC Asia Qingdao Regional Problem C]

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=4060 题意: 给出两个 $0,1$ 字符串 $S,T$,现在你有 ...

  2. ZOJ 4062 - Plants vs. Zombies - [二分+贪心][2018 ACM-ICPC Asia Qingdao Regional Problem E]

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=4062 题意: 现在在一条 $x$ 轴上玩植物大战僵尸,有 $n$ ...

  3. ZOJ 4067 - Books - [贪心][2018 ACM-ICPC Asia Qingdao Regional Problem J]

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=4067 题意: 给出 $n$ 本书(编号 $1 \sim n$), ...

  4. ZOJ 4063 - Tournament - [递归][2018 ACM-ICPC Asia Qingdao Regional Problem F]

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=4063 Input Output Sample Input 2 3 ...

  5. HDU 5875 Function 【倍增】 (2016 ACM/ICPC Asia Regional Dalian Online)

    Function Time Limit: 7000/3500 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)Total ...

  6. The 2018 ACM-ICPC Asia Qingdao Regional Contest(部分题解)

    摘要: 本文是The 2018 ACM-ICPC Asia Qingdao Regional Contest(青岛现场赛)的部分解题报告,给出了出题率较高的几道题的题解,希望熟悉区域赛的题型,进而对其 ...

  7. The 2018 ACM-ICPC Asia Qingdao Regional Contest

    The 2018 ACM-ICPC Asia Qingdao Regional Contest 青岛总体来说只会3题 C #include<bits/stdc++.h> using nam ...

  8. 2018 ICPC Asia Singapore Regional A. Largest Triangle (计算几何)

    题目链接:Kattis - largesttriangle Description Given \(N\) points on a \(2\)-dimensional space, determine ...

  9. HDU 6312.Game-博弈-签到题 (2018 Multi-University Training Contest 2 1004)

    2018 Multi-University Training Contest 2 6312.Game 博弈,直接官方题解,懒了. 考虑将游戏变成初始时只有2~n,如果先手必胜的话,那么先手第一步按这样 ...

随机推荐

  1. 为ExecutorService增加shutdown hook

    public class ShutdownHook { private static final ShutdownHook INSTANCE = new ShutdownHook(); private ...

  2. CMD 命令1

    cmd /c dir 是执行完dir命令后关闭命令窗口. cmd /k dir 是执行完dir命令后不关闭命令窗口. cmd /c start dir 会打开一个新窗口后执行dir指令,原窗口会关闭. ...

  3. 微信小程序+微信管理后台+微信用户前台

    代码地址如下:http://www.demodashi.com/demo/15043.html #### 微信小程序+微信管理后台+微信用户前台 #### 产品介绍 基础功能开发:景区微信地图导游.天 ...

  4. (原)DropBlock A regularization method for convolutional networks

    转载请注明出处: https://www.cnblogs.com/darkknightzh/p/9985027.html 论文网址: https://arxiv.org/abs/1810.12890 ...

  5. MySQL 8 中新的复制功能

    MySQL 8 中新的复制功能使得操作更加方便,并帮助用户更好地观察复制过程中内部发生的情况. 使用 MySQL 5.7.17 获取 MySQL 组复制插件是一项巨大的工作.组复制是一个新的插件,通过 ...

  6. 《Java 9 揭秘》全目录汇总

    Tips 做一个终身学习的人. 当写这篇文章时,关于Java 9的学习就先告一段落了. 首先介绍一下背景,大概两个月前,我突然有兴趣想看看Java 9,当时读了一本英文原著<Java 9 Rev ...

  7. 星云STS 常用配置

    STS4  下载地址:https://spring.io/tools    (这个版本没有tomcat插件) STS3  下载地址:https://spring.io/tools3/sts/all ( ...

  8. 关于Cocos的内存管理机制引发一些异常的解决方案

    错误:引发了异常: 读取访问权限冲突. this 是 0xDDDDDDDD.或者hero是 0xDDDDDDDD.hero是在GameController里创建的对象 这个的意思是this所指向的内存 ...

  9. react项目和next项目修改默认端口号

    creat-react-app生成的项目默认端口号是3000,如下可以更改: 在package.json中修改 "start":"react-scripts start& ...

  10. opencv利用直方图判断人脸光照质量

    懒得用中文再写一遍了, 直接传送门过去吧. https://medium.com/@fanzongshaoxing/detect-face-in-bad-lighting-condition-usin ...