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 幸运数字] 一样的(只是 ...
随机推荐
- Contest - 第10届“新秀杯”ACM程序设计大赛现场热身赛 赛后信息(题解)
Problem Id Title Problem A A+B Problem B 统计字数 Problem C 生日计算 Problem D 冬瓜的寒假之旅 Problem A(略 ...
- iOS--九宫格布局
[self rankWithTotalColumns: andWithAppW: andWithAppH:]; //九宫格布局 - (void)rankWithTotalColumns:(int)to ...
- Xcode7真机测试
根据这个网址上的步骤能够完成真机测试,我已经试过了,还不错 http://www.bubuko.com/infodetail-1061938.html
- jQuery -> 获取兄弟元�
获取指定元素的兄弟元素时,能够使用adjacent sibling combinator (+),当中+的两側内容都是selector expression. 假设要获取下例中全部的 h1的直接兄弟元 ...
- Windows server 2008系统下FTP服务器的安装
一.在 Windows 服务器上安装 FTP 服务 1. 在"开始"菜单上,单击"管理工具",然后单击"服务器管理器". 2. 在" ...
- 服务 远程服务 AIDL 进程间通讯 IPC 深化
示例 aidl接口文件 package com.bqt.aidlservice.aidl; parcelable Person; package com.bqt.aidlservice.aidl; ...
- OD: Windows Security Techniques & GS Bypassing via C++ Virtual Function
Windows 安全机制 漏洞的万源之本在于冯诺依曼设计的计算机模型没有将代码和数据进行区分——病毒.加壳脱壳.shellcode.跨站脚本攻击.SQL注入等都是因为计算机把数据和代码混淆这一天然缺陷 ...
- 黑马程序员——HTML语言
------<a href="http://www.itheima.com" target="blank">Java培训.Android培训.iOS ...
- IFeatureClass.Search中的 Recycling 参数 - 浅谈.
语法: public IFeatureCursor Search ( IQueryFilter filter, bool Recycling); 当 Recycling 为true时,调用NextFe ...
- scala学习笔记——操作符
中置操作符(二元操作符),操作符位于两个参数之间.操作符包括字母,比如to,也可以包括操作符字符,比如1->10,等同于方法调用1.->(10) a 标识符 b 其中的标识符是一个带有两个 ...