P10024

· · 题解

我们列出每个数字所需要的直线数量,容易发现满足答案需求的幸运数对的长度最长为 2 同时当 l 和 r 的差值大于 10 时(因为 2 和 3 的用的直线的数量相同),一定可以得到长度为 2 的幸运数对。当 l 和 r 的差值小于 10 时,我们暴力枚举即可(因为还会出现末尾为 29 和 30 这种情况也是符合的)。

Code

#include <iostream>
using namespace std;
#define int long long//10年OI一场空,不开longlong见祖宗
int l,r;
int vis[10]={6,2,5,5,4,5,6,3,7,6};
int zhao(int x){
    int ans=0;
    while(x){
        int tmp=x%10;
        ans+=vis[tmp];
        x/=10;
    }
    return ans;
}
signed main(){
    cin>>l>>r;
    if(l==r){
        cout<<1;
        return 0;
    }
    for(int i=l;i<r;i++){
        int tmp1=zhao(i),tmp2=zhao(i+1);
        if(tmp1==tmp2){
            cout<<2;
            return 0;
        }
    }
    cout<<1;
    return 0;
}


/*
       ┏┓   ┏┓
     ┏┛┻━━━┛┻┓
     ┃       ┃
     ┃   ━   ┃
     ┃ ┳┛ ┗┳ ┃
     ┃       ┃
     ┃   ┻   ┃
     ┃       ┃
     ┗━┓   ┏━┛Codes are far away from bugs with the animal protecting
         ┃   ┃    神兽保佑,代码无bug
         ┃   ┃
         ┃   ┗━━━┓
         ┃      ┣┓
         ┃     ┏┛
         ┗┓┓┏━┳┓┏┛
           ┃┫┫ ┃┫┫
           ┗┻┛ ┗┻┛     ○| ̄|_

*/