zoukankan      html  css  js  c++  java
  • ZOJ 4070 Function and Function

    这题卡输入输出,不能用 cin 和  cout。

    Function and Function


    Time Limit: 1 Second      Memory Limit: 65536 KB


    If we define , do you know what function means?

    Actually, calculates the total number of enclosed areas produced by each digit in . 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, , and .

    We now define a recursive function by the following equations:

    For example, , and .

    Given two integers and , please calculate the value of .

    Input

    There are multiple test cases. The first line of the input contains an integer (about ), indicating the number of test cases. For each test case:

    The first and only line contains two integers and ( ). Positive integers are given without leading zeros, and zero is given with exactly one '0'.

    Output

    For each test case output one line containing one integer, indicating the value of .

    Sample Input

    6
    123456789 1
    888888888 1
    888888888 2
    888888888 999999999
    98640 12345
    1000000000 0
    

    Sample Output

    5
    18
    2
    0
    0
    1000000000
    

    Hint


    Author: WENG, Caizhi
    Source: The 2018 ACM-ICPC Asia Qingdao Regional Contest
    #include<iostream>
    #include<cstdio>
    using namespace std;
    typedef long long LL;
    
    int main()
    {
    	LL a[] = {1,0,0,0,1,0,1,0,2,1};
    	LL n,m,j,k,i,T;
    	scanf("%lld",&T);
        for (j=0;j<T;j++)
    	{
    		scanf("%lld%lld",&n,&m);
    		if (m==0)
    		{
    			printf("%lld
    ",n);
    			continue;
    		}
    		LL sum=0,x=0,flag = -1;
    		for (i=0;i<m;i++)
    		{
    			if (n == 0)
    			{
    				flag = 0;
    				break;
    			}
    
    			if (n == 1)
    			{
    				flag = 1;
    				break;
    			}
    			sum=0;
    			while (n)
    			{
    				sum = sum + (a[n%10]);
    				n/=10;
    			}
    			n = sum;
    			//cout<<"n = "<<n<<endl;
    		}
    
    		if (flag == 1)
    		{
    			if ( ( (m-1) - i) % 2 == 0 )
    			printf("0
    ");
    			else
    			printf("1
    ");
    		}
    		else if (flag == 0)
    		{
    			if ( ( (m-1) - i) % 2 == 0 )
    			printf("1
    ");
    			else
    			printf("0
    ");
    		}
    		else
    		printf("%lld
    ",sum);
    	}
    
    	return 0;
    }
    
    
    
    
    
    
    
    
    
  • 相关阅读:
    第2天 栈和寄存器
    第1天 工作计划和开端
    贯穿实例(1)
    闹心的变量
    开启懒人模式
    前言
    python基础学习7-网络编程、异常处理、面向对象
    python基础学习6-mongodb、sys、接口开发、操作excel
    python基础学习5-常用函数模块、操作数据库、发邮件、写日志、写excel
    python基础学习4-函数、内置函数、os模块、time模块
  • 原文地址:https://www.cnblogs.com/Romantic-Chopin/p/12451364.html
Copyright © 2011-2022 走看看