1. 程式人生 > >【ZOJ4070】Function and Function(簽到)

【ZOJ4070】Function and Function(簽到)

題意:求 k 層巢狀的 f(x)

0<=x,k<=1e9

思路:迭代不會很多次後函式裡就會=0或者1,再看層數奇偶直接返回答案

 1 #include<cstdio>
 2 #include<cstring>
 3 #include<string>
 4 #include<cmath>
 5 #include<iostream>
 6 #include<algorithm>
 7 #include<map>
 8 #include<set>
 9 #include<queue>
10
#include<vector> 11 using namespace std; 12 typedef long long ll; 13 typedef unsigned int uint; 14 typedef unsigned long long ull; 15 typedef pair<int,int> PII; 16 typedef vector<int> VI; 17 #define fi first 18 #define se second 19 #define MP make_pair 20 #define N 110000 21 #define
M 51 22 #define MOD 1000000007 23 #define eps 1e-8 24 #define pi acos(-1) 25 #define oo 1010000000 26 27 int a[10]={1,0,0,0,1,0,1,0,2,1}; 28 29 int f(int n) 30 { 31 int s=0; 32 do{ 33 s+=a[n%10]; 34 n/=10; 35 }while(n); 36 return s; 37 } 38 39 int g(int n,int k) 40 { 41 while
(k--) 42 { 43 n=f(n); 44 if(n==0) return k%2; 45 if(n==1) return 1-k%2; 46 } 47 return n; 48 } 49 50 int main() 51 { 52 int cas; 53 scanf("%d",&cas); 54 for(int v=1;v<=cas;v++) 55 { 56 int n,k; 57 scanf("%d%d",&n,&k); 58 printf("%d\n",g(n,k)); 59 } 60 return 0; 61 } 62