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 幸运数字] 一样的(只是 ...
随机推荐
- HDU_2027——统计元音
Problem Description 统计每个元音字母在字符串中出现的次数. Input 输入数据首先包括一个整数n,表示测试实例的个数,然后是n行长度不超过100的字符串. Output ...
- CCF 送货 + 欧拉路模板
#include <bits/stdc++.h> using namespace std; stack<int> st; vector<]; ][]; ],cp[]; i ...
- fuelSources
function countdown() { local i; sleep 1 for ((i=$1 - 1;i>=1;i--));do printf '\b\b%02d' "$i&q ...
- iOS--创建uiscrollview
//创建uiscrollview self.PageHeight = self.view.bounds.size.height; self.PageWidth = self.view.bounds.s ...
- (转)Android签名详解(debug和release)
1. 为什么要签名 1) 发送者的身份认证 由于开发商可能通过使用相同的Package Name来混淆替换已经安装的程序,以此保证签名不同的包不被替换 2) 保证信息传输的完整性 签名对于包中的每个文 ...
- 用PlistBuddy修改Plist文件
Plist文件是以.plist为结尾的文件的总称. 众所周知, Plist在Mac OSX系统中起着举足轻重的作用,就如同Windows里面的Registry一样,系统和程序使用Plist文件来存储自 ...
- windows服务程序
首先创建一个myService的窗体程序作为服务安装卸载控制器(管理员身份运行vs,windows服务的安装卸载需要管理员权限) 在同一个解决方案里面添加一个windows服务程序,取名myWin ...
- 从 Windows 到 Android: 威胁的持续迁移
作者:趋势科技 新闻媒体现在正喧腾着 OBAD 这个 Android 恶意软件,这也是到目前为止,Android 恶意软件中“最坏”,同时也是“最先进的 Android 木马程序”.除了各种强大的功能 ...
- python:字符串取值
某个字符串为stmp="abcdef54321" 取前面5个stmp[:5] #abcde 取后面5个stmp[-5:] #54321 从前面开始取,不包括最后两个stmp[:-2 ...
- sql server里一些常用的查询
查看表的创建和更改时间: select * from sys.tables 查询数据库的创建时间: select * from sys.databases where name in ('数据 ...