UVa 12683 Odd and Even Zeroes(数论+数字DP)
意甲冠军: 要求 小于或等于n号码 (0<=n <= 1e18)尾数的数的阶乘0数为偶数
思考:当然不是暴力,因此,从数论。尾数0数为偶数,然后,它将使N阶乘5电源是偶数。(二指数肯定少5指数),乞讨N。阶乘5该指数是N/5+ N/25+N/125。
。
。。
以530为例。尝试着将转化为5进制 即为 4110。那么5的指数 就是 411+41+4 (5进制)easy发现要使这个数是偶数。就是要使5进制奇数位的个数为偶数。依据刚才那个加法,能够看出,最后结果的5进制的末位就是411+41+4 的末位 即 4+1+1 即为原数最高位到最低第二位每一位的和,末二位依次类推。。。。
。
那么仅仅要做到这里。。。接下来就是数位DP的事了,DP[pos][parity][presum]
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
using namespace std;
typedef long long LL;
vector<int> digit;
#define REP(_,a,b) for(int _ = (a); _ <= (b); _++)
LL dp[30][2][2];
LL n;
LL dfs(int pos,int parity,int sum,bool done) {
if(pos==0) {
if(parity==0) {
int sz = done?digit[pos]:4;
return sz+1;
}else{
return 0;
} }
if(!done && dp[pos][parity][sum] != -1) return dp[pos][parity][sum];
LL ret = 0;
int end = done? digit[pos]:4;
for(int i = 0; i <= end; i++) {
ret += dfs(pos-1,(parity+(sum+i)&1)&1,(sum+i)&1,done&&i==end ) ;
}
if(!done) dp[pos][parity][sum] = ret;
return ret;
}
LL solve(LL n) {
if(n <= 4) return n+1;
memset(dp,-1,sizeof dp);
digit.clear();
while(n) {
digit.push_back(n%5);
n /= 5;
}
return dfs(digit.size()-1,0,0,1);
}
int main(){ while(~scanf("%lld",&n) && n !=-1) {
printf("%lld\n",solve(n));
}
return 0;
}
版权声明:本文博主原创文章。博客,未经同意不得转载。
UVa 12683 Odd and Even Zeroes(数论+数字DP)的更多相关文章
- UVA 12683 Odd and Even Zeroes(数学—找规律)
Time Limit: 1000 MS In mathematics, the factorial of a positive integer number n is written as n! an ...
- UVALive - 6575 Odd and Even Zeroes 数位dp+找规律
题目链接: http://acm.hust.edu.cn/vjudge/problem/48419 Odd and Even Zeroes Time Limit: 3000MS 问题描述 In mat ...
- UVA.12716 GCD XOR (暴力枚举 数论GCD)
UVA.12716 GCD XOR (暴力枚举 数论GCD) 题意分析 题意比较简单,求[1,n]范围内的整数队a,b(a<=b)的个数,使得 gcd(a,b) = a XOR b. 前置技能 ...
- 【bzoj4872】[Shoi2017]分手是祝愿 数论+期望dp
题目描述 Zeit und Raum trennen dich und mich. 时空将你我分开. B 君在玩一个游戏,这个游戏由 n 个灯和 n 个开关组成,给定这 n 个灯的初始状态,下标为从 ...
- 训练指南 UVA - 11324(双连通分量 + 缩点+ 基础DP)
layout: post title: 训练指南 UVA - 11324(双连通分量 + 缩点+ 基础DP) author: "luowentaoaa" catalog: true ...
- HDU - 4734 F(x) (2013成都网络游戏,数字DP)
意甲冠军:求0-B见面<=F[A]所有可能的 思维:数字DP,内存搜索 #include <iostream> #include <cstring> #include & ...
- UVa 1640 - The Counting Problem(数论)
链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...
- UVA 11246 - K-Multiple Free set(数论推理)
UVA 11246 - K-Multiple Free set 题目链接 题意:一个{1..n}的集合.求一个子集合.使得元素个数最多,而且不存在有两个元素x1 * k = x2,求出最多的元素个数是 ...
- UVa 106 - Fermat vs Pythagoras(数论题目)
题目来源:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=3&pa ...
随机推荐
- PropertiesDemo
import org.apache.commons.configuration.ConfigurationException; import org.apache.commons.configurat ...
- 西南民大oj(递推)
我的数学不可能那么难推 时间限制(普通/Java) : 3000 MS/ 9000 MS 运行内存限制 : 65536 KByte总提交 : 49 测试通过 : ...
- BGP协议学习总结
BGP学习总结 BGP是目前使用的唯一的自治系统间的路由协议,它是一种矢量路由协议,基于TCP的179号端口,它采用单播增量更新的方式更新路由,与其他的路由协议不同的是,BGP只要TCP可达,就可以建 ...
- 安装IntelliJ IDEA JetGroovy(转)
JetGroovy是一个免费而且开源的专用于支持Groovy和Grails的IntelliJ IDEA插件.这个插件是由JetBrains公司自己开发的,对于Groovy语言和Web框架都提供了无以伦 ...
- 开启本地MySql数据库远程连接
解决MySQL不允许从远程访问的方法 开启 MySQL 的远程登陆帐号有两大步: 1.确定服务器上的防火墙没有阻止 3306 端口. MySQL 默认的端口是 3306 ,需要确定防火墙没有阻止 33 ...
- Spring框架简单介绍
原文地址: http://my.oschina.net/myriads/blog/37922 1.使用框架的意义与Spring的主要内容 随着软件结构的日益庞大,软件模块化趋势出现,软件开发也须要多 ...
- HibernateReview Day1 - Introduction
Hibernate已经学过去大概有半个月了,然后默默的忘掉了……所谓Practice makes perfect. 我尽力重新拾起来. 1.什么是ORM 在介绍Hibernate之前,我们先学习下OR ...
- [置顶] ffmpg简介以及用它实现音频视频合并(java)
1.简介 FFmpeg是一个自由软件,可以运行音频和视频多种格式的录影.转档.流功能. 2.下载 源代码 git://git.libav.org/libav.git Windo ...
- ASP.Net 重写IHttpModule 来拦截 HttpApplication 实现HTML资源压缩和空白过滤
务实直接上代码: 1. 重写FilterModule.cs using System; using System.Collections.Generic; using System.Linq; usi ...
- 举例说,在命令模式(Command Pattern)
在前面加上 谈到命令,大部分的人脑海中会想到以下这幅画面 这在现实生活中是一副讽刺漫画,做决定的人不清楚运行决定的人有何特点,瞎指挥.外行领导内行说的就是这样的.只是在软件设计领域,我们显然要为这 ...