BZOJ 1853
http://www.lydsy.com/JudgeOnline/problem.php?id=1853
岛娘在空间上发的题解就看了看果然被骗了。还以为是数位dp。
原来是容斥啊。好吧第一道正式的题目。
这题还不错,有几个小优化,像排序之类的啦很常见。
看了一下别人的代码,学习了一下姿势。
这里直接把别人的代码贴过来。
1 #include <iostream>
2 #include <algorithm>
3 #include <cstring>
4
5 using namespace std ;
6
7 #define rep( i , x , y ) for ( int i = x ; i <= y ; ++ i )
8
9 typedef long long ll ;
const int maxn = ;
ll a , b , num[ maxn ] ;
int cnt = ;
void make( ll now ) {
if ( now > b ) return ;
num[ ++ cnt ] = now ;
make( now * + ) , make( now * + ) ;
}
ll ans , n[ maxn ] ;
int m = ;
ll X ;
ll gcd( ll x , ll y ) {
if ( x < y ) swap( x , y ) ;
ll k ;
while ( y ) {
k = y ;
y = x % y ;
x = k ;
}
return x ;
}
void dfs( int pos , int times , ll rec ) {
if ( ! pos ) {
if ( ! times ) return ;
ll ret = ( b / rec ) - ( a / rec ) ;
if ( times & ) ans += ret ; else ans -= ret ;
return ;
}
ll temp = gcd( rec , n[ pos ] ) ;
if ( rec / temp <= b / n[ pos ] ) dfs( pos - , times + , rec / temp * n[ pos ] ) ;
dfs( pos - , times , rec ) ;
}
int main( ) {
cin >> a >> b ;
make( ) , make( ) ;
rep( i , , cnt ) if ( num[ i ] ) {
rep( j , , cnt ) if ( i != j && ! ( num[ j ] % num[ i ] ) ) {
num[ j ] = ;
}
}
memset( n , , sizeof( n ) ) ;
rep( i , , cnt ) if ( num[ i ] ) {
n[ ++ m ] = num[ i ] ;
}
sort( n + , n + m + ) ;
-- a ;
ans = ;
dfs( m , , ) ;
cout << ans << endl ;
return ;
68 }
BZOJ 1853的更多相关文章
- 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: 1774 Solved: 644[Submit][Status] ...
- bzoj 1853: [Scoi2010]幸运数字 容斥
1853: [Scoi2010]幸运数字 Time Limit: 2 Sec Memory Limit: 64 MBSubmit: 1170 Solved: 406[Submit][Status] ...
- ●BZOJ 1853 [Scoi2010]幸运数字
题链: http://www.lydsy.com/JudgeOnline/problem.php?id=1853 题解: 容斥原理,暴力搜索,剪枝(这剪枝剪得真玄学) 首先容易发现,幸运号码不超过 2 ...
- BZOJ 1853: [Scoi2010]幸运数字(容斥原理)
http://www.lydsy.com/JudgeOnline/problem.php?id=1853 题意: 在中国,很多人都把6和8视为是幸运数字!lxhgww也这样认为,于是他定义自己的“幸运 ...
- 【BZOJ 1853】 1853: [Scoi2010]幸运数字 (容斥原理)
1853: [Scoi2010]幸运数字 Time Limit: 2 Sec Memory Limit: 64 MBSubmit: 2472 Solved: 911 Description 在中国 ...
- AC日记——[SCOI2010]幸运数字 bzoj 1853
1853: [Scoi2010]幸运数字 Time Limit: 2 Sec Memory Limit: 64 MBSubmit: 2405 Solved: 887[Submit][Status] ...
- BZOJ 1853 【Scoi2010】 幸运数字
Description 在中国,很多人都把6和8视为是幸运数字!lxhgww也这样认 为,于是他定义自己的"幸运号码"是十进制表示中只包含数字6和8的那些号码,比如68,666,8 ...
- BZOJ 1853 幸运数字
需要优化一波常数. 以及刚才那个版本是错的. #include<iostream> #include<cstdio> #include<cstring> #incl ...
随机推荐
- 在 Vue 项目中(vue-cli2,vue-cli3)使用 pug 简化 HTML 的编写
使用 pug 的原因: 使得 HTML 写起了来更加清晰和快捷 用法: Vue 的用法没有变化: <template lang="pug"> transition(na ...
- hdu5922Minimum’s Revenge
Minimum's Revenge Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others ...
- 构造+暴力 Codeforces Round #283 (Div. 2) B. Secret Combination
题目传送门 /* 构造+暴力:按照题目意思,只要10次加1就变回原来的数字,暴力枚举所有数字,string大法好! */ /************************************** ...
- 题解报告:hdu 2588 GCD(欧拉函数)
Description The greatest common divisor GCD(a,b) of two positive integers a and b,sometimes written ...
- 用SpringMVC实现的上传下载方式二(多文件上传)
参考来源: http://blog.csdn.net/qq_32953079/article/details/52290208 1.导入相关jar包 commons-fileupload.j ...
- 全面学习ORACLE Scheduler特性(9)创建Chains
五.使用Chains 今天要来认识一位新同学:CHAIN(注意不要敲成CHINA).CHAIN可以被视做一组Programs的复合,举个简单的例子:运行PROGRAM:A以及PROGRAM:B,如果成 ...
- ASP.NET控件之RadioButtonList
“RadioButtonList”控件表示一个封装了一组单选按钮控件的列表控件. 可以使用两种类型的 ASP.NET 控件将单选按钮添加到网页上:各个“RadioButton”控件或一个“RadioB ...
- 网上商城 Incorrect datetime value: '' for column 'ordertime' at row 1
今天在做商城项目的[提交订单]功能的时候,向数据库插入数据报错:Incorrect datetime value: '' for column 'ordertime' at row 1 public ...
- [ SDOI 2006 ] 仓库管理员的烦恼
\(\\\) Description 有 \(n\) 种货物和 \(n\) 个仓库,开始第 \(i\) 个仓库里有 \(a_{ij}\) 个第 \(j\) 种货物. 现在要让每种货物都只放到一个仓库里 ...
- Spark学习之编程进阶——累加器与广播(5)
Spark学习之编程进阶--累加器与广播(5) 1. Spark中两种类型的共享变量:累加器(accumulator)与广播变量(broadcast variable).累加器对信息进行聚合,而广播变 ...