bzoj3134: [Baltic2013]numbers
稍微用脑子想一想,要是一个回文数,要么s[i]==s[i+1]要么s[i]==s[i+2]就可以实锤了
所以多开两维表示最近两位选的是什么数就完了
注意前导0
#include<cstdio>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
using namespace std;
typedef long long LL;
const int mbit=; LL f[mbit][mbit][mbit];//第i位,第i位和第i-1位放的是啥 -----> 非回文数个数 (有前导零)
LL g[mbit];//枚举到第i位 -----> 非回文数个数 (无前导零)
void init()
{
g[]=,g[]=;
for(int i=;i<=;i++)
for(int j=;j<=;j++)
if(i!=j)f[][i][j]=;
for(int i=;i<=;i++)
{
for(int u=;u<=;u++)
for(int v=;v<=;v++) if(u!=v)
for(int w=;w<=;w++) if(u!=w&&v!=w)
f[i][u][v]+=f[i-][v][w];
g[i]=g[i-];
for(int u=;u<=;u++)
for(int v=;v<=;v++)
g[i]+=f[i][u][v];
}
} int clen,c[mbit];
LL getnum(LL k)
{
if(k<)return ;
LL t=k;clen=;
while(t>){c[++clen]=t%;t/=;}
if(clen==)clen++;
c[clen+]=-;c[clen+]=-; LL ret=;
for(int i=clen;i>=;i--)
{
int li=c[i]-;if(i==)li++;
for(int j=;j<=li;j++)
{
if(j==c[i+]||j==c[i+])continue;
if(i==)ret++;
else if(i==)
{
for(int k=;k<=;k++)
if(k!=c[i+]&&(k!=j||(i==clen&&j==)))ret++;
}
else
{
if(i==clen&&j==)
{
ret+=g[i-];
continue;
} for(int u=;u<=;u++)
for(int v=;v<=;v++)
if(u!=v&& u!=c[i+]&&u!=j&&v!=j )
ret+=f[i-][u][v];
}
}
if(c[i]==c[i+]||c[i]==c[i+])break;
}
return ret;
} int main()
{
freopen("a.in","r",stdin);
freopen("a.out","w",stdout);
init();
LL L,R;
scanf("%lld%lld",&L,&R);
printf("%lld\n",getnum(R)-getnum(L-)); return ;
}
bzoj3134: [Baltic2013]numbers的更多相关文章
- bzoj AC倒序
Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...
- Java 位运算2-LeetCode 201 Bitwise AND of Numbers Range
在Java位运算总结-leetcode题目博文中总结了Java提供的按位运算操作符,今天又碰到LeetCode中一道按位操作的题目 Given a range [m, n] where 0 <= ...
- POJ 2739. Sum of Consecutive Prime Numbers
Sum of Consecutive Prime Numbers Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 20050 ...
- [LeetCode] Add Two Numbers II 两个数字相加之二
You are given two linked lists representing two non-negative numbers. The most significant digit com ...
- [LeetCode] Maximum XOR of Two Numbers in an Array 数组中异或值最大的两个数字
Given a non-empty array of numbers, a0, a1, a2, … , an-1, where 0 ≤ ai < 231. Find the maximum re ...
- [LeetCode] Count Numbers with Unique Digits 计算各位不相同的数字个数
Given a non-negative integer n, count all numbers with unique digits, x, where 0 ≤ x < 10n. Examp ...
- [LeetCode] Bitwise AND of Numbers Range 数字范围位相与
Given a range [m, n] where 0 <= m <= n <= 2147483647, return the bitwise AND of all numbers ...
- [LeetCode] Valid Phone Numbers 验证电话号码
Given a text file file.txt that contains list of phone numbers (one per line), write a one liner bas ...
- [LeetCode] Consecutive Numbers 连续的数字
Write a SQL query to find all numbers that appear at least three times consecutively. +----+-----+ | ...
随机推荐
- bzoj [Scoi2016]美味
[Scoi2016]美味 Time Limit: 30 Sec Memory Limit: 256 MBSubmit: 721 Solved: 391[Submit][Status][Discus ...
- Jerasure库接口简介及性能测试
http://blog.chinaunix.net/uid-20196318-id-3277600.html Jerasure库提供Reed-Solomon和Cauchy Reed-Solomon两种 ...
- BZOJ 3675 [Apio2014]序列分割 (斜率优化DP)
题目链接 BZOJ 3675 首先最后的答案和分割的顺序是无关的, 那么就可以考虑DP了. 设$f[i][j]$为做了$i$次分割,考虑前$j$个数之后的最优答案. 那么$f[i][j] = max( ...
- jquery的固定定位效果
今天做了个固定定位的效果.比如对导航需要进行固定定位效果: 当没有滚动到导航下面,导航正常显示. 当滚动到导航下面,导航就固定到顶部. 这个效果使用了jquery的方法实现,具体思路为: 1)首先获取 ...
- MACBOOK 忘记密码
如果没有系统安装盘,可以采用下面的几种方法:首先,启动机器,启动时按住Apple和S键,以单用户模式(single user mode)进入系统.输入:mount -uv / 然后回车.接下来可以采用 ...
- Linux内核配置选项
http://blog.csdn.net/wdsfup/article/details/52302142 http://www.manew.com/blog-166674-12962.html Gen ...
- widows 2008 同步时间命令
由于windows2008没有提供类似XP的自动同步功能,因此需要使用windows 2008计划任务来运行一行命令进行同步. 首先查看与想要同步时间的internet时间服务器的时差: w32t ...
- jquery ajax 跨域訪问样例
<script type="text/javascript"> $(function(){ $.ajax({ cache : false, type ...
- printf行缓冲区的分析总结
最近在客户那调试串口的时候,read串口然后printf打印,单字符printf,发现没有输出,后来想起来printf这些标准输入输出函数也是属于标准C库glibc的, 这里就要区分一下标准库函数和系 ...
- 翻翻git之---"有趣效果"的自己定义View EasyArcLoading
转载请注明出处:王亟亟的大牛之路 早上写了一个关于MD的文章,下午给编译器调了个色,感觉要上天了.所以为了试颜色就出了这篇文章,让大家一起瞎一下 好了废话不说.这一片给大家介绍一个当做Dialog作用 ...