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 ...
随机推荐
- 在不使用ssr的情况下解决Vue单页面SEO问题
遇到的问题: 近来在写个人博客的时候遇到了大家可能都会遇到的问题 Vue单页面在SEO时显得很无力,尤其是百度不会抓取动态脚本 Vue-Router配合前后端分离无法让meta标签在蜘蛛抓取时动态填充 ...
- 03 数据解析-Xpath
Xpath解析 XPath在Python的爬虫学习中,起着举足轻重的地位,对比正则表达式 re两者可以完成同样的工作,实现的功能也差不多,但XPath明显比re具有优势,在网页分析上使re退居二线. ...
- 使用 ES (elasticsearch) 搜索中文
1.创建索引 curl -XPUT http://172.16.125.139:9200/ques2.创建索引类型 curl -XPOST http://172.16.125.139:9200/que ...
- zzuli 1905 小火山的跳子游戏
Description 小火山和火山火山在一块玩跳子游戏.规则如下: 1:跳子的起始位置为0,棋盘大小从1到N 2:每次跳子跳k步. 例如当前位置为i, 那么下一步为i + k 3:跳 ...
- [BZOJ4207]Can
[BZOJ4207]Can 试题描述 这个问题是源于一个在棋盘上玩的,由Sid Sackson设计的名叫Can't stop的游戏的.这个问题与Can't stop有一定的相似之处,但是不需要玩过Ca ...
- 修改K/3 Cloud管理中心端口
有时候可能会应为端口号被占用或者数据隔离等等,不会使用K/3 Cloud默认的8000端口,这时候就设计到要修改端口号了,具体步骤如下: 1. 2. 打开{安装目录}\ManageSite\App_D ...
- 推荐10+必备的 WordPress 常用插件
众多的WordPress插件,使得WordPress的功能得到了较大的扩展,但是也正是由于过多的插件,导致我们很难选择所需的插件.今天,倡萌就根据自己的经验,给WordPress新手推荐一些常用的插件 ...
- POJ 1704 Georgia and Bob【博弈】
题目链接: http://poj.org/problem?id=1704 题意: 给定棋子及其在格子上的坐标,两个人轮流选择一个棋子向左移动,每次至少移动一格,但是不可以碰到其他棋子.无路可走的时候视 ...
- struts2 input file多文件同时通过ajax提交
<input type="file" name="files" multiple="multiple">必须是multiple才 ...
- 异步SOCKET分包和组包的一种通用算法
unit uPackage;// 应用协议// cxg 2016-9-23// 包=包头+包体 interface uses SysUtils, Classes, PeachCtrl.Net.Iocp ...















