●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? ...
随机推荐
- Python web服务器
Python 配置wsgi接口# 引入Python wsgi包 from wsgiref.simple_server import make_server # 撰写服务器端程序代码 def Appli ...
- caffe实现GAN
我实现GAN网络结构比较复杂: 通过建立两个一模一样的网络,他们相对应的层共享权重,一个网络用来跟新D model另一个网络用来更新G model 更新G model的网络,D部分只进行梯度传递,不进 ...
- SpringMVC 无法访问到指定jsp页面可能的原因
当出现你的程序可以访问到对应的controller层.但是却无法访问对应的jsp文件时.你首先做的不是检查web.xml等配置文件,而是打开的服务器根文件检查对应路径下的文件是否存在.命名是否正确.命 ...
- css3动画 一行字鼠标触发 hover 从左到右颜色渐变
偶然的机会发现的这个东东 这几天做公司的官网 老板突然说出了一个外国网站 我就顺手搜了 并没有发现他说的高科技 但是一个东西深深地吸引了我 就是我下面要说的动画 这个好像不能放视频 我就简单的描述一 ...
- Spring Security 入门(1-4-1)Spring Security - 认证过程
理解时可结合一下这位老兄的文章:http://www.importnew.com/20612.html 1.Spring Security的认证过程 1.1.登录过程 - 如果用户直接访问登录页面 用 ...
- CentOS ping www.baidu.com 报错 name or service not know
今天尝试安装了centos系统 玩一玩 刚刚装好的操作系统 ping www.baidu.com的时候 报出 name or service not known 查了好多资料,都没有很好的解决 最后 ...
- zoj 3950 how many nines
https://vjudge.net/problem/ZOJ-3950 题意: 给出两个日期,计算从第一个日期开始到第二个日期,每一天的日期中的9加起来一共有多少个. 思路: 看题解补的题.首先看这题 ...
- switchysharp设置
在线规则列表里面插入下面的网址:https://autoproxy-gfwlist.googlecode.com/svn/trunk/gfwlist.txt
- Java:日期类Date与Calendar
Timestamp类型与日期类型之间的转化? Timestamp timestamp = Timestamp.valueOf("2017-03-17 07:00:00"); Dat ...
- springboot集成mybatis(一)
MyBatis简介 MyBatis本是apache的一个开源项目iBatis, 2010年这个项目由apache software foundation迁移到了google code,并且改名为MyB ...