C. Classy Numbers

题目链接:https://codeforces.com/contest/1036/problem/C

题意:

给出n个询问,每个询问给出Li,Ri,问在这个闭区间中有多少个数满足,除开0之外,最多只有4个数字。

题解:

由于题目给出的数满足前缀性质,所以我们可以直接求[1,r]这个区间中有多少个数满足就好了。

具体做法就是从高位往低位来看,然后如果当前数组不为0,假设为p,那么当前数组对答案的贡献就比较好计算了,假设后面的数有x位,目前已经有k个数字了。

那么分两种情况:一种是当前这位为0的时候,那么贡献就是C(x,3-k);另外一种就是当前这位为1~p-1的时候,贡献就是(p-1)*C(x,3-k-1)。

当前为p的情况我们留在后面统计就行了,因为这种情况主要是取决后面的数的。

细节见代码吧:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll C[][];
int T;
ll a,b;
int num[],pow9[]={,,,};
ll calc(ll x,ll k){
ll ans = ;
if(x<=) return ;
for(int i=;i<=k;i++) ans+=C[x][i]*pow9[i];
return ans ;
}
ll solve(ll x){
memset(num,,sizeof(num));
int n;
for(n=;x;n++){
num[n]=x%;
x/=;
}
n--;
ll ans = ;
for(int i=n,cur=;i>=;i--){
if(!num[i]) continue ;
ans+=calc(i-,cur);
cur--;
ans+=(num[i]-)*calc(i-,cur);
if(cur==) break ;
//if(i==1) ans++;
}
return ans ;
}
int main(){
ios::sync_with_stdio(false);cin.tie();
C[][]=;C[][]=;
for(int i=;i<=;i++){
C[i][]=;
for(int j=;j<=i;j++){
C[i][j]=C[i-][j]+C[i-][j-];
}
}
cin>>T;
while(T--){
cin>>a>>b;
//cout<<solve(b)<<" "<<solve(a-1)<< '\n';
cout<<solve(b)-solve(a-)<< '\n';
}
return ;
}

Educational Codeforces Round 50 (Rated for Div. 2) C. Classy Numbers的更多相关文章

  1. Educational Codeforces Round 50 (Rated for Div. 2) F - Relatively Prime Powers(数学+容斥)

    题目链接:http://codeforces.com/contest/1036/problem/F 题意: 题解:求在[2,n]中,x != a ^ b(b >= 2 即为gcd)的个数,那么实 ...

  2. Educational Codeforces Round 50 (Rated for Div. 2)的A、B、C三题AC代码

    A题链接:https://codeforces.com/contest/1036/problem/A A题AC代码: #include <stdio.h> #include <std ...

  3. Educational Codeforces Round 50 (Rated for Div. 2)F. Relatively Prime Powers

    实际上就是求在[2,n]中,x != a^b的个数,那么实际上就是要求x=a^b的个数,然后用总数减掉就好了. 直接开方求和显然会有重复的数.容斥搞一下,但实际上是要用到莫比乌斯函数的,另外要注意减掉 ...

  4. Educational Codeforces Round 50 (Rated for Div. 2) E. Covered Points

    注释上都有解析了,就不写了吧,去重的问题就用set解决,并且呢第i个线段最多和其他线段产生i-1个交点,n^2logn. #include <cmath> #include <cst ...

  5. Educational Codeforces Round 65 (Rated for Div. 2) B. Lost Numbers

    链接:https://codeforces.com/contest/1167/problem/B 题意: This is an interactive problem. Remember to flu ...

  6. Educational Codeforces Round 65 (Rated for Div. 2)B. Lost Numbers(交互)

    This is an interactive problem. Remember to flush your output while communicating with the testing p ...

  7. Codeforces Educational Codeforces Round 44 (Rated for Div. 2) F. Isomorphic Strings

    Codeforces Educational Codeforces Round 44 (Rated for Div. 2) F. Isomorphic Strings 题目连接: http://cod ...

  8. Educational Codeforces Round 63 (Rated for Div. 2) 题解

    Educational Codeforces Round 63 (Rated for Div. 2)题解 题目链接 A. Reverse a Substring 给出一个字符串,现在可以对这个字符串进 ...

  9. Educational Codeforces Round 60 (Rated for Div. 2) - C. Magic Ship

    Problem   Educational Codeforces Round 60 (Rated for Div. 2) - C. Magic Ship Time Limit: 2000 mSec P ...

随机推荐

  1. 【button】 按钮组件说明

    原型: <button size="[default | mini]" type="[primary | default | warn]" plain=& ...

  2. 代码对齐 (Alignment of Code,ACM/ICPC NEERC 2010,UVa1593)

    题目描述: 解题思路: 输入时提出单个字符串,并用一个数组记录每列最长长度,格式化输出 #include <iostream> #include <algorithm> #in ...

  3. 本地矩阵(Local Matrix)

    本地矩阵具有整型的行.列索引值和双精度浮点型的元素值,它存储在单机上.MLlib支持稠密矩阵DenseMatrix和稀疏矩阵Sparse Matrix两种本地矩阵,稠密矩阵将所有元素的值存储在一个列优 ...

  4. OpenMPI 集群配置

    现在有2台机器,希望可以尝试一下在多台机器上跑MPI的感觉,所以跑之前就得配置,先参考网址: https://www.cnblogs.com/awy-blog/p/3402949.html: 1. 配 ...

  5. 国内版Office365实现MFA的方案(未完)

    现在二十一世纪互联版也可以实现了MFA,现在也就是2017年3月份,支持了PC,但是对移动端应用还是不支持的,请了解. 具体方法如下: 登录国内版Office365(事例为高级商业版 https:// ...

  6. HDFS essay 2 - Clarify Name Node / Checkpoint Node/ Backup Node

    为什么想用英文写了?我获取知识.技术的大部分途径都是通过英文,所以按照自己的理解用英文写下来也比较容易,另外,很多term都是不能翻译的,如果要持续学习技术和知识,那就不但要习惯去阅读,听,还要写,说 ...

  7. 统计学习三:1.k近邻法

    全文引用自<统计学习方法>(李航) K近邻算法(k-nearest neighbor, KNN) 是一种非常简单直观的基本分类和回归方法,于1968年由Cover和Hart提出.在本文中, ...

  8. Alpha项目冲刺_博客链接合集

    组员 学号 林泽宇(队长) 211606317 李涵 211606365 尹海川 211606388 郏敏杰 211606307 何永康 211606362 陈炳旭 211606353 苏宇翔 211 ...

  9. ASP.NET 使用MVC4的EF5 Code First 入门(一):创建数据库

    一.基本流程 建立模型→建立控制器→EF框架自动生成视图的数据库 二.基本理论 1.约定优于配置(Convention Over Configuration) 设计不好的框架通常需要多个配置文件,每一 ...

  10. js控制input只能输入数字和小数点后两位,输入其他自动清除方法。

    工作中input='text'总会遇到要控制输入数字,或者是输入中文,输入电话,输入身份证号,邮箱等.今天我遇到的是要输入数字并且只能小数点后面两位的数字,还不能为负数.废话不多说上代码: <i ...