ZOJ3962 2017 E.Seven Segment Display
数码管从某个状态顺序转移N个状态 计算总共有多少个数码管被点亮 N<=10^9
观察数码管的变化规律,有明显的周期和重复,利用这个性质,计算相对于初始状态,某一位上的某个状态重复了多少次,就可以在常数时间内求得。
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<algorithm>
#include<cmath>
using namespace std;
typedef long long int LL; int main()
{freopen("t.txt","r",stdin);
LL val[16]={6,2,5,5,4,5,6,3,7,6,6,5,4,5,5,4};
LL hpo[9];
hpo[0]=1;
for(int i=1;i<=9;i++)
hpo[i]=hpo[i-1]*16;
int n;
char cc[9];
int num[8];
int T;
scanf("%d",&T);
LL ans;
while(T--)
{
scanf("%d%s",&n,&cc);
for(int i=0;i<8;i++)
{
if(cc[i]<='9'&&cc[i]>='0')num[i]=cc[i]-'0';
if(cc[i]<='F'&&cc[i]>='A')num[i]=cc[i]-'A'+10;
}
ans=0;
for(int i=0;i<8;i++)
ans+=val[num[i]];
LL nv=n;
ans=ans*nv;
LL res=0;
for(int i=7;i>=0;i--)
{
nv=n;
LL pow=hpo[7-i];
nv+=res;
res+=num[i]*pow;
for(int j=1;j<16&&nv>pow;j++)
{
ans+=(((nv-pow)/(pow*16))*pow)*(val[(num[i]+j)%16]-val[num[i]]);
ans+=min((((nv-pow)%(pow*16))),pow)*(val[(num[i]+j)%16]-val[num[i]]);
nv-=pow;
}
}
printf("%lld\n",ans);
}
return 0;
}
ZOJ3962 2017 E.Seven Segment Display的更多相关文章
- (2017浙江省赛E)Seven Segment Display
Seven Segment Display Time Limit: 2 Seconds Memory Limit: 65536 KB A seven segment display, or ...
- 2017浙江省赛 E - Seven Segment Display ZOJ - 3962
地址:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3962 题目: A seven segment display, or ...
- ZOJ 3962 Seven Segment Display
Seven Segment Display 思路: 经典数位dp 代码: #include<bits/stdc++.h> using namespace std; #define LL l ...
- ZOJ 3962 Seven Segment Display 16进制的八位数加n。求加的过程中所有的花费。显示[0,F]有相应花费。
Seven Segment Display Time Limit: Seconds Memory Limit: KB A seven segment display, or seven segment ...
- 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 s ...
- ZOJ 3962:Seven Segment Display(思维)
https://vjudge.net/problem/ZOJ-3962 题意:有16种灯,每种灯的花费是灯管数目,代表0~F(十六进制),现在从x开始跳n-1秒,每一秒需要的花费是表示当前的数的花费之 ...
- zoj 3962 Seven Segment Display 数位dp
非常好的一个题,可以比赛时想到的状态太奇葩,不方便转移,就一直没能AC. 思路:dp(i, j)表示已经考虑了前i位,前i位的和为j的贡献.如果当前的选择一直是最大的选择,那么就必须从0~下一位的最大 ...
- ZOJ 3962 Seven Segment Display(数位DP)题解
题意:给一个16进制8位数,给定每个数字的贡献,问你贡献和. 思路:数位DP,想了很久用什么表示状态,看题解说用和就行,其他的都算是比较正常的数位DP. 代码: #include<iostrea ...
- ZOJ 3962 Seven Segment Display(数位DP)
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3962 题目大意: 有t组数据. 给你一个n,和8位的十六进制数s ...
随机推荐
- python多线程和多进程(一)
一.多线程 Python的标准库提供了两个模块:_thread和threading,_thread是低级模块,threading是高级模块,对_thread进行了封装.绝大多数情况下,只需要使用thr ...
- html css笔记 -度一
"""浏览器 shell 内核外表 内心 IE tridentFirefox Geckogoogle chrome webkit/blinksafari webkitop ...
- UI组件之色彩选择器
var myData = { canvas : document.getElementById('colors'),// context : myData.canvas.getContext('2d' ...
- xtu summer individual 6 E - Find Metal Mineral
Find Metal Mineral Time Limit: 1000ms Memory Limit: 65768KB This problem will be judged on HDU. Orig ...
- expdp,impdp,include,exclude
The examples below are based on:- the demo schema SCOTT that is created with script: $ORACLE_HOME/rd ...
- Django开发:(1)django基础 & url控制器
HTTP请求协议 HTTP协议是Hyper Text Transfer Protocol(超文本传输协议)的缩写,是用于万维网(WWW:World Wide Web )服务器与本地浏览器之间传输超文本 ...
- [thrift] thrift基本原理及使用
参考文章RPC 基本原理与 Apach Thrift 初体验 RPC基本原理 RPC(Remote Procedure Call),远程过程调用,大部分的RPC框架都遵循如下三个开发步骤: 1. 定义 ...
- wait和waitpid函数
来源:http://hohahohayo.blog.163.com/blog/static/120816010200971210230362/ wait(等待子进程中断或结束)表头文件 #in ...
- nyoj_10_skiing_201405181748
skiing 时间限制:3000 ms | 内存限制:65535 KB 难度:5 描述 Michael喜欢滑雪百这并不奇怪, 因为滑雪的确很刺激.可是为了获得速度,滑的区域必须向下倾斜,而且当 ...
- Ubuntu 16.04安装ntopng流量监控软件
ntop官方在2012年就已经不再更新,取代的是ntopng.ntopng具有Web页面,适合做网络管理监控软件.比如监控局域网内多台机器的上网情况等. 不过这个东西感觉不太准,最好的方案应该把安装n ...