UVA 11038 - How Many O's? 计算对答案的贡献
题意: 求[n, m]之间包含0的数字的个数
题解:转化为求solve(n) - solve(m-1)的前缀问题
对于求0到n的解,我们举例 n = 25789 对于8这位,让其为0对答案的贡献是 (0~257)*(0~9)
假设是 n = 25709 那么让这位为0的答案贡献是 (0~256) * (0~9) + (257)* (0~9)
//meek///#include<bits/stdc++.h>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include<iostream>
using namespace std ;
#define mem(a) memset(a,0,sizeof(a))
#define pb push_back
#define fi first
#define se second
#define MP make_pair
typedef long long ll; const int N = (<<)*;
const int M = ;
const int inf = 0x3f3f3f3f;
const int MOD = ;
const double eps = 0.000001; ll n,m;
ll solve(ll l) {
if(l < ) return ;
ll x = , r = ;
ll ans = ;
while(l >= ) {
ll now = l % ;
l /= ;
if(now) ans += l*x;
else ans += (l-)*x + r + ;
r = r + now*x;
x *= ;
}
return ans;
}
int main() {
while(scanf("%lld%lld",&n,&m)!=EOF) {
if(n == - && m == -) break;
printf("%lld\n", solve(m) - solve(n-));
}
return ;
}
UVA 11038 - How Many O's? 计算对答案的贡献的更多相关文章
- UVA 11076 Add Again 计算对答案的贡献+组合数学
A pair of numbers has a unique LCM but a single number can be the LCM of more than one possiblepairs ...
- ZOJ 3872 计算对答案的贡献
D - Beauty of Array Description Edward has an array A ...
- UVa 109 - SCUD Busters(凸包计算)
题目来源:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=3&pa ...
- uva 11038 - How Many O's?
想法: 將問題簡化為求1~m 0的總數,以及1~n 0的總數,然後最後再相減. 求1~n 0的總數,要將n分別算每個位數0的個數,舉例如30324: 先從右邊第一位'4'開始,其左邊為3032,表示1 ...
- How Many O's? UVA - 11038
这个题个人感觉有点难,不容易理解. 题意 给你两个数,n,m,找出从n到m所有的数一共包含几个0,看似简单,包含0的不就都是整数么,然后就用暴力循环来找,绝对TL.我自己写这题也没有什么好的办法,没有 ...
- UVa 11038 有多少个0
https://vjudge.net/problem/UVA-11038 题意: 输入两个非负整数m和n,求将m~n的所有整数写出来,一共要写多少个数字0? 思路: 举个例子来说: 12345 从右到 ...
- [poj 3904] sky code 解题报告(组合计算+容斥原理)
题目链接:http://poj.org/problem?id=3904 题目大意: 给出一个数列,询问从中取4个元素满足最大公约数为1的方案数 题解: 很显然,ans=总的方案数-最大公约数大于1的4 ...
- 2016.08.07计算几何总结测试day2
T1 bzoj: [Usaco2010 OPen]Triangle Counting 数三角形 看到这个题n那么大, 于是想到极角排序搞一搞,然而排完序后立马懵逼,完全不知道接下来应该怎么写.... ...
- HDU 5514 Frogs (容斥原理)
题目链接 : http://acm.hdu.edu.cn/showproblem.php?pid=5514 题意 : 有m个石子围成一圈, 有n只青蛙从跳石子, 都从0号石子开始, 每只能越过a[i] ...
随机推荐
- aliyun install php apache mysql nginx
yum install httpd -y yum install mysql mysql-server -y yum install php-mysql php-pgsql php-pecl-mong ...
- 插入排序 & 快速排序
2.1 插入排序: 接口定义: int insert_sort(void* data, int size, int esize, int (*compare)(const void* key1, co ...
- 3-附1 ->和*的区别
问题: c++ .和 ->有什么区别? 还有什么是继承什么是派生?-------------------------------------------------------------- 比 ...
- 61.MII、RMII、GMII接口的详细介绍
概述: MII (Media Independent Interface(介质无关接口)或称为媒体独立接口,它是IEEE-802.3定义的以太网行业标准.它包括一个数据接口和一个MAC和PHY之间的管 ...
- 线程同步 Lock接口
同步:★★★★★ 好处:解决了线程安全问题. 弊端:相对降低性能,因为判断锁需要消耗资源,产生了死锁. 定义同步是有前提的: 1,必须要有两个或者两个以上的线程,才需要同步. 2,多个线程必须保证使用 ...
- Windows python 安装 nNumpy、Scipy、matplotlib模块
折腾了 很久,总结一些. 首先如果python 是64位,安装32位的numpy ,Scipy,或者matplotlib 模块. 会出现很多问题. 比如当你 在python 导入 Numpy 时,导入 ...
- Android BLE API: GATT Notification not received
When setting the value to the descriptor instead of putting descriptor.setValue(BluetoothGattDescrip ...
- 阿里云服务器Node环境配置
最近,将网站的阿里云服务器迁移到阿里云北京机房,记录下CentOS的迁移过程. 首次登录云服务器,要先进行用户设置. 用户设置 首先用passwd命令修改超级管理员root密码. $ passwd 根 ...
- Shell遍历文件的每一行[转载]
#!/bin/sh while read line do echo $line done < /home/jms/lab/input.txt
- Json Serialize 忽略特定属性
Json Serialize 忽略特定属性 Json Serialize SerializeFilter 忽略特定属性 key words:Json Serialize jackson fastjso ...