BZOJ2393: Cirno的完美算数教室
2393: Cirno的完美算数教室
Time Limit: 10 Sec Memory Limit: 128 MB
Submit: 138 Solved: 83
[Submit][Status]
Description
Input
Output
Sample Input
Sample Output
HINT
题解:
同幸运数字,第一次排rank1,哈哈!
代码:
#include<cstdio> #include<cstdlib> #include<cmath> #include<cstring> #include<algorithm> #include<iostream> #include<vector> #include<map> #include<set> #include<queue> #include<string> #define inf 1000000000 #define maxn 1200 #define maxm 500+100 #define eps 1e-10 #define ll unsigned long long #define pa pair<int,int> #define for0(i,n) for(int i=0;i<=(n);i++) #define for1(i,n) for(int i=1;i<=(n);i++) #define for2(i,x,y) for(int i=(x);i<=(y);i++) #define for3(i,x,y) for(int i=(x);i>=(y);i--) #define mod 1000000007 using namespace std; inline ll read() { ll x=,f=;char ch=getchar(); while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();} while(ch>=''&&ch<=''){x=*x+ch-'';ch=getchar();} return x*f; }
ll l,r,ans,tot,n,a[maxn],b[maxn];
ll v[maxn];
inline void dfs(ll x)
{
if(x>r)return;
if(x)a[++tot]=x;
dfs(*x+);
dfs(*x+);
}
inline ll gcd(ll x,ll y)
{
return y?gcd(y,x%y):x;
}
inline void calc(ll x,int y,int z)
{
if(y>n)
{
if(z&)ans+=r/x-(l-)/x;
else if(z)ans-=r/x-(l-)/x;
return;
}
calc(x,y+,z);
ll t=(x/gcd(x,a[y]))*a[y];
if(t<=r)calc(t,y+,z+);
} int main() { freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); l=read();r=read();
dfs();
sort(a+,a+tot+);
for1(i,tot)
if(!v[i])
{
b[++n]=a[i];
for2(j,i+,tot)if(a[j]%a[i]==)v[j]=;
}
for1(i,n)a[n+-i]=b[i];
calc(,,);
printf("%lld\n",ans); return ; }
BZOJ2393: Cirno的完美算数教室的更多相关文章
- [BZOJ2393] Cirno的完美算数教室(dfs+容斥原理)
传送门 先通过dfs预处理出来所有只有2和9的数,也就大概2000多个. 想在[L,R]中找到是这些数的倍数的数,可以通过容斥原理 那么如果a % b == 0,那么便可以把 a 去掉,因为 b 的倍 ...
- 【BZOJ-1853&2393】幸运数字&Cirno的完美算数教室 容斥原理 + 爆搜 + 剪枝
1853: [Scoi2010]幸运数字 Time Limit: 2 Sec Memory Limit: 64 MBSubmit: 1817 Solved: 665[Submit][Status] ...
- Bzoj 2393: Cirno的完美算数教室 容斥原理,深搜
2393: Cirno的完美算数教室 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 287 Solved: 175[Submit][Status][ ...
- 【bzoj2393】【Cirno的完美算数教室】容斥原理的剪枝应用
(上不了p站我要死了,侵权度娘背锅) 在用容斥定理时,常常会用到dfs的形式,如果枚举完所有的情况可能会超时,其剪枝的优化很是重要. Description ~Cirno发现了一种baka数,这种数呢 ...
- 【bzoj2393】Cirno的完美算数教室 数论容斥
Description ~Cirno发现了一种baka数,这种数呢~只含有2和⑨两种数字~~ 现在Cirno想知道~一个区间中~~有多少个数能被baka数整除~ 但是Cirno这么天才的妖精才不屑去数 ...
- BZOJ1853:[SCOI2010]幸运数字 & BZOJ2393:Cirno的完美算数教室——题解
https://www.lydsy.com/JudgeOnline/problem.php?id=1853 https://www.lydsy.com/JudgeOnline/problem.php? ...
- BZOJ 2393 Cirno的完美算数教室
就是爆搜嘛. 先从大到小排个序能减去dfs树上很大的一部分.这个技巧要掌握. #include<iostream> #include<cstdio> #include<c ...
- bzoj 2393 Cirno的完美算数教室(容斥原理+搜索)
[题意] 定义C数为只包含数字2和9的数,求[L,R]内能被C数整除的个数. [思路] Dfs预处理出C数,并去除其中倍数的情况. Dfs搜索出现情况,奇数加,偶数减,当数值大于R时剪枝. [代码] ...
- ●BZOJ 2393 Cirno的完美算数教室
题链: http://www.lydsy.com/JudgeOnline/problem.php?id=2393 题解: 容斥原理,暴力搜索,剪枝...和 [Scoi2010 幸运数字] 一样的(只是 ...
随机推荐
- Java中快速排序的实现
快速排序是对冒泡排序的一种改进.它的基本思想是:通过一躺排序将要排序的数据分割成独立的两部分,其中一部分的所有数据都比另外一部分的所有数据都要 小,然后再按次方法对这两部分数据分别进行快速排序,整个排 ...
- Misha and Changing Handles
Description Misha hacked the Codeforces site. Then he decided to let all the users change their hand ...
- MySQL查看数据库、表的占用空间大小
SELECT TABLE_NAME,DATA_LENGTH+INDEX_LENGTH,TABLE_ROWS FROM information_schema.tables WHERE TABLE_SCH ...
- Day01_UNIX基础及VI简介
2013年09月29日 星期日 11时35分58秒 Linux 是一个区别于Windows的操作系统 Linux 是一个多用户的操作系统 Linux 系统通过账号区分不同的用户 在使用Linux系统的 ...
- 面试al tx
阿里: 一面: 1:写代码,给三个数组abc,每个数组若干数字,判断一个数字在不在三个数组中.用的map解决. 2:例举知道的排序,写出归并排序代码. 3:剩下的都是小题目了:包括三次握手,tc ...
- pic_for_youdao
- C++编程规范之20:避免函数过长,避免嵌套过深
摘要: 短胜于长,平胜于优,过长的函数和嵌套过深的代码块的出现,经常是因为没能赋予一个函数以一个紧凑的职责所致,这两种情况通常都能够通过更好的重构予以解决. 每个函数都应该顾其名而能知其义,易于理解的 ...
- hdu 4940 无源汇有上下界最大流
/* <img src="http://img.blog.csdn.net/20140823174212937?watermark/2/text/aHR0cDovL2Jsb2cuY3N ...
- CentOS7--64安装python的psutil模块
1.以root身份登陆CentOS依次 执行以下命令: wget https://pypi.python.org/packages/source/p/psutil/psutil-2.1.3.tar.g ...
- Python购物车的实现课程
需求: 1.用户输入工资收入 2.打印商品列表 3.用户选择商品,不断的加入购物车 4.检测用户余额,直接捐款,不足提示余额不足 5.允许主动退出,退出时,打印已购商品列表 重点方法: 打印列表下标的 ...