ZOJ 4070 - Function and Function - [签到题][2018 ACM-ICPC Asia Qingdao Regional Problem M]
题目链接: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]的更多相关文章
- 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$,现在你有 ...
- 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$ ...
- 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$), ...
- 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 ...
- 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 ...
- The 2018 ACM-ICPC Asia Qingdao Regional Contest(部分题解)
摘要: 本文是The 2018 ACM-ICPC Asia Qingdao Regional Contest(青岛现场赛)的部分解题报告,给出了出题率较高的几道题的题解,希望熟悉区域赛的题型,进而对其 ...
- The 2018 ACM-ICPC Asia Qingdao Regional Contest
The 2018 ACM-ICPC Asia Qingdao Regional Contest 青岛总体来说只会3题 C #include<bits/stdc++.h> using nam ...
- 2018 ICPC Asia Singapore Regional A. Largest Triangle (计算几何)
题目链接:Kattis - largesttriangle Description Given \(N\) points on a \(2\)-dimensional space, determine ...
- HDU 6312.Game-博弈-签到题 (2018 Multi-University Training Contest 2 1004)
2018 Multi-University Training Contest 2 6312.Game 博弈,直接官方题解,懒了. 考虑将游戏变成初始时只有2~n,如果先手必胜的话,那么先手第一步按这样 ...
随机推荐
- js 动态生成html 触发事件传参字符转义
通常,在使用 JS 动态生成 html 的过程中,会嵌入相应的样式.事件等属性元素,而这时经常会出现所谓的 “单.双引号不够用” 的情况,别急,这时可以利用 html 语言中的转义字符来解决.下面就来 ...
- Ubuntu16.04安装串口调试工具gtkterm
gtkterm是一个用GTK+写的串口终端. 安装:sudo apt install gtkterm 配置文件的位置为:~/.gtktermrc [default] port = /dev/ttyUS ...
- python - Linux C调用Python 函数
1.Python脚本,名称为py_add.py def add(a=,b=): print('Function of python called!') print('a = ',a) print('b ...
- 2、金融之关于BOLL
一.BOLL(1)什么是BOLL线☆ BOLL指标又叫布林线指标(Bolinger Bands),是由约翰·布林格(John Bollinger)根据统计学中的标准差原理设计出来的一种非常简单实用的技 ...
- NodeJs之fs
NodeJs版本:4.4.4 fs的实用方法 查看文件信息(fs.stat) 定义:fs.stat(path, callback) var fs = require('fs'); fs.stat('t ...
- ANTLR v4 权威参考笔记(目录)
ANTLR v4是一款强大的语法分析器生成器,可以用来读取.处理.执行和转换结构化文本或二进制文件.通过称为文法的形式化语言描述,ANTLR可以为该语言自动生成词法分析器.生成的语法分析器可以自动构建 ...
- mongodb配置文件解说(转载)
启动方式 ./bin/mongod -f mongodb.conf 会看到 about to fork child process, waiting until server is ready for ...
- 理解REST和RPC
REST 越来越多的人开始意识到,网站即软件,而且是一种新型的软件. 网站开发,完全可以采用软件开发的模式.但是传统上,软件和网络是两个不同的领域,很少有交集:软件开发主要针对单机环境,网络则主要研究 ...
- linux的挂载的问题,重启后就挂载就没有了
我用fdisk命令,分一个/dev/sda6出来,然后用mkfs格式化为ext3,然后挂载到根目录下的PPP文件夹中,挂载是成功了,但是用reboot和shutdown重启或关机后挂载就没有了 要修改 ...
- 使用JavaScript验证用户输入的是否为正整数
在项目开发中,需要使用JavaScript验证用户输入的是否为正整数. 方法一: var type="^[0-9]*[1-9][0-9]*$"; var r=new RegExp( ...