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 ...
随机推荐
- 利用爬虫、SMTP和树莓派3B发送邮件&续集&(爬取墨迹天气预报信息)
-----------------------------------------------学无止境----------------------------------------------- 前 ...
- java后台接收微信服务号/订阅号消息
1.申请订阅号(适合个人)或者服务号(适合企业) 微信公众平台 2.填写配置 服务器地址: 需要接收消息 的服务端接口地址 令牌:通话识别码,随便写,后端接收时,使用一样的就可以了. 消息加密秘钥 : ...
- Visual Studio Code——PHP Debug扩展
最近在使用PHP开发,使用了很多IDE,发现都不是很顺手,之前一直都在使用Sublime Text,但是作为一个爱折腾的人,当我发现VS Code以后觉得很是很适合自己的编程需要的.配置过程中遇到了一 ...
- Python基础 之 tuple类-元组 和 dict类-字典
tuple 元组 一.tuple 类的基本属性 1.元组,有序:元素不可被修改,不能被增加或者删除tuple类 tu = (111,22,33,44) 一般写元组的时候,推荐在最后加入,和类方法进行区 ...
- 动画效果 ObjectAnimator
学习了一下动画效果的使用,做一下笔记 ImageView imageView = findViewById(R.id.imageView); ObjectAnimator.ofFloat(imageV ...
- Java Class Object
Object类 它是所有类的基类. public class Person { } //实际上是 public class Person extends Object { } Object类的方法 t ...
- 【android】实现手指滑动来切换activity(转)
http://code.eoe.cn/115 1.jpg外部引用 原始文档 MainActivity.java外部引用 原始文档 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 ...
- windows编程了解
文章:浅谈Windows API编程 (这个经典)
- iOS- 用MapKit和CoreLocation 来实现移动设备(地图与定位)
1.前言 发现在很多的社交软件都引入了地图和定位功能,如果我们要想实现这两大功能,需要利用到两个框架:MapKit和CoreLocation 我们先来看看CoreLocation框架: 它可以 ...
- TCP系列03—连接管理—2、TCP连接的同时打开和同时关闭
在前面的内容中我们介绍了TCP连接管理中最常见的三次握手方式和四次挥手的方式.但是有可能A和B两端同时执行主动打开并连接对方或者同时执行主动关闭连接(尽管发生这种情况的可能性比较低低),这个时候的流程 ...