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,如果先手必胜的话,那么先手第一步按这样 ...
随机推荐
- git主要操作命令
1.创建版本库 (1)初始化一个 Git仓库,使用git init命令 (在相应的本地库目录下执行,将该目录初始化为一个Git库): (2)添加文件到Git仓库,分两步: 第一步,使用命令 git a ...
- Oracle JDBC驱动安装到Maven本地仓库
Oracle JDBC驱动因为授权问题,没有放到Maven的中央仓库里面,当然了,阿里云的镜像也没有了.所以要从Oracle官网下载驱动: 注意下载ojdbc6.jar 因为这个JDK1.8才能用. ...
- Saltstack之Scheduler
一.引言: 在日常的运维工作中经常会遇到需要定时定点启动任务,首先会考虑到crontab,但是通过crontab的话需要每台机器下进行设置,这样统一管理的话比较复杂:通过查百度和google发现sal ...
- Redis面试刁难大全
转自:https://mp.weixin.qq.com/s?__biz=MzI0MzQyMTYzOQ==&mid=2247483686&idx=1&sn=18dfa0fd08b ...
- 恶心github 下载慢
起因 某天看github上面的代码,有点不耐烦,想下载下来再看,但是现在速度慢的可怜 解决思路 相关网站 获取域名相关ip ipaddress.com 这个有好处就是知道网站部署在哪里,如果有vpn的 ...
- 物联网架构成长之路(29)-Jenkins环境搭建
0. 说明 哈哈,前面中间插入了一篇Eclipse增加Git插件,在此之前真的没有用过GIT. 1. 运行Jenkins 这里为了方便,还是用Docker方式安装,由于这个是标准的war报,不对Doc ...
- kernel事件通知userspace
https://stackoverflow.com/questions/31646466/how-to-send-signal-from-kernel-to-user-space
- vue element-ui 的奇怪组件el-switch
https://segmentfault.com/q/1010000010008343
- Vue 创建组件的方式
Vue 创建组件的方式 2018年08月07日 11:10:56 虔诚带着决然 阅读数:1015 版权声明:本文为博主原创文章,未经博主允许不得用做其他商业活动. https://blog.csd ...
- Golang查缺补漏(一)
Go语言高级编程(Advanced Go Programming) Go语言高级编程(Advanced Go Programming) golang都是传值,与其他语言不同的是数组作为参数时,也是传值 ...