码迷,mamicode.com
首页 > 其他好文 > 详细

【ZOJ 4070】Function and Function

时间:2018-11-07 11:42:51      阅读:107      评论:0      收藏:0      [点我收藏+]

标签:ace   http   ==   const   turn   ons   base   and   int   

【链接】 我是链接,点我呀:)
【题意】

【题解】


递归一会。
会发现最后肯定是0,1一直循环。
开始循环之后就直接返回结果就好。

【代码】

#include <bits/stdc++.h>
#define ll long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
using namespace std;

const int N = 1e6;
int base_f[10]={1,0,0,0,1,0,1,0,2,1};

int get_f(int x){
    if (x==0) return 1;
    int temp = 0;
    while (x>0){
        temp+=base_f[x%10];
        x/=10;
    }
    return temp;
}

int f(int x,int dep){
    if (dep==0) return x;
    if (x==0){
        if (dep&1)
            return 1;
        else
            return 0;   
     }
    if (x==1){
        if (dep&1)
            return 0;
        else 
            return 1;
    }
    return f(get_f(x),dep-1);
}

int main(){
    #ifdef ccy
            freopen("rush.txt","r",stdin);
    #endif
    int T;
    scanf("%d",&T);
    while (T--){
        int x,k;
        scanf("%d%d",&x,&k);
        printf("%d\n",f(x,k));
    }
    return 0;
}

【ZOJ 4070】Function and Function

标签:ace   http   ==   const   turn   ons   base   and   int   

原文地址:https://www.cnblogs.com/AWCXV/p/9920749.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!