当前位置: 首页 > news >正文

HDU - 4734 -- F(x)

题目如下:

For a decimal number x with n digits (AnAn−1An−2...A2A1)(A_nA_{n-1}A_{n-2} ... A_2A_1)(AnAn1An2...A2A1), we define its weight as F(x)=An∗2n−1+An−1∗2n−2+...+A2∗2+A1∗1.F(x) = A_n * 2^{n-1} + A_{n-1} * 2^{n-2} + ... + A_2 * 2 + A_1 * 1.F(x)=An2n1+An12n2+...+A22+A11. Now you are given two numbers AAA and BBB, please calculate how many numbers are there between 000 and BBB, inclusive, whose weight is no more than F(A)F(A)F(A).
Input
The first line has a number T(T≤10000)T (T \le 10000)T(T10000) , indicating the number of test cases.
For each test case, there are two numbers AAA and BBB (0≤A,B<109)(0 \le A,B < 10^9)(0A,B<109)
Output
For every case,you should output "Case #t: " at first, without quotes. The t is the case number starting from 111. Then output the answer.

Sample

Input

3
0 100
1 10
5 100

Output

Case #1: 1
Case #2: 2
Case #3: 13

思路 or 题解:

数位DP
dfs(数位, F(x) - 该位数的贡献,是否有限制)
具体请参考下面代码

AC 代码如下:

/*
Make it simple and keep self stupid
author:Joanh_Lan
*/
#pragma GCC optimize(3)
#pragma GCC optimize("inline") // 如果比赛允许开编译器优化的话,可以默写这两段
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <numeric>
#include <cstring>
#include <cmath>
#include <map>
#include <unordered_map>
#include <bitset>
#include <set>
#include <random>
#include <ctime>
#include <queue>
#include <stack>
#include <climits>
#define buff                     \ios::sync_with_stdio(false); \cin.tie(0);
// #define int long long
#define ll long long
#define PII pair<int, int>
#define px first
#define py second
typedef std::mt19937 Random_mt19937;
Random_mt19937 rnd(time(0));
using namespace std;
const int mod = 1e9 + 7;
const int inf = 2147483647;
const int N = 100009;
//int Mod(int a,int mod){return (a%mod+mod)%mod;}
//int lowbit(int x){return x&-x;}//最低位1及其后面的0构成的数值
//int qmi(int a, int k, int p){int res = 1 % p;while (k){if (k & 1) res = Mod(res * a , p);a = Mod(a * a , p);k >>= 1;}return res;}
//int inv(int a,int mod){return qmi(a,mod-2,mod);}
//int lcm(int a,int b){return a*b/__gcd(a,b);}
int f[30][N], dig[30], idx;
int calc(int x)
{int ans = 0, t = 1;while (x)ans += x % 10 * t, t <<= 1, x /= 10;return ans;
}
int dfs(int pos, int s, bool lim)
{if (pos == -1)	return s >= 0;if (s < 0)return 0;if (!lim && f[pos][s] != -1)	return f[pos][s];int len = lim ? dig[pos] : 9;int ans = 0;for (int i = 0; i <= len; i++)ans += dfs(pos - 1, s - i * (1 << pos), lim && i == len);if (!lim)	f[pos][s] = ans;return ans;
}
void solve()
{int x, n;	cin >> x >> n;idx = 0;while (n)dig[idx++] = n % 10, n /= 10;cout << dfs(idx - 1, calc(x), 1) << '\n';
}
int main()
{buff;memset(f, -1, sizeof f);int _ = 1;cin >> _;for (int i = 1; i <= _; i++){cout << "Case #" << i << ": ";solve();}
}
http://www.lryc.cn/news/59661.html

相关文章:

  • 【音视频第10天】GCC论文阅读(1)
  • 如何进行移动设备资产管理
  • 使用国密SSL证书,实现SSL/TLS传输层国密改造
  • Oracle之增删改(六)
  • OJ练习第81题——岛屿数量
  • remote gdb 操作流程
  • STM32基础代码学习G070CB串口透传调试(出厂默认)代码
  • 介绍一款idea神级插件【Bito-ChatGPT】
  • pycharm 2021.2.2 版本之前试用期过了怎么办
  • 【通世智库】宁晓红:医疗更完整的样子
  • AD20打开PCB后找不到
  • RTC 基础
  • Quaternion插值方法
  • 如何配置Stash以便与4EVERLAND一起使用
  • webpack plugin源码解析(四) HashedModuleIdsPlugin
  • pytorch | 使用vmap对自定义函数进行并行化/ 向量化的执行
  • Docker部署RabbitMQ(单机,集群,仲裁队列)
  • 生活污水处理设备选购指南
  • 奥威BI数据可视化大屏分享|多场景、多风格
  • 超越时空:加速预训练语言模型的训练
  • 数据库管理系统PostgreSQL部署安装完整教程
  • 有学生问我,重构是什么?我应该如何回答?
  • 交际场合---英文单词
  • 【网络安全】文件上传漏洞及中国蚁剑安装
  • [Java]面向对象高级篇
  • 苹果应用商店上架流程
  • 基于Eclipse下使用arm gcc开发GD32调用printf
  • 5个降低云成本并提高IT运营效率的优先事项
  • 95-拥塞控制
  • Linux常见操作命令【二】