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. 10.27night清北刷题班

    /* 枚举每个部分的总和,利用前缀和进行检验. 如果能分成4部分就一定能分成2部分,就筛了一边素数优化.清空数组!!! */ #include<bits/stdc++.h> #define ...

  2. justify-content属性

    justify-content 用于设置或检索弹性盒子元素在主轴方向上的对齐方式. 属性值:flex-start 属性值:flex-end 属性值:center 属性值:space-between 属 ...

  3. 题解报告:poj 1321 棋盘问题(dfs)

    Description 在一个给定形状的棋盘(形状可能是不规则的)上面摆放棋子,棋子没有区别.要求摆放时任意的两个棋子不能放在棋盘中的同一行或者同一列,请编程求解对于给定形状和大小的棋盘,摆放k个棋子 ...

  4. NHibernate3.2学习笔记

    一.开发环境 数据库:SQLServer2008 编译器:VS2010 .Net版本:.Net Framework 4.0 二.涉及第三方程序集 NHibernate.dll:版本3.2 Iesi.C ...

  5. 6.13---example

    example如何使用?简单查询这个例子展示了如何用生成后的Example类去生成一个简单的where子句: TestTableExample example = new TestTableExamp ...

  6. leetcode377 Combination Sum IV

    思路: dp. 实现: class Solution { public: int combinationSum4(vector<int>& nums, int target) { ...

  7. 简述 MVC, MVP, MVVM三种模式

    Make everything as simple as possible, but not simpler - Albert Einstein* 把每件事,做简单到极致,但又不过于简单 - 阿尔伯特 ...

  8. ci框架中model简单的mysql操作

    <?php class SingerModel extends CI_Model { function SingerModel() { //会将数据库对象赋值给CI_Controller的db属 ...

  9. h5移动端混编总结

    1.通信机制:解决是否能通信的问题: 2.接口:解决调用会话问题: 3.数据.URL正确性:解决数据.URL跳转路径正确性问题.

  10. nodejs连接数据库

    var express = require("express");var query = require("querystring");var mysql = ...