Bzoj 1853: [Scoi2010]幸运数字 容斥原理,深搜
1853: [Scoi2010]幸运数字
Time Limit: 2 Sec Memory Limit: 64 MB
Submit: 1774 Solved: 644
[Submit][Status][Discuss]
Description
Input
Output
Sample Input
1 10
【样例输入2】
1234 4321
Sample Output
2
【样例输出2】
809
HINT
【数据范围】
对于30%的数据,保证1 < =a < =b < =1000000
对于100%的数据,保证1 < =a < =b < =10000000000
Source
题解:
容斥原理+爆搜。
记得开double或unsigned long long。
#include<bits/stdc++.h>
using namespace std;
#define LL unsigned long long
LL sum,cc[],lc,a,b;
bool vis[];
LL Gcd(LL aa,LL bb){if(bb==)return aa;else return Gcd(bb,aa%bb);}
void DFS(LL x,LL y,LL gs,LL lcm, LL gcd,LL ii)
{
LL LCM,GCD,i;
//if(lcm>x||lcm>y)return;
if(lcm>x&&lcm>y)return;
if(gs>)
{
if(gs%!=)sum+=((LL)(y/lcm)-(LL)(x/lcm));
else sum-=((LL)(y/lcm)-(LL)(x/lcm));
}
if(gs==lc+||ii+>lc)return;
for(i=ii+;i<=lc;i++)
{
if(vis[i]==false)
{
vis[i]=true;
LCM=lcm;GCD=gcd;
gcd=Gcd(lcm,cc[i]);lcm=(lcm*cc[i])/gcd;
DFS(x,y,gs+,lcm,gcd,i);
lcm=LCM;gcd=GCD;
vis[i]=false;
}
}
}
LL calc(LL x,LL y)
{
/*for(i=1;i<=lc;i++)
{
tot=0;
DFS(x);
}*/
memset(vis,false,sizeof(vis));sum=;
DFS(x-,y,,,,);
return sum;
}
void dfs(LL k)
{
if(k>b)return;
if(k!=)cc[++lc]=k;
dfs(k*+);
dfs(k*+);
}
int main()
{
LL len,i;
scanf("%lld %lld",&a,&b);
memset(cc,,sizeof(cc));lc=;
dfs();
sort(cc+,cc+lc+);
len=unique(cc+,cc+lc+)-(cc+);
for(i=;i<=len/;i++)swap(cc[i],cc[len-i+]);
lc=len;
printf("%lld",calc(a,b));
return ;
}
Bzoj 1853: [Scoi2010]幸运数字 容斥原理,深搜的更多相关文章
- BZOJ_2393_Cirno的完美算数教室&&BZOJ_1853_[Scoi2010]幸运数字 _深搜+容斥原理
BZOJ_2393_Cirno的完美算数教室&&BZOJ_1853_[Scoi2010]幸运数字 _深搜+容斥原理 题意: ~Cirno发现了一种baka数,这种数呢~只含有2和⑨两种 ...
- BZOJ 1853: [Scoi2010]幸运数字
1853: [Scoi2010]幸运数字 Time Limit: 2 Sec Memory Limit: 64 MBSubmit: 2117 Solved: 779[Submit][Status] ...
- bzoj 1853: [Scoi2010]幸运数字 容斥
1853: [Scoi2010]幸运数字 Time Limit: 2 Sec Memory Limit: 64 MBSubmit: 1170 Solved: 406[Submit][Status] ...
- 1853: [Scoi2010]幸运数字[容斥原理]
1853: [Scoi2010]幸运数字 Time Limit: 2 Sec Memory Limit: 64 MBSubmit: 2405 Solved: 887[Submit][Status] ...
- BZOJ 1853: [Scoi2010]幸运数字(容斥原理)
http://www.lydsy.com/JudgeOnline/problem.php?id=1853 题意: 在中国,很多人都把6和8视为是幸运数字!lxhgww也这样认为,于是他定义自己的“幸运 ...
- bzoj 1853: [Scoi2010]幸运数字&&2393: Cirno的完美算数教室【容斥原理】
翻了一些blog,只有我用状压预处理嘛2333,.把二进制位的0当成6,1当成8就行啦.(2393是2和9 然后\( dfs \)容斥,加上一个数的\( lcm \),减去两个数的\( lcm \), ...
- ●BZOJ 1853 [Scoi2010]幸运数字
题链: http://www.lydsy.com/JudgeOnline/problem.php?id=1853 题解: 容斥原理,暴力搜索,剪枝(这剪枝剪得真玄学) 首先容易发现,幸运号码不超过 2 ...
- 【BZOJ 1853】 1853: [Scoi2010]幸运数字 (容斥原理)
1853: [Scoi2010]幸运数字 Time Limit: 2 Sec Memory Limit: 64 MBSubmit: 2472 Solved: 911 Description 在中国 ...
- BZOJ2393 & 1853 [Scoi2010]幸运数字 【搜索 + 容斥】
题目 在中国,很多人都把6和8视为是幸运数字!lxhgww也这样认为,于是他定义自己的"幸运号码"是十进制表示中只包含数字6和8的那些号码,比如68,666,888都是" ...
随机推荐
- ZeroMemory和memset的区别
摘自百度百科,保存为学习使用 ZeroMemory,是美国微软公司的软件开发包SDK中的一个宏. 其作用是用0来填充一块内存区域. 声明 void ZeroMemory( PVOID Destinat ...
- leetcode problem 10 Regular Expression Matching(动态规划)
Implement regular expression matching with support for '.' and '*'. '.' Matches any single character ...
- gcc 生成动态库时-fpic选项是什么意思。
-f后面跟一些编译选项,PIC是其中一种,表示生成位置无关代码(Position Independent Code)
- jQuery DataTables 插件使用笔记
初始化 在页面中 <!DOCTYPE html> <html> <head> <link rel="stylesheet" type=&q ...
- 列表显示数据 但是数据的字体颜色要js添加
1.需求:数据在前台显示,但是每个条记录的颜色要有点不同 1.java后台数据的处理 String ids=""; for(int x=0;x<sign.size();x++ ...
- Windows下MySQL数据库备份脚本(一)
说明: MySQL数据库安装目录:C:\Program Files\MySQL\MySQL Server 5.0 MySQL数据库存放目录:C:\Program Files\MySQL\MySQL S ...
- Class TBoundlabel not found and so on..
Class TBoundlabel not found when you put a labeledit into a panel of CategoryPanel then you'll found ...
- javax.servlet不存在的问题
摘自:http://blog.csdn.net/tgeh23/article/details/2216682 最近在学习servlet,看书看的似乎还比较理想就想上机试下,这一试就发现,问题来 ...
- Axure草记
页面控件和DataSet绑定,DataSet和输入控件绑定(通过临时变量) 双击Repeater进入之后,你会发现下面已经默认添加了3行,这代表着,每增加一行将会重复3遍: Repeater可以只是部 ...
- qt 5 基础知识 2(控件篇)
QVBoxLayout *lay = new QVBoxLayout(this); // 创建一个竖直的盒子 lebel 篇 lay->addWidget(label = new QLabel( ...