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 ...
随机推荐
- 清北考前刷题day6下午好
/* 贪心 负数一定不取 枚举最高位是1 且答案取为0的 位置, 更新答案. */ #include<iostream> #include<cstdio> #include&l ...
- 源码阅读之LinkedHashMap(JDK8)
概述 LinkedHashMap继承自HashMap,实现了Map<K,V>接口.其内部还维护了一个双向链表,在每次插入数据,或者访问.修改数据时,会增加节点.或调整链表的节点顺序.以决定 ...
- 微信小程序setData的使用,通过[...]进行动态key赋值
首先先介绍一下微信小程序Page.prototype.setData(Object data, Function callback)的讲解: setData函数用于将数据从逻辑层发送到视图层(异步), ...
- 区间DP UVA 1351 String Compression
题目传送门 /* 题意:给一个字符串,连续相同的段落可以合并,gogogo->3(go),问最小表示的长度 区间DP:dp[i][j]表示[i,j]的区间最小表示长度,那么dp[i][j] = ...
- Git管理多个远程分支
在此目录下使用GIT要注意一下几点: 因为这个目录是管理远程多个不同的分支的项目,所以使用GIT之前确认一下几点: 打开git bash,使用命令:git config –list查看目前本地的目录文 ...
- python tkinter窗口置顶
下面两句即可实现root窗口的置顶显示,可以用于某些程序的消息提示,能够弹出到桌面显示 root = Tk()root.wm_attributes('-topmost',1)
- JOptionPane.showMessageDialog出现在浏览器下面的解决方法
将JOptionPane.showMessageDialog(null, result, "发布公告:", JOptionPane.INFORMATION_MESSAGE);中的参 ...
- IDEA 导入maven项目,显示:nothing to show
问题描述: IDEA 导入maven项目,import project,默认下一步,直到Select Maven projects to import界面无选项,提示:nothing to show ...
- UVM基础之---------uvm report 机制分析
uvm 中的信息报告机制相对来说比较简单,功能上来说主要分为两部分: 第一通过ID对component的信息报告冗余级别进行控制,针对每个冗余级别进行不同的行为控制.这部分工作主要由uvm_repor ...
- 如何把mysql的列修改成行显示数据简单实现
如何把mysql的列修改成行显示数据简单实现 创建测试表: 1: DROP TABLE IF EXISTS `test`; 2: CREATE TABLE `test` ( 3: `year` int ...