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,如果先手必胜的话,那么先手第一步按这样 ...
随机推荐
- Oracle 11g透明网关连接Sqlserver
Oracle 11g透明网关连接Sqlserver oracle 透明网关是oracle连接异构数据库提供的一种技术.通过Gateway,可以在Oracle里透明的访问其他不同的数据库,如SQL Se ...
- jenkins获取git上的源码
jenkins获取git上的源码会遇到三种情况,我们在这里会分别介绍一下: 一.获取git上public(公有)的项目 只需配置仓库的URL即可 jenkins下使用git获取源码的配置方法 二.获取 ...
- Laravel: 基础篇
一.安装 1)采用一键安装包 http://laravelacademy.org/resources-download 2)Mac 上安装 ----------在Mac上安装composer----- ...
- [古怪问题] Marshal.GetActiveObject 在管理员模式下无法正常运行
问题: var obj = Marshal.GetActiveObject("PowerPoint.Application") 该代码在管理员模式下运行无法正常获取正在运行的 PP ...
- 抓包神器 tcpdump 使用介绍
tcpdump 命令使用简介 简单介绍 tcpdump 是一款强大的网络抓包工具,运行在 linux 平台上.熟悉 tcpdump 的使用能够帮助你分析.调试网络数据. 要想使用很好地掌握 tcpdu ...
- MySQL 4 种隔离级别的区别
## 测试环境 mysql> select version(); +------------+ | version() | +------------+ -log | +------------ ...
- yaf项目将500错误打印到页面上
一般在yaf项目调试的时候,如果代码有错误,页面只会响应500错误,但看不到哪里报了什么错误,通过开启yaf的一个配置可以将错误信息显示在页面上. 打开项目的index.php入口文件,在开头加入如下 ...
- JS IOS/iPhone的Safari浏览器不兼容Javascript中的Date()问题的解决方法
1 var date = new Date('2016-11-11 11:11:11'); 2 document.write(date); 最近在写一个时间判断脚本,需要将固定好的字符串时间转换为时间 ...
- IndexedDB 教程
IndexedDB 教程 IndexedDB 是一个基于 JavaScript 的面向对象的事务型数据库.有了 LocalStorage 和 Cookies,为什么还要推出 indexedDB 呢?其 ...
- [Linux]Linux read/write
Read 默认read是block模式,如果想设置非block默认,则open时候参数添加O_NONBLOCK read block模式下,并非等到Buffer满才返回,而是只要有data avaia ...