●BZOJ 2393 Cirno的完美算数教室
题链:
http://www.lydsy.com/JudgeOnline/problem.php?id=2393
题解:
容斥原理,暴力搜索,剪枝
...和 [Scoi2010 幸运数字] 一样的(只是那个题是 6,8,这个题是2,9)
代码:
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define ll long long
#define filein(x) freopen(#x".in","r",stdin);
#define fileout(x) freopen(#x".out","w",stdout);
using namespace std;
bool mark[3000];
ll luck[3000],l,r,ans;
int cnt; bool fg;
ll gcd(ll a,ll b){
while(b^=a^=b^=a%=b);
return a;
}
void dfs(int p,int num,ll val,const ll &lim){
if(!p) return;
ll LCM=val/gcd(val,luck[p])*luck[p];
if(0<LCM&&LCM<=lim) ans+=1ll*lim/LCM*((num+1)%2?1:-1),dfs(p-1,num+1,LCM,lim);
dfs(p-1,num,val,lim);
}
ll solve(ll lim){
ans=0;
dfs(cnt,0,1,lim);
return ans;
}
void pre(int dep,ll val){
if(val) luck[++cnt]=val;
if(!dep) return;
pre(dep-1,val*10+2);
pre(dep-1,val*10+9);
}
int main()
{
pre(10,0); int ccnt=0;
sort(luck+1,luck+cnt+1);
for(int i=1;i<=cnt;i++)
for(int j=1;j<i;j++) if(luck[i]%luck[j]==0) mark[i]=1;
for(int i=1;i<=cnt;i++) if(!mark[i]) luck[++ccnt]=luck[i]; cnt=ccnt;
scanf("%lld%lld",&l,&r);
printf("%lld",solve(r)-solve(l-1));
return 0;
}
●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树上很大的一部分.这个技巧要掌握. #include<iostream> #include<cstdio> #include<c ... 
- bzoj 2393 Cirno的完美算数教室(容斥原理+搜索)
		[题意] 定义C数为只包含数字2和9的数,求[L,R]内能被C数整除的个数. [思路] Dfs预处理出C数,并去除其中倍数的情况. Dfs搜索出现情况,奇数加,偶数减,当数值大于R时剪枝. [代码] ... 
- [bzoj 2393] Cirno的完美算数教室 (容斥原理+dfs剪枝)
		题目描述 CirnoCirnoCirno发现了一种bakabakabaka数,这种数呢只含有222和999两种数字 现在CirnoCirnoCirno想知道[L,R][L,R][L,R]中有多少个数能 ... 
- bzoj 1853: [Scoi2010]幸运数字&&2393: Cirno的完美算数教室【容斥原理】
		翻了一些blog,只有我用状压预处理嘛2333,.把二进制位的0当成6,1当成8就行啦.(2393是2和9 然后\( dfs \)容斥,加上一个数的\( lcm \),减去两个数的\( lcm \), ... 
- 【BZOJ-1853&2393】幸运数字&Cirno的完美算数教室       容斥原理 + 爆搜 + 剪枝
		1853: [Scoi2010]幸运数字 Time Limit: 2 Sec Memory Limit: 64 MBSubmit: 1817 Solved: 665[Submit][Status] ... 
- BZOJ2393: Cirno的完美算数教室
		2393: Cirno的完美算数教室 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 138 Solved: 83[Submit][Status] D ... 
- 【BZOJ1853/2393】[Scoi2010]幸运数字/Cirno的完美算数教室 DFS+容斥
		[BZOJ1853][Scoi2010]幸运数字 Description 在中国,很多人都把6和8视为是幸运数字!lxhgww也这样认为,于是他定义自己的“幸运号码”是十进制表示中只包含数字6和8的那 ... 
- BZOJ1853:[SCOI2010]幸运数字 & BZOJ2393:Cirno的完美算数教室——题解
		https://www.lydsy.com/JudgeOnline/problem.php?id=1853 https://www.lydsy.com/JudgeOnline/problem.php? ... 
随机推荐
- SaaS的那些事儿
			前两年... 大一大二期间,不知道软件架构.云服务器.数据库为何物,偶尔听过却从未用过.天天学的写的东西都是一些命令行代码,所幸在学完<数据结构>和<算法导论>后能够独立实 ... 
- CoreAnimation注意事项
			最近调查的一个bug和内存泄露都和CoreAnimation有关,因此谈一下使用CoreAnimation需要注意的几个问题 CAAnimation的delegate属性是retain的,这个设计确实 ... 
- Swift - 使用导航条和导航条控制器来进行页面切换并传递数据
			转自:http://www.hangge.com/blog/cache/detail_586.html 
- Web前端性能分析
			Web前端性能通常上代表着一个完全意义上的用户响应时间,包含从开始解析HTML文件到最后渲染完成开始的整个过程,但不包括在输入url之后与服务器的交互阶段.下面是整个过程的各个步骤: 开始解析html ... 
- bzoj千题计划244:bzoj3730: 震波
			http://www.lydsy.com/JudgeOnline/problem.php?id=3730 点分树内对每个节点动态维护2颗线段树 线段树以距离为下标,城市的价值为权值 对于节点x的两棵线 ... 
- selenium多个标签页的切换(弹出新页面的切换)
			1_windows = driver.current_window_handle #定位当前页面句柄 all_handles = driver.window_handles #获取全部页面句柄 for ... 
- threadlocal原理及常用应用场景
			1.深入解析ThreadLocal类 ThreadLocal类提供的几个方法: public T get() { } public void set(T value) { } public void ... 
- 九、Python+Selenium模拟用QQ登陆腾讯课堂,并提取报名课程(练习)
			研究QQ登录规则的话,得分析大量Javascript的加密解密,比较耗时间.自己也是练习很少,短时间成功不了.所以走了个捷径. Selenium是一个WEB自动化测试工具,它运行时会直接实例化出一个浏 ... 
- 19届华为实习生笔试之判断iPv6地址类型
			题二: 答案: #coding=utf-8 import re,sys str = sys.stdin.readline().strip() def regex(str): result = &quo ... 
- Java并发编程:synchronized和锁优化
			1. 使用方法 synchronized 是 java 中最常用的保证线程安全的方式,synchronized 的作用主要有三方面: 确保线程互斥的访问代码块,同一时刻只有一个方法可以进入到临界区 保 ... 
