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学习笔记(1)
1.检测变化 <ul> <li v-for="item in list">{{item}}</li> </ul> <scrip ...
- P2597 [ZJOI2012]灾难(倍增LCA+拓扑排序)
传送门 据大佬说这玩意儿好像叫灾难树还是灭绝树? 我们先按建图,设点$u$的食物有$x[1]...x[k]$,即在图中这些点都有一条指向它的边 以样例来说,对于人,羊和牛都有一条指向它的边,然而不管是 ...
- [51nod]1678 lyk与gcd(莫比乌斯反演)
题面 传送门 题解 和这题差不多 //minamoto #include<bits/stdc++.h> #define R register #define pb push_back #d ...
- C#封装访问修饰符
C# 封装 封装 被定义为"把一个或多个项目封闭在一个物理的或者逻辑的包中".在面向对象程序设计方法论中,封装是为了防止对实现细节的访问. 抽象和封装是面向对象程序设计的相关特性. ...
- 暴力+构造 Codeforces Round #283 (Div. 2) C. Removing Columns
题目传送门 /* 题意:删除若干行,使得n行字符串成递增排序 暴力+构造:从前往后枚举列,当之前的顺序已经正确时,之后就不用考虑了,这样删列最小 */ /*********************** ...
- Python(1)-第一天
PTVS下载地址:https://pytools.codeplex.com/releases/view/109707 Python下载地址:https://www.python.org/downloa ...
- LN : leetcode 515 Find Largest Value in Each Tree Row
lc 515 Find Largest Value in Each Tree Row 515 Find Largest Value in Each Tree Row You need to find ...
- HTTP的报文格式、GET和POST格式解析
1. HTTP报文格式 HTTP报文是面向文本的,报文中的每一个字段都是一些ASCII码串,各个字段的长度是不确定的.HTTP有两类报文:请求报文和响应报文.请求报文一个HTTP请求报文由请求行(re ...
- JavaScript(九)正则表达式
RegExp 正则表达式 ,一般被创建出来就是用于 字符串的替换 查找方法中的 1.创建正则表达式 var reg = /pattern/flag; // 字面量 var reg = new RegE ...
- ubuntu查看系统资源占用(内存,cpu和进程)
http://blog.csdn.net/vivian187/article/details/51476043 http://bluexp29.blog.163.com/blog/static/338 ...