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 ...
随机推荐
- .Net Core配置文件
.Net Core下如何管理配置文件 一.前言 根据该issues来看,System.Configuration在.net core中已经不存在了,那么取而代之的是由Microsoft.Extensi ...
- Wix学习整理(4)——关于WiX文件格式和案例HelloWorld的分析
原文:Wix学习整理(4)--关于WiX文件格式和案例HelloWorld的分析 关于WiX文件格式 .wxs是WiX的源文件扩展名..wxs文件以类XML文件的格式来指定了要构造Windows In ...
- hdu2606(递推)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2606 题意: 用1*1,2*2,3*3,4*4的正方形填充4*n的矩形, 问有多少种不同填法. 分析 ...
- Urban Dictionary: psd
Urban Dictionary: psd psd Share on twitter Share on facebook Share on more 3 up, 1 down It means Poo ...
- 使用python向Redis批量导入数据
1.使用pipeline进行批量导入数据.包含先使用rpush插入数据,然后使用expire改动过期时间 class Redis_Handler(Handler): def connect(self) ...
- leetcode 之 Permutation Sequence
Permutation Sequence The set [1,2,3,-,n] contains a total of n! unique permutations. By listing and ...
- 服务器编程入门(1)TCP/IP协议族
问题聚焦: 简单地梳理一下TCP/IP各层的功能和常用协议 详细了解ARP(数据链路层)和DNS(应用层)协议的工作原理 1 TCP/IP协议族体系结构 数据链路层: 职责:实现网卡接口的网络 ...
- VS上的WebService入门贴
由于项目需要,最近要熟悉一下通过IIS发布WebService.首先熟悉一下使用VS来创建webservice并且调用它. //------------------------------------ ...
- 阅读zepto.js的core中的Core methods
学习zepto.js,參考资料:http://www.zeptojs.cn/ 跟jQuery一样.其选择符号也是$; 首先接触的是 $.() 选择 $(selector, [context]) ⇒ ...
- linux下mysql数据的导出和导入
导出整个数据库中的全部数据 1.在linux命令行下输入: mysqldump -u userName -p dabaseName > fileName.sql fileName.sql最好加上 ...