Educational Codeforces Round 50 (Rated for Div. 2) C. Classy Numbers
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的更多相关文章
- 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)的个数,那么实 ...
- 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 ...
- Educational Codeforces Round 50 (Rated for Div. 2)F. Relatively Prime Powers
实际上就是求在[2,n]中,x != a^b的个数,那么实际上就是要求x=a^b的个数,然后用总数减掉就好了. 直接开方求和显然会有重复的数.容斥搞一下,但实际上是要用到莫比乌斯函数的,另外要注意减掉 ...
- Educational Codeforces Round 50 (Rated for Div. 2) E. Covered Points
注释上都有解析了,就不写了吧,去重的问题就用set解决,并且呢第i个线段最多和其他线段产生i-1个交点,n^2logn. #include <cmath> #include <cst ...
- 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 ...
- 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 ...
- 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 ...
- Educational Codeforces Round 63 (Rated for Div. 2) 题解
Educational Codeforces Round 63 (Rated for Div. 2)题解 题目链接 A. Reverse a Substring 给出一个字符串,现在可以对这个字符串进 ...
- 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 ...
随机推荐
- 关于java使用double还是float
眼睛一亮在论坛上发现一枚很有价值的评论赶紧抄下来... 记住java一定要用double,更鼓不变,就算数值不大也要用double.了解java虚拟机的底层会知道,float放在内存中其实是当作dou ...
- Spark- 根据IP获取城市(java)
开源 IP 地址定位库 ip2region 1.4 ip2region 是准确率 99.9% 的 IP 地址定位库,0.0x毫秒级查询,数据库文件大小只有 2.7M,提供了 Java.PHP.C.Py ...
- 清橙 A1318 加强版:Almost
题意: 直接看题面吧 原版:\(n \leq 1e5, q \leq 3e4, TL 5s, ML 256G\) 加强版1:\(n,q \leq 1.5e5, TL 5s, ML 256G\) 加强版 ...
- Period :KMP
I - Period Problem Description For each prefix of a given string S with N characters (each character ...
- 浅谈PCA
最近在回顾PCA方面的知识,发现对于之前的很多东西有了新的理解,下面和大家分享下我的一些个人的理解 1.我们为什么要用PCA,它能解决我什么问题? PCA(Principal Component An ...
- metamask注记词
leaf orbit poet zebra toy day put dinosaur review cool pluck throw(m) 一个钱包地址 里面有多个账号 菲苾代表了不同网络
- Python3 Tkinter-Radionbutton
1.创建单选按钮 from tkinter import * root=Tk() Radiobutton(root,text='b1').pack() Radiobutton(root,text='b ...
- Python3 Tkinter-Checkbutton
1.多选按钮创建 from tkinter import * root=Tk() Checkbutton(root,text='python').pack() root.mainloop() 2.绑定 ...
- SpringCloud IDEA 教学 番外篇 后台运行Eureka服务注册中心
写在开头 研发过程中经常要做的事就是启动Eureka服务注册中心,每每都要启动一个IDEA,很是困扰.现在分享一个后台启动服务注册中心的方法. 准备工作 1打包一个eureka服务注册中心jar包(注 ...
- Nodejs第一天-{Nodejs基础 深刻理解浏览器 环境变量 基础语法}
Nodejs第一天 1.什么是Nodejs Nodejs是一个可以运行(解析)ECMAScript的环境; ECMAScript是规定了一些列的语法 ,这些语法想要解析的执行就需要放在某个环境 ...