ZOJ 3962 E.Seven Segment Display / The 14th Zhejiang Provincial Collegiate Programming Contest Sponsored by TuSimple E.数位dp
Seven Segment Display
Time Limit: 1 Second Memory Limit: 65536 KB
A seven segment display, or seven segment indicator, is a form of electronic display device for displaying decimal numerals that is an alternative to the more complex dot matrix displays. Seven segment displays are widely used in digital clocks, electronic meters, basic calculators, and other electronic devices that display numerical information.
Edward, a student in Marjar University, is studying the course "Logic and Computer Design Fundamentals" this semester. He bought an eight-digit seven segment display component to make a hexadecimal counter for his course project.
In order to display a hexadecimal number, the seven segment display component needs to consume some electrical energy. The total energy cost for display a hexadecimal number on the component is the sum of the energy cost for displaying each digit of the number. Edward found the following table on the Internet, which describes the energy cost for display each kind of digit.
|
|
|
For example, in order to display the hexadecimal number "5A8BEF67" on the component for one second, 5 + 6 + 7 + 5 + 5 + 4 + 6 + 3 = 41 units of energy will be consumed.
Edward's hexadecimal counter works as follows:
- The counter will only work for n seconds. After n seconds the counter will stop displaying.
- At the beginning of the 1st second, the counter will begin to display a previously configured eight-digit hexadecimal number m.
- At the end of the i-th second (1 ≤ i < n), the number displayed will be increased by 1. If the number displayed will be larger than the hexadecimal number "FFFFFFFF" after increasing, the counter will set the number to 0 and continue displaying.
Given n and m, Edward is interested in the total units of energy consumed by the seven segment display component. Can you help him by working out this problem?
Input
There are multiple test cases. The first line of input contains an integer T (1 ≤ T ≤ 105), indicating the number of test cases. For each test case:
The first and only line contains an integer n (1 ≤ n ≤ 109) and a capitalized eight-digit hexadecimal number m (00000000 ≤ m ≤ FFFFFFFF), their meanings are described above.
We kindly remind you that this problem contains large I/O file, so it's recommended to use a faster I/O method. For example, you can use scanf/printf instead of cin/cout in C++.
Output
For each test case output one line, indicating the total units of energy consumed by the eight-digit seven segment display component.
Sample Input
3
5 89ABCDEF
3 FFFFFFFF
7 00000000
Sample Output
208
124
327
Hint
For the first test case, the counter will display 5 hexadecimal numbers (89ABCDEF, 89ABCDF0, 89ABCDF1, 89ABCDF2, 89ABCDF3) in 5 seconds. The total units of energy cost is (7 + 6 + 6 + 5 + 4 + 5 + 5 + 4) + (7 + 6 + 6 + 5 + 4 + 5 + 4 + 6) + (7 + 6 + 6 + 5 + 4 + 5 + 4 + 2) + (7 + 6 + 6 + 5 + 4 + 5 + 4 + 5) + (7 + 6 + 6 + 5 + 4 + 5 + 4 + 5) = 208.
For the second test case, the counter will display 3 hexadecimal numbers (FFFFFFFF, 00000000, 00000001) in 3 seconds. The total units of energy cost is (4 + 4 + 4 + 4 + 4 + 4 + 4 + 4) + (6 + 6 + 6 + 6 + 6 + 6 + 6 + 6) + (6 + 6 + 6 + 6 + 6 + 6 + 6 + 2) = 124.
数位DP硬刚
其实就是暴力
#include<bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:102400000,102400000")
#define ls i<<1
#define rs ls | 1
#define mid ((ll+rr)>>1)
#define pii pair<int,int>
#define MP make_pair
typedef long long LL;
const long long INF = 1e18+1LL;
const double Pi = acos(-1.0);
const int N = 1e5+, M = 1e3+, mod = 1e9+, inf = 2e9; LL d[N],dp[][],vis[][],dp1[][];
LL a[] = {,,,,,,,,,,,,,,,};
int id(char ch) {
if(ch >= '' && ch <= '') return ch - '';
else return ch - 'A' + ;
}
LL quick_pow(LL x,LL p) {
if(p<=) return ;
LL ans = quick_pow(x,p>>);
ans = ans*ans;
if(p & ) ans = ans*x;
return ans;
}
LL dfs(int dep,int f,LL x) {
if(dep<) return ;
if(f && vis[dep][f]) return dp[dep][f];
if(f) {
LL& ret = dp[dep][f];
vis[dep][f] = ;
ret += *quick_pow(,dep) + 1LL**dfs(dep-,f,quick_pow(,dep));
return ret;
}
else
{
LL ret = ;
for(int i = ; i <= d[dep]; ++i) {
LL tmp;
if(i < d[dep]) tmp = quick_pow(,dep);
else tmp = x%quick_pow(,dep)+;
ret += (tmp)*a[i] + dfs(dep-,i<d[dep],tmp-);
}
return ret;
}
}
LL solve(LL x) {
if(x < ) return ;
int len = ;
LL tmp = x;
for(LL i = ; i <= ; ++i) {
d[len++] = x%;
x/=;
}
return dfs(len-,,tmp);
}
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
int n;
char s[];
scanf("%d%s",&n,s);
int L = strlen(s);
LL l = ,tmp = ;
for(int i = L-; i >= ; --i) {
l += id(s[i])*tmp;
tmp*=;
}
LL r = l+n-,ans = ;
if(r > ) {
ans = solve() - solve(l-);
l = ;
r = r--;
}
printf("%lld\n",ans + solve(r) - solve(l-));
}
return ;
} /*
2
3 FFFFFFFF
7 00000000
*/
ZOJ 3962 E.Seven Segment Display / The 14th Zhejiang Provincial Collegiate Programming Contest Sponsored by TuSimple E.数位dp的更多相关文章
- The 14th Zhejiang Provincial Collegiate Programming Contest Sponsored by TuSimple - F 贪心+二分
Heap Partition Time Limit: 2 Seconds Memory Limit: 65536 KB Special Judge A sequence S = { ...
- The 14th Zhejiang Provincial Collegiate Programming Contest Sponsored by TuSimple - C 暴力 STL
What Kind of Friends Are You? Time Limit: 1 Second Memory Limit: 65536 KB Japari Park is a larg ...
- ZOJ 4033 CONTINUE...?(The 15th Zhejiang Provincial Collegiate Programming Contest Sponsored by TuSimple)
#include <iostream> #include <algorithm> using namespace std; ; int a[maxn]; int main(){ ...
- ZOJ 3872 Beauty of Array (The 12th Zhejiang Provincial Collegiate Programming Contest )
对于没有题目积累和clever mind的我来说,想解这道题还是非常困难的,也根本没有想到用dp. from: http://blog.csdn.net/u013050857/article/deta ...
- zoj The 12th Zhejiang Provincial Collegiate Programming Contest Capture the Flag
http://acm.zju.edu.cn/onlinejudge/showContestProblem.do?problemId=5503 The 12th Zhejiang Provincial ...
- ZOJ 3946.Highway Project(The 13th Zhejiang Provincial Collegiate Programming Contest.K) SPFA
ZOJ Problem Set - 3946 Highway Project Time Limit: 2 Seconds Memory Limit: 65536 KB Edward, the ...
- zoj The 12th Zhejiang Provincial Collegiate Programming Contest Team Formation
http://acm.zju.edu.cn/onlinejudge/showContestProblem.do?problemId=5494 The 12th Zhejiang Provincial ...
- zoj The 12th Zhejiang Provincial Collegiate Programming Contest Beauty of Array
http://acm.zju.edu.cn/onlinejudge/showContestProblem.do?problemId=5496 The 12th Zhejiang Provincial ...
- zoj The 12th Zhejiang Provincial Collegiate Programming Contest Lunch Time
http://acm.zju.edu.cn/onlinejudge/showContestProblem.do?problemId=5499 The 12th Zhejiang Provincial ...
随机推荐
- JavaScript:对Object对象的一些常用操作总结
JavaScript对Object对象的一些常用操作总结. 一.Object.assign() 1.可以用作对象的复制 var obj = { a: 1 }; var copy = Object.as ...
- CSS3---圆角设置
1.border-radius是向元素添加圆角边框.border-radius:10px; /* 所有角都使用半径为10px的圆角 */ border-radius: 5px 4px 3px ...
- Spring异常——BeanNotOfRequiredTypeException
使用junit测试ssh搭建的框架的时候,遇到了一个异常: 异常消息: org.springframework.beans.factory.BeanCreationException: Error c ...
- Sql Server数据库视图的创建、修改
if OBJECT_ID('Sales.USACusts') is not null drop view Sales.USACusts; go create view Sales.USACusts a ...
- 复(学)习化学时突然的一个 idea
期中考试成功探底...但是某些化学问题还是很有信息学价值的... n 烷同分异构体计数. 这个题 fanhq666 出过,就是一个 dp. 设 f[i] 表示含有 i 个节点的无标号不同构的度数限制为 ...
- 前端的指导方针---css篇
英语是渣渣,想学英语,又不想花钱报培训班.看不懂的文章,还是翻译一下留着自己看吧. 引自 : https://github.com/bendc/frontend-guidelines HTML ...
- mysql查所有列名
查询该视图 information_schema.columns 该有的都有 desc information_schema.columns; select * from information_ ...
- 牛客网暑期ACM多校训练营(第九场) A题 FWT
链接:https://www.nowcoder.com/acm/contest/147/A来源:牛客网 Niuniu has recently learned how to use Gaussian ...
- eclipse菜单字体乱码的解决
方法一: 这个跟活动控制台代码页有关. 如果要更改为 UTF-8,则需要运行 chcp 命令: chcp 65001 有时新安装的系统可能在运行一些中文软件时显示错乱,可通过控制面板修改系统区域来管理 ...
- 【Nginx】负载均衡
本文介绍的负载均衡是针对的客户端请求在多个Nginx进程之间的均衡.注意与客户端请求在多个后端服务器之间的均衡相区别. 负载均衡问题的产生 在nginx中,建立连接的时候,会设计负载均衡问题.在多个子 ...















