Live2d Test Env

HDU4278 Faulty Odometerd

开始以为是容斥原理,想着做一下,应该是可以用容斥解决的,有空再过来写一下。题解是进制转换,开始没想到,不过很好理解。

如在10进制里: 1254=  (1*10^3 + 2*10^2 + 5* 10^1+ 4*10^0)

而faulty的大小:1254=  (1* 8^3  +  2* 8^2  +  4* 8^1+  3*8^0)  

当然faulty里面没有3和8所以 0-9分别代表:

int s[10]={0,1,2,3,3,4,5,6,6,7};

 

#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<memory.h>
using namespace std;
#define LL long long 
int s[10]={0,1,2,3,3,4,5,6,6,7};
int main()
{
    LL n;
    int i,j;
    while(~scanf("%lld",&n)&&n)  {
        printf("%lld: ",n);
        LL tmp=1,ans=0;
        while(n){
           ans+=s[n%10]*tmp;
           n/=10;
           tmp*=8;
        }
        printf("%lld\n",ans);
    }
    return 0;
}

 

posted @ 2017-10-11 08:08  nimphy  阅读(172)  评论(0编辑  收藏  举报