http://www.lydsy.com/JudgeOnline/problem.php?id=1853

岛娘在空间上发的题解就看了看果然被骗了。还以为是数位dp。

原来是容斥啊。好吧第一道正式的题目。

这题还不错,有几个小优化,像排序之类的啦很常见。

看了一下别人的代码,学习了一下姿势。


http://hi.baidu.com/greencloud/item/6f564ec036a3ba2ee90f2edb

这里直接把别人的代码贴过来。

 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的更多相关文章

  1. BZOJ 1853: [Scoi2010]幸运数字

    1853: [Scoi2010]幸运数字 Time Limit: 2 Sec  Memory Limit: 64 MBSubmit: 2117  Solved: 779[Submit][Status] ...

  2. Bzoj 1853: [Scoi2010]幸运数字 容斥原理,深搜

    1853: [Scoi2010]幸运数字 Time Limit: 2 Sec  Memory Limit: 64 MBSubmit: 1774  Solved: 644[Submit][Status] ...

  3. bzoj 1853: [Scoi2010]幸运数字 容斥

    1853: [Scoi2010]幸运数字 Time Limit: 2 Sec  Memory Limit: 64 MBSubmit: 1170  Solved: 406[Submit][Status] ...

  4. ●BZOJ 1853 [Scoi2010]幸运数字

    题链: http://www.lydsy.com/JudgeOnline/problem.php?id=1853 题解: 容斥原理,暴力搜索,剪枝(这剪枝剪得真玄学) 首先容易发现,幸运号码不超过 2 ...

  5. BZOJ 1853: [Scoi2010]幸运数字(容斥原理)

    http://www.lydsy.com/JudgeOnline/problem.php?id=1853 题意: 在中国,很多人都把6和8视为是幸运数字!lxhgww也这样认为,于是他定义自己的“幸运 ...

  6. 【BZOJ 1853】 1853: [Scoi2010]幸运数字 (容斥原理)

    1853: [Scoi2010]幸运数字 Time Limit: 2 Sec  Memory Limit: 64 MBSubmit: 2472  Solved: 911 Description 在中国 ...

  7. AC日记——[SCOI2010]幸运数字 bzoj 1853

    1853: [Scoi2010]幸运数字 Time Limit: 2 Sec  Memory Limit: 64 MBSubmit: 2405  Solved: 887[Submit][Status] ...

  8. BZOJ 1853 【Scoi2010】 幸运数字

    Description 在中国,很多人都把6和8视为是幸运数字!lxhgww也这样认 为,于是他定义自己的"幸运号码"是十进制表示中只包含数字6和8的那些号码,比如68,666,8 ...

  9. BZOJ 1853 幸运数字

    需要优化一波常数. 以及刚才那个版本是错的. #include<iostream> #include<cstdio> #include<cstring> #incl ...

随机推荐

  1. hdu1512 Monkey King(并查集,左偏堆)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1512 题目大意:有n个猴子,一开始每个猴子只认识自己.每个猴子有一个力量值,力量值越大表示这个猴子打架 ...

  2. PWBI--Excel 数据源

    博客园地址: http://blog.sina.com.cn/s/blog_68c4467d0102w5cc.html http://www.cnblogs.com/asxinyu/p/Power_B ...

  3. jquery实现文字自动向上滚动,鼠标放上去停止,移开继续滚动代码...

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  4. 编写UI自动化测试用例原则

    1.一个脚本是一个完整的场景,从用户登陆操作到用户退出系统关闭浏览器.2.一个脚本脚本只验证一个功能点,不要试图用户登陆系统后把所有的功能都进行验证再退出系统3.尽量只做功能中正向逻辑的验证,不要考虑 ...

  5. C#基础 out传值

    public void Out(out int a, out int b) {//out相当于return返回值 //可以返回多个值 //拿过来变量名的时候,里面默认为空值 a=1; b=2; } s ...

  6. SQL数据库--数据访问

    数据访问: 对应命名空间:System.Data.SqlClient; SqlConnection:连接对象 SqlCommand:命令对象 SqlDataReader:读取器对象 //造连接字符串 ...

  7. can't set blob value on that column

    MySQL_Prepared_Statement::setBlob: can't set blob value on that column, MySQL error code:0, SQLState ...

  8. MyBatis 之一 简介

    什么是 MyBatis ? MyBatis 是支持定制化 SQL.存储过程以及高级映射的优秀的持久层框架.MyBatis 避免了几乎所有的 JDBC 代码和手动设置参数以及获取结果集.MyBatis ...

  9. (转)淘淘商城系列——导入商品数据到索引库——Service层

    http://blog.csdn.net/yerenyuan_pku/article/details/72894187 通过上文的学习,我相信大家已经学会了如何使用Solrj来操作索引库.本文我们将把 ...

  10. 使用CAShapeLayer的path属性与UIBezierPath画出扫描框

    1.CAShapeLayer CAShapeLayer具有path属性,(是CGPath对象),可以使用这个属性与UIBezierPath画出想要的图形.该子类根据其fill color和stroke ...