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 ...
随机推荐
- bzoj 1657: [Usaco2006 Mar]Mooo 奶牛的歌声【单调栈】
先考虑只能往一边传播,最后正反两边就行 一向右传播为例,一头牛能听到的嚎叫是他左边的牛中与高度严格小于他并且和他之间没有更高的牛,用单调递减的栈维护即可 #include<iostream> ...
- swoole之 swoole_process 应用于TP框架
swoole_process 实现了多进程的管理,多个进程同时进行采集任务, 公司的框架比较low,用的tp框架,结合tp框架实现多进程的采集 这是swoole好的学习资源 https://segme ...
- Poj 3177 Redundant Paths (双连通分支+节点统计)
题目描述: 给出一个无向的连通图,问最少加入几条边,才能使所给的图变为无桥的双连通图? 解题思路: 可以求出原图中所有的不包含桥的所有最大连通子图,然后对连通子图进行标记缩点,统计度为1的叶子节点le ...
- maven idea
写在前面的话:此篇文章教程是在IntelliJ IDEA中搭建的maven项目.(建议eclipse党快点转IDEA吧,IDEA大法好.逃… 1.maven的安装 前往Apache Maven官网点击 ...
- Python之Pandas中Series、DataFrame实践
Python之Pandas中Series.DataFrame实践 1. pandas的数据结构Series 1.1 Series是一种类似于一维数组的对象,它由一组数据(各种NumPy数据类型)以及一 ...
- Android屏幕尺寸与度量单位(px,dp,sp)简介
MarkdownPad Document *:first-child { margin-top: 0 !important; } body>*:last-child { margin-botto ...
- Verification Mind Games---how to think like a verifier像验证工程师一样思考
1. 有效的验证需要验证工程师使用不同于设计者的思维方式思考问题.具体来说,验证更加关心在严格遵循协议的基础上发现设计里面的bug,搜索corner cases,对设计的不一致要保持零容忍的态度. m ...
- tomcat日志详释
1.tomcat的日志分类: 一是运行中的日志,它主要记录运行的一些信息,尤其是一些异常错误日志信息 . 二是访问日志信息,它记录的访问的时间,IP ,访问的资料等相关信息. 2.tomcat的日志目 ...
- 【C++】朝花夕拾——树(开篇)
树 ===================我是分割线====================== 1. 定义: 一些结点的集合,集合可以为空.定义树的自然方式是递归的方法. 2. 相关概念: 根(ro ...
- HDU_2544_最短路
题意:第一个路口是起点,第n个(最后一个)路口是终点,问最短路径. 总结:第一个dijkstra. 代码: #include<iostream> #include<cstdio> ...