您的位置:首页 > 其它

HDU_3555

2014-08-23 14:25 92 查看
题意:就是计算出从1-N之间有多少个49,与2089类似。

但是最后的答案为N+1减去所求的答案。

代码:

#include <cstdlib>

#include <cstdio>

#include <cstring>

#include <algorithm>

#include <iostream>

using namespace std;

__int64 f[100][2], bit[100];

__int64 dfs(int p, int s, int e) {

if (p == -1) {

return 1;

}

if (!e && f[p][s]!=-1) return f[p][s];

__int64 res = 0;

int u = e ? bit[p] : 9;

for (int i = 0; i <= u; ++i) {

if(i==9&&s) {

continue;

}

res += dfs(p-1, i==4, e&&i==u);

}

return e ? res : f[p][s] = res;

}

__int64 cal(__int64 x) {

int idx = 0;

while (x) {

bit[idx++] = x % 10;

x /= 10;

}

return dfs(idx-1, 0, 1);

}

int main() {

__int64 T, l, r;

memset(f, -1, sizeof (f));

while(~scanf("%I64d", &T)) {

while (T--) {

scanf("%I64d",&r);

printf("%I64d\n", r-cal(r)+1);

}

}

return 0;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: