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. robotframework - Edit编辑器

    1.测试项目&套件 提供的Edit编辑器 2.在 Edit 标签页中主要分:加载外部文件.定义内部变量.定义元数据等三个部分. (1):加载外部文件Add Library:加载测试库,主要是[ ...

  2. RecycleView的简单应用

    recycleView在界面展示上类似于ListView,但不同于ListView的是它展示的每一个item类型可以不一样:    RecycleAdapter类: public class Recy ...

  3. 全面学习ORACLE Scheduler特性(10)管理Chains

    5.2  管理Chains 5.2.1  修改Chains属性 基本上碰到修改CHAIN属性的机率不会太大,因此确实没啥可修改的,对于CHAIN对象来说,能够修改的属性只有两个:evaluation_ ...

  4. 235 Lowest Common Ancestor of a Binary Search Tree 二叉搜索树的最近公共祖先

    给定一棵二叉搜索树, 找到该树中两个指定节点的最近公共祖先. 详见:https://leetcode.com/problems/lowest-common-ancestor-of-a-binary-s ...

  5. scala学习笔记1: scala method

    刚接触scala,做练习的时候碰到一个问题,顺便mark一下. 先看下面一段代码: def sum(args:Int*) = { var result = 0 for (arg <- args) ...

  6. 类函数:string、math

    类:系统内置的处理字符串类型的函数方法类. string是String的快捷方式.所包含的内容都是一样的. Int i=x.length;//获取一个字符串长度 字符串中,索引号从0开始 String ...

  7. Django--知识补充

    自定义标签或过滤器 渲染变量的方法(过滤器:修改数据或格式转换) {{ var | add }} {{ var | date:"Y-m" }} {{ var | safe }} 渲 ...

  8. python+opencv+Face++实现人脸识别比对

    2018-03-2010:16:55 代码仓库--GitHub--https://github.com/az666/python_opencv_face- 依旧是先来图片 下面这张是我进行识别的效果( ...

  9. form表单清空、重置

    form_live为formID <input type="button" value="重置" onclick="$('#form_live' ...

  10. 【Linux】 JDK安装及配置 (linux-tar.gz版)

    安装环境:Linux(CentOS 7 64位 版) JDK安装:tar.gz为解压后就可以使用的版本,这里使用jdk-8u211-linux-x64.tar.gz版,安装到/usr/java/(us ...