• 数制的运用-CodeForces


    题解:

      因为每一位只可能是4或者7,可以类比二进制的思想。

      基数为2,每一位的权值为2i-1;数字4表示的大小为1*2i-1;数字7表示的大小为2*2i-1

      将给定的n按照这种方法进行分解,求和。即为答案。

     1 #include<iostream>
     2 #include<cstdio>
     3 #include<cstring>
     4 #include<queue>
     5 using namespace std;
     6 
     7 int main(){
     8     int n;
     9     while(~scanf("%d",&n)){//二进制的思想
    10         int ans=0;
    11         int index=1;
    12         while(n){
    13             if(n%10==4)ans+=index;
    14             else if(n%10==7)ans+=2*index;
    15             n/=10;
    16             index*=2;
    17         }
    18         printf("%d
    ",ans);
    19     }
    20 
    21     return 0;
    22 }
    View Code
  • 相关阅读:
    GC原理---垃圾收集算法
    GC原理---对象可达判断
    散列算法和哈希表结构
    桶排序
    Spring事务梳理
    AQS
    重入锁
    CAS
    研究一下phpspider
    用php写爬虫去爬数据
  • 原文地址:https://www.cnblogs.com/dialectics/p/12370512.html
Copyright © 2020-2023  润新知