双倍经验: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. 【AtCoder】AGC033(A-F)

    AGC033 A - Darker and Darker 直接BFS #include <bits/stdc++.h> #define fi first #define se second ...

  2. laravel_Supervisor队列

    Queue 1. 队列驱动 //数据库驱动,修改.env的QUEUE_DRIVER QUEUE_DRIVER=database 1. 数据库表 php artisan queue:table php ...

  3. python — 池

    1. 池 池分为:进程池.线程池 池:预先的开启固定个数的进程数/线程数,当任务来临的时候,直接提交给已经开好的进程 / 线程,让这个进程 / 线程去执行就可以了. 池节省了进程.线程的开启.关闭.切 ...

  4. 玩linux笔记——持续更新

    说在最前面 centos 是基于redhat linux,所以最好的教程在红帽官网 https://access.redhat.com/documentation/en-us/red_hat_ente ...

  5. AlertManager 部署及使用

    熟悉了 Grafana 的报警功能,但是 Grafana 的报警功能目前还比较弱,只支持 Graph 的图表的报警.今天来给大家介绍一个功能更加强大的报警工具:AlertManager. 简介 之前我 ...

  6. HttpContext is null

    HttpContext context1 = System.Web.HttpContext.Current; HttpContext context2 = System.Runtime.Remotin ...

  7. 作业13:Map相关知识点(一)

    一 Map相关类图 二 Map接口 1 Map接口中的方法 jdk 方法名 简单描述 put(K,V):V 添加value,当Key对应无值,返回null;有值则返回上一个值.(覆盖式,可以反复覆盖前 ...

  8. 怎么解决64位Access与32位不能同时安装的问题

    如何在同时安装32位和64位Micsoft Access数据库引擎 ​ 由于某些64位应用程序需要访问Access数据库,而访问数据库须使用AccessDataEngine即Access数据库引擎64 ...

  9. [转载]目标检测-Selective Search

    [转载]目标检测-Selective Search 转载纯粹是因为这篇写的很好,mark一下: https://zhuanlan.zhihu.com/p/27467369

  10. sipp命令 各参数含义

    sipp -sn uac 172.31.89.4:5060 -r 1 -rp 3000 -inf data.csv -p 7098 -i 172.31.89.242 -s 8001 -sf uac_o ...