zoukankan      html  css  js  c++  java
  • hdu 5936 2016ccpc 杭州

    数学题好难啊!!!!

    最长长度不超过十位, 折半枚举。。。

    题解

     1 #include<bits/stdc++.h>
     2 #define LL long long
     3 #define fi first
     4 #define se second
     5 #define mk make_pair
     6 #define pii pair<int,int>
     7 #define piii pair<int, pair<int,int>>
     8 
     9 using namespace std;
    10 
    11 const int N = 1e5 + 7;
    12 const int M = 1e4 + 7;
    13 const int inf = 0x3f3f3f3f;
    14 const LL INF = 0x3f3f3f3f3f3f3f3f;
    15 const LL base = 100000;
    16 const int mod = 1e9 + 7;
    17 
    18 int x, k;
    19 LL f[N][10], v[N];
    20 
    21 int fastPow(int a, int b) {
    22     int ans = 1;
    23     while(b) {
    24         if(b & 1) ans = ans * a;
    25         a = a * a; b >>= 1;
    26     }
    27     return ans;
    28 }
    29 void init() {
    30     for(int i = 0; i < N; i++) {
    31         for(int j = 0; j < 10; j++) {
    32             for(int now = i; now; now /= 10) {
    33                 f[i][j] += fastPow(now % 10, j);
    34             }
    35         }
    36     }
    37 }
    38 
    39 
    40 int main() {
    41     init();
    42     int T; scanf("%d", &T);
    43     for(int cas = 1; cas <= T; cas++) {
    44         scanf("%d%d", &x, &k);
    45         LL ans = 0;
    46         for(int i = 0; i < base; i++)
    47             v[i] = f[i][k] - i * base;
    48         sort(v, v + base);
    49 
    50         for(int i = 0; i < base; i++) {
    51             LL ret = f[i][k] - i;
    52             ans += upper_bound(v, v + base, x - ret) - lower_bound(v, v + base, x - ret);
    53         }
    54 
    55         ans -= (x == 0);
    56         printf("Case #%d: ", cas);
    57         printf("%lld
    ", ans);
    58     }
    59     return 0;
    60 }
    61 /*
    62 */
  • 相关阅读:
    sequence.c
     Link 
    转:MFC中屏蔽ESC和回车关闭对话框
    转:CWebBrowser2去除边框、滚动条、右键菜单
    VC:res协议——从模块中获取资源
    20131213
    20131212
    20131211
    20131205
    20131128
  • 原文地址:https://www.cnblogs.com/CJLHY/p/9080234.html
Copyright © 2011-2022 走看看