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 ...
随机推荐
- VLine2.0——仿阿里巴巴VIPABC真人视频在线教育(基于Flash支持一对多多对多Web在线视频)
感兴趣的朋友可与我联系:acsebt@qq.com 一.登陆页 二.功能页
- [置顶] Firefox OS 学习——manifest.webapp结构分析
在Firefox OS 学习——Gaia 编译分析 这篇文章多次提到manifest.webapp文件,对于做过android app 开发的人来说,都很熟悉Android.mk 和Manifest ...
- CSS selectors for Selenium with example,selenium IDE
CSS selectors for Selenium with example http://seleniumeasy.com/selenium-tutorials/css-selectors-tut ...
- 单点更新线段树 RMQ
D. Xenia and Bit Operations time limit per test 2 seconds memory limit per test 256 megabytes input ...
- OpenCV 通过 MFC 的 Picture Control 控件操作图像
假设希望对显示在MFC Picture Control 控件里的图像进行操作,比方画线画点之类的,能够利用 OpenCV 结合 MFC 本身的鼠标响应函数来实现. 怎样将图像显示到 Picture C ...
- 怎样使用docker不加sudo
有时候发现docker有的指令必须加sudo才干运行,通过下面三步设置便可不加sudo直接运行docker指令: 1. 假设还没有docker group就加入一个: sudo groupadd do ...
- pcie inbound、outbound及EP、RC间的互相訪问
Inbound:PCI域訪问存储器域 Outbound:存储器域訪问PCI域 RC訪问EP: RC存储器域->outbound->RC PCI域->EP PCI域->inbou ...
- hdu 1698 Just a Hook(线段树之 成段更新)
Just a Hook Time Limit: ...
- CentOS 6.4 文件夹打开方式
CentOS 6.4 文件夹打开方式 在CentOS 6.4中,双击文件夹,默认会在新窗口中打开文件夹,没有路径.前进.后退这样的按钮,如果一个文件夹的路径很深,则需要打开n多的窗口才能找到最终想要的 ...
- zabbix 监控特定进程
因为一些server上跑着一些重要程序,须要对它们进行监控,公司用的是zabbix监控,之前都是在zabbix中加入自己定义脚本对特定程序进行监控,近期看了zabbix的官方文档,发现原来强大的zab ...