bzoj 2393 Cirno的完美算数教室(容斥原理+搜索)
【题意】
定义C数为只包含数字2和9的数,求[L,R]内能被C数整除的个数。
【思路】
Dfs预处理出C数,并去除其中倍数的情况。
Dfs搜索出现情况,奇数加,偶数减,当数值大于R时剪枝。
【代码】
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std; typedef long long ll;
const int N = 2e3+; ll a[N],b[N],vis[N],ans,tot,n,L,R; void get_pre(int num)
{
if(num>R) return ;
if(num) a[++tot]=num;
get_pre(num*+);
get_pre(num*+);
}
ll gcd(ll a,ll b)
{
return b==? a:gcd(b,a%b);
}
void dfs(int cur,int cnt,ll lcm)
{
if(cur==n+) {
if(cnt&) ans+=R/lcm-(L-)/lcm;
else if(cnt) ans-=R/lcm-(L-)/lcm;
return ;
}
dfs(cur+,cnt,lcm);
ll val=lcm*a[cur]/(gcd(lcm,a[cur]));
if(val<=R) dfs(cur+,cnt+,val);
} int main()
{
scanf("%lld%lld",&L,&R);
get_pre();
sort(a+,a+tot+);
for(int i=;i<=tot;i++)
if(!vis[i]) {
b[++n]=a[i];
for(int j=i+;j<=tot;j++)
if(a[j]%a[i]==) vis[j]=;
}
for(int i=;i<=n;i++)
a[i]=b[n-i+];
dfs(,,);
printf("%lld\n",ans);
return ;
}
bzoj 2393 Cirno的完美算数教室(容斥原理+搜索)的更多相关文章
- Bzoj 2393: Cirno的完美算数教室 容斥原理,深搜
2393: Cirno的完美算数教室 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 287 Solved: 175[Submit][Status][ ...
- [bzoj 2393] Cirno的完美算数教室 (容斥原理+dfs剪枝)
题目描述 CirnoCirnoCirno发现了一种bakabakabaka数,这种数呢只含有222和999两种数字 现在CirnoCirnoCirno想知道[L,R][L,R][L,R]中有多少个数能 ...
- ●BZOJ 2393 Cirno的完美算数教室
题链: http://www.lydsy.com/JudgeOnline/problem.php?id=2393 题解: 容斥原理,暴力搜索,剪枝...和 [Scoi2010 幸运数字] 一样的(只是 ...
- BZOJ 2393 Cirno的完美算数教室
就是爆搜嘛. 先从大到小排个序能减去dfs树上很大的一部分.这个技巧要掌握. #include<iostream> #include<cstdio> #include<c ...
- 【BZOJ-1853&2393】幸运数字&Cirno的完美算数教室 容斥原理 + 爆搜 + 剪枝
1853: [Scoi2010]幸运数字 Time Limit: 2 Sec Memory Limit: 64 MBSubmit: 1817 Solved: 665[Submit][Status] ...
- bzoj 1853: [Scoi2010]幸运数字&&2393: Cirno的完美算数教室【容斥原理】
翻了一些blog,只有我用状压预处理嘛2333,.把二进制位的0当成6,1当成8就行啦.(2393是2和9 然后\( dfs \)容斥,加上一个数的\( lcm \),减去两个数的\( lcm \), ...
- BZOJ2393: Cirno的完美算数教室
2393: Cirno的完美算数教室 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 138 Solved: 83[Submit][Status] D ...
- 【bzoj2393】【Cirno的完美算数教室】容斥原理的剪枝应用
(上不了p站我要死了,侵权度娘背锅) 在用容斥定理时,常常会用到dfs的形式,如果枚举完所有的情况可能会超时,其剪枝的优化很是重要. Description ~Cirno发现了一种baka数,这种数呢 ...
- [BZOJ2393] Cirno的完美算数教室(dfs+容斥原理)
传送门 先通过dfs预处理出来所有只有2和9的数,也就大概2000多个. 想在[L,R]中找到是这些数的倍数的数,可以通过容斥原理 那么如果a % b == 0,那么便可以把 a 去掉,因为 b 的倍 ...
随机推荐
- Sina App Engine(SAE)入门教程(5)- SaeSegment(中文分词服务)使用
分词能干什么? 提取一篇文章的关键字 检测特定的段落中有没有违禁词 智能机器人 …..尽你所想 开启SAE 分词服务 首先你需要在sae的管理面板开始分词服务后才能使用sae的服务.具体的开启操作: ...
- Dictionary<Key,Value>的用法
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...
- 写出优秀论文How To Write A Great Essay About Anything
There is an assumption in the world that an essay is something literary you write for school about a ...
- SPOJ 1108 Card Trick 暴力模拟
解释一下样例,因为我觉得这个题意表述的不是很清楚.以第二组样例为例. 牌序为:3 1 4 5 2 第一轮:把 3 放到末尾:1 4 5 2 3,最顶上的牌是1,把1拿走.剩余 4 5 2 3 第二轮: ...
- 【原创】30分钟入门 github
很久没更新了,这篇文章重点在github的入门使用,读者可以下载github for windows shell,边看边操作,加深印象. 好了,30分钟的愉快之旅开始吧: 一.github使用的注意事 ...
- wordCount程序中MapReduce工作过程分析
Map处理的是一个纯文本.Mapper处理的数据是由InputFormat分解过的数据集,其中InputFormat的作用是将数据集切割成小数据集InputSplit,每一个InputSplit将由一 ...
- HDU 4686 Arc of Dream(矩阵)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4686 题意: 思路: #include <iostream>#include <cs ...
- Java Swing中Substance常用皮肤
AutumnSkin; BusinessSkin; BusinessBlackSteelSkin; BusinessBlueSteelSkin; ChallengerDeepSkin; CremeSk ...
- poj 2411 Mondriaan's Dream(状态压缩dP)
题目:http://poj.org/problem?id=2411 Input The input contains several test cases. Each test case is mad ...
- Android中LayoutInflater的使用
Inflater英文意思是膨胀,在Android中应该是扩展的意思吧. LayoutInflater 的作用类似于 findViewById(),不同点是LayoutInflater是用来找layou ...