双倍经验:BZOJ 2393 Cirno的完美算数教室


做法:先把$[1,r]$中所有的幸运数字筛出来,然后用这些幸运数字来筛$[l,r]$中的近似幸运号码;

剪枝:当一个幸运数字$a[i]$是另一个幸运数字$a[j]$的倍数时,那么应该把$a[i]$去掉;

贡献用容斥搞一下好了(就是dfs部分)。。

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<cctype>
#include<cstdlib>
#include<vector>
#include<map>
#include<set>
#define ll long long
#define R register ll
static char B[<<],*S=B,*D=B;
#define getchar() (S==D&&(D=(S=B)+fread(B,1,1<<15,stdin),S==D)?EOF:*S++)
using namespace std;
inline ll g() {
R ret=,fix=; register char ch; while(!isdigit(ch=getchar())) fix=ch=='-'?-:fix;
do ret=ret*+(ch^); while(isdigit(ch=getchar())); return ret*fix;
} ll q[],l,r,ans; bool vis[]; int tot;
inline void PRE(ll x) {if(x>r) return ; if(x) q[++tot]=x; PRE(x*+); PRE(x*+);}
inline ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
inline bool cmp(const ll& a,const ll& b) {return a>b;}
inline void dfs(int x,int d,ll L) {
if(x==tot) return ; ++x; dfs(x,d,L); d^=;
if(vis[x]) return ; L=L*q[x]/gcd(L,q[x]);
if(L<=||L>r) return ; if(d) ans+=r/L-(l-)/L;
else ans-=r/L-(l-)/L; dfs(x,d,L);
}
signed main() {
l=g(),r=g(); PRE(); sort(q+,q+tot+,cmp);
for(R i=;i<=tot;++i) for(R j=i+;j<=tot;++j) if(q[i]%q[j]==) {vis[i]=; break; }
dfs(,,); printf("%lld\n",ans);
}

2019.06.04别颓。

Luogu P2567 [SCOI2010]幸运数字 容斥+脑子的更多相关文章

  1. bzoj1853[Scoi2010]幸运数字 容斥

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

  2. [BZOJ1853][Scoi2010]幸运数字 容斥+搜索剪枝

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

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

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

  4. P2567 [SCOI2010]幸运数字 DFS+容斥定理

    P2567 [SCOI2010]幸运数字 题目描述 在中国,很多人都把6和8视为是幸运数字!lxhgww也这样认为,于是他定义自己的“幸运号码”是十进制表示中只包含数字6和8的那些号码,比如68,66 ...

  5. P2567 [SCOI2010]幸运数字

    题目 P2567 [SCOI2010]幸运数字 做法 容斥+剪枝 先预处理幸运数字,别看数据范围这么大,其实也没几个,然后去掉倍数这种 然后处理相似数字,一眼的容斥,递归选数然后求出这些的公倍数容斥一 ...

  6. [洛谷P2567] SCOI2010 幸运数字

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

  7. BZOJ1853 Scoi2010 幸运数字 【枚举+容斥】

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

  8. 【BZOJ1853/2393】[Scoi2010]幸运数字/Cirno的完美算数教室 DFS+容斥

    [BZOJ1853][Scoi2010]幸运数字 Description 在中国,很多人都把6和8视为是幸运数字!lxhgww也这样认为,于是他定义自己的“幸运号码”是十进制表示中只包含数字6和8的那 ...

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

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

随机推荐

  1. (十八)JDBC获取存储过程和主键

    目录 获取数据库自动生成的主键: JDBC调用存储过程 获取数据库自动生成的主键: update 更新操作以后,如果需要用到结果集,可以通过 PreparedStatement.getResultSe ...

  2. 数据结构:BF算法

    贴上源代码: #include<iostream> using namespace std; int BF(char S[],char T[]) { int i,j; i = j = 0; ...

  3. 剑指offer45:扑克牌顺子

    1 题目描述 LL今天心情特别好,因为他去买了一副扑克牌,发现里面居然有2个大王,2个小王(一副牌原本是54张^_^)...他随机从中抽出了5张牌,想测测自己的手气,看看能不能抽到顺子,如果抽到的话, ...

  4. Python字符串的常用方法总结

    tring.capitalize() 把字符串的第一个字符大写 string.center(width) 返回一个原字符串居中,并使用空格填充至长度 width 的新字符串 , end=len(str ...

  5. PBE加密 .net 实现

    using System; using System.Security.Cryptography; using System.Text; namespace Demo { internal class ...

  6. python3.7 lxml4.2.5 etree xpath 的使用

    #2019年10月14日11:08:49 from lxml import html etree = html.etree html = etree.HTML(response_dl.content) ...

  7. vue学习(10)-vue-resource

    下载:cnpm i vue-resource --save 在main.js导入包:import VueResource from 'vue-resource' 安装:Vue.use(VueResou ...

  8. vue组件常用传值

    一.使用Props传递数据   在父组件中使用儿子组件 <template> <div> 父组件:{{mny}} <Son1 :mny="mny"&g ...

  9. wepy2创建项目

    1.首先 在桌面(自己选定目录下)新建一个文件夹,注意需要使用英文名. 2.Cmd中  进入到该文件目录下 3.安装 wepy 命令行工具. npm install wepy-cli -g wepy ...

  10. 【坑】new一个对象时,tostring报空指针异常

    错误环境 java1.8.0_111 错误描述 对某vo进行了修改,属性类型由long修改为了Long,getter.setter没有修改类型 调用该对象的new方法时抛出npe 错误原因 没深究.. ...