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,如果先手必胜的话,那么先手第一步按这样 ...
随机推荐
- M600 Pro 安装问题解决
1.遥控器版本为1.2.10 提示版本已是最新版本,那么Lightbridge2 必须是1.1.60 不能是1.1.70 2.卸载机翼的时候,尽量用飞机带的那把工具 3.机翼安装 135 逆时针 cc ...
- webstorm快捷键 webstorm keymap内置快捷键英文翻译、中英对照说明
20160114参考网络上的快捷键,整理自己常用的: 查找/代替shift+shift 快速搜索所有文件,简便ctrl+shift+N 通过文件名快速查找工程内的文件(必记)ctrl+shift+al ...
- Vue $emit()不触发方法的原因
vue使用$emit时,父组件无法触发监听事件的原因是: $emit传入的事件名称只能使用小写,不能使用大写的驼峰规则命名
- linux内存管理之malloc、vmalloc、kmalloc的区别
kmalloc kzalloc vmalloc malloc 和get_free_page()的区别 一.简述 1. kmalloc申请的是较小的连续的物理内存,虚拟地址上也是连续的.kmalloc和 ...
- CentOS 6.5 x64下查找依赖包,或用YUM安装
查看某个命令YUM上的安装源 1)当某个命令不存时进行查询所依赖的包,如:pstree [root@localhost ~]# yum provides pstree 已加载插件:fastestmir ...
- SNF软件开发机器人教程更新
SNF开发机器人教程:链接:https://pan.baidu.com/s/1Qpomg11c_1b1NKY5P7e4Bw 密码:jwc3
- 【转】pymongo实现模糊查询
pymongo 模糊匹配查询在mongo中这样实现 {'asr':/若琪/} 使用pymongo 两种实现方式 1.import re {'asr':re.compile('若琪')} 2.{'asr ...
- spring boot 项目启动无任何反应
遇到的问题 spring boot项目启动后无任何报错,ps有进程,nohub无日志 定位 更换jar包,问题依然存在,将jar包放到其他服务器,运行正常,排除打包问题 同服务器其他系统运行正常,但停 ...
- @Scope用法
http://www.cnblogs.com/lonecloud/p/5937513.htmlhttp://www.cnblogs.com/lonecloud/p/5937513.htmlhttp:/ ...
- maven项目打包额外lib目录
maven项目依赖了几个额外的jar包一直都无法打进最终jar,不知道哪里出了问题.一直对这块不甚清楚,就大概梳理一下 默认打包方式: maven项目下,默认编译目录为 src/main/java和s ...