题意:   求[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? 计算对答案的贡献的更多相关文章

  1. 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 ...

  2. ZOJ 3872 计算对答案的贡献

                                                   D - Beauty of Array Description Edward has an array A ...

  3. UVa 109 - SCUD Busters(凸包计算)

    题目来源:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=3&pa ...

  4. uva 11038 - How Many O's?

    想法: 將問題簡化為求1~m 0的總數,以及1~n 0的總數,然後最後再相減. 求1~n 0的總數,要將n分別算每個位數0的個數,舉例如30324: 先從右邊第一位'4'開始,其左邊為3032,表示1 ...

  5. How Many O's? UVA - 11038

    这个题个人感觉有点难,不容易理解. 题意 给你两个数,n,m,找出从n到m所有的数一共包含几个0,看似简单,包含0的不就都是整数么,然后就用暴力循环来找,绝对TL.我自己写这题也没有什么好的办法,没有 ...

  6. UVa 11038 有多少个0

    https://vjudge.net/problem/UVA-11038 题意: 输入两个非负整数m和n,求将m~n的所有整数写出来,一共要写多少个数字0? 思路: 举个例子来说: 12345 从右到 ...

  7. [poj 3904] sky code 解题报告(组合计算+容斥原理)

    题目链接:http://poj.org/problem?id=3904 题目大意: 给出一个数列,询问从中取4个元素满足最大公约数为1的方案数 题解: 很显然,ans=总的方案数-最大公约数大于1的4 ...

  8. 2016.08.07计算几何总结测试day2

    T1 bzoj: [Usaco2010 OPen]Triangle Counting 数三角形 看到这个题n那么大, 于是想到极角排序搞一搞,然而排完序后立马懵逼,完全不知道接下来应该怎么写.... ...

  9. HDU 5514 Frogs (容斥原理)

    题目链接 : http://acm.hdu.edu.cn/showproblem.php?pid=5514 题意 : 有m个石子围成一圈, 有n只青蛙从跳石子, 都从0号石子开始, 每只能越过a[i] ...

随机推荐

  1. hdu 1434 幸福列车

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=1434 幸福列车 Description 一批幸福的列车即将从杭州驶向幸福的终点站——温州,身为总列车长 ...

  2. windows phone 新手引导

    说到windows phone 新手这个问题,当初我们纠结了很久,网上大致有两种解决方案:一种是通过动画的方式:另一种简单的方式就是通过pivot 在第一种方式里面我们的实现思路就是监测手势的滑动方向 ...

  3. ListView与GridView异步加载图片

    原理很简单,主要是用到了回调方法,下面是异步加载图片的类 <span style="font-size:16px;">package com.xxx.xxx; impo ...

  4. sql语句查询经纬度范围

    指定一个经纬度,给定一个范围值(单位:千米),查出在经纬度周围这个范围内的数据. 经度:113.914619 纬度:22.50128 范围:2km longitude为数据表经度字段 latitude ...

  5. openssl AES加密以及padding

    好习惯,先上代码再说事 加密 void AesEncrypt(unsigned char* pchIn, int nInLen, unsigned char *ciphertext, int & ...

  6. Reverse String

    Write a function that takes a string as input and returns the string reversed. Example:Given s = &qu ...

  7. Effective Objective-C 2.0之Note.01

    1.在类的头文件中尽量少引入其他头文件 除非确有必要,否则不要引入头文件.一般来说,应在某个类的头文件中使用向前声明来提及别的类,并在实现文件中引入那些类的头文件.这样做可以尽量降低类之间的耦合(co ...

  8. 发布项目MVC4-EF6.0出错

    出错: The Entity Framework provider type 'System.Data.Entity.SqlServer.SqlProviderServices, EntityFram ...

  9. ExtJS FormPanel不执行校验

    经检查问题原因在于使用了 validator 属性. 使用validator属性,必须添加返回值.不添加返回值,就会出现FormPanel不执行校验的问题.

  10. DXP中原理图与PCB图元件互找

    在原理图中找到元件,快捷键TS即可在PCB中找到元件,且为选中状态.