[contest 782] 9.7
[contest 782] 9.7 - XJOI
个人觉得温暖题啊,,,可是卡毛空间呀!!!
T1 传送
线性筛预处理,然后一遍BFS。显然,这个BFS是O(n)的,主要要卡的就是预处理。
code:
%:pragma gcc optimize()
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
;
int L,R,n,H,T;
],cnt;
bool isp[N];
int Q[N],f[N];
short D[N];
void Maker(){
memset(isp,,]=isp[]=;
memset(p,,,D[]=;
; i<N; i++){
;
; j<=cnt&&(long long)i*p[j]<N; j++){
isp[i*p[j]]=;
){
;
) c++,now/=p[j];
D[i*p[j]]=D[i]/(c+)*(c+);
break;
}else D[i*p[j]]=D[i]+D[i];
}
}
}
)%N,Q[T]=x;}
int main(){
Maker();
int Ts; scanf("%d",&Ts);
for (; Ts; Ts--){
scanf("%d%d%d",&L,&R,&n);
memset(Q,,,T=,Q[]=L;
memset(f,,;
int x,y;
if (L!=R)
while (H!=T){
H=(H+)%N,x=Q[H],y=D[x]; if (x==R) break;
if (x+y<=n){
) f[x+y]=f[x]+,pus(x+y);
}
){
) f[x-y]=f[x]+,pus(x-y);
}
}
printf("%d\n",f[R]);
}
;
}
T2 异或
一眼就是字典树,然而我把ch数组初值赋了-1然后计数时出现了一些奇妙的事情。。。
事实上,ai^x<=lim这是没有不等式规律的,然而,我们可以把他按位来计算,字典树就很有作用了。
复杂度大概是O(30n)。
code:
#include<cstdio>
#include<cstring>
#include<algorithm>
#define M(a,x) memset(a,x,sizeof a)
#define jug(i,x) (((1<<i)&x)>0)
using namespace std;
;
int n,m,a[N];
struct Trie{
][],va[N*];
void init(){
siz=,M(ch,),M(va,);
}
void insert(int x){
;
; i>=; i--){
bool c=jug(i,x);
if (!ch[u][c]) ch[u][c]=++siz;
u=ch[u][c],va[u]++;
}
}
int query(int x,int lim){
) ;
,ret=n;
; i>=; i--){
bool v=jug(i,x),w=jug(i,lim);
) ret-=va[ch[u][-(w^v)]];
u=ch[u][w^v];
}
return ret;
}
}t;
inline int read(){
; char ch=getchar();
') ch=getchar();
+ch-',ch=getchar();
return x;
}
int main(){
n=read(),m=read(),t.init();
; i<=n; i++)
a[i]=read(),t.insert(a[i]);
for (; m; m--){
int x=read(),L=read(),R=read();
printf());
}
;
}
T3 棋盘
md,看到这题就想表一下。为什么要卡16MB!!!
还不是因为我手贱将f[1<<20]“细心地”变成f[1<<21],然后爆了0.39M内存。。。
好吧,这就是个状压DP,真的水。
code:
%:pragma gcc optimize()
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#define LL long long
using namespace std;
;
][];
<<];
LL ans;
int main(){
scanf(<<n);
; i<n; i++) scanf("%s",G[i]);
memset(f,,sizeof f);
; i<n; i++) ][i]==<<i]=;
; r<n; r++){
; j--)
; i<n; i++)
<<i)&j)==)
f[j|(<<i)]=((LL)f[j|(<<i)]+f[j])%TT;
; i<n; i++) <<i]++;
}
; j<M; j++){
;
; i<n; i++) <<i)&j) c++;
if (c==k) ans=(ans+f[j])%TT;
}
printf("%lld",ans%TT);
;
}
总而言之,题目不难,限制变态。。。
[contest 782] 9.7的更多相关文章
- Codeforces 782C. Andryusha and Colored Balloons 搜索
C. Andryusha and Colored Balloons time limit per test:2 seconds memory limit per test:256 megabytes ...
- 树的性质和dfs的性质 Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals) E
http://codeforces.com/contest/782/problem/E 题目大意: 有n个节点,m条边,k个人,k个人中每个人都可以从任意起点开始走(2*n)/k步,且这个步数是向上取 ...
- 2-sat Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals) D
http://codeforces.com/contest/782/problem/D 题意: 每个队有两种队名,问有没有满足以下两个条件的命名方法: ①任意两个队的名字不相同. ②若某个队 A 选用 ...
- Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals) E Underground Lab
地址:http://codeforces.com/contest/782/problem/E 题目: E. Underground Lab time limit per test 1 second m ...
- Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals) D. Innokenty and a Football League
地址:http://codeforces.com/contest/782/problem/D 题目: D. Innokenty and a Football League time limit per ...
- Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals) C Andryusha and Colored Balloons
地址:http://codeforces.com/contest/782/problem/C 题目: C. Andryusha and Colored Balloons time limit per ...
- Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals) B. The Meeting Place Cannot Be Changed
地址:http://codeforces.com/contest/782/problem/B 题目: B. The Meeting Place Cannot Be Changed time limit ...
- Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals) A. Andryusha and Socks
地址:http://codeforces.com/contest/782/problem/A 题目: A. Andryusha and Socks time limit per test 2 seco ...
- 【codeforces 782C】Andryusha and Colored Balloons
[题目链接]:http://codeforces.com/contest/782/problem/C [题意] 给你一棵树 让你满足要求 ->任意相连的3个节点的颜色不能相同 的情况下进行染色 ...
随机推荐
- [学习一个] Matlab GUI 学习笔记 Ⅰ
Matlab GUI 学习笔记 Ⅰ 1. Foreword Matlab 是严格意义上的编程语言吗?曾经有人告诉我他是通过 Matlab 学会了面对对象编程,我是不信的,但这依然不妨碍它在特殊领域的强 ...
- 【Selenium2】【环境搭建】
Windows7 64位 Mozilla Firefox 36.0.4 + Firebug 2.0.19 + FirePath 0.9.7.1.1-signed.1-signed 火狐历史版本:ht ...
- QQ帐户的申请与登陆-(字符串操作)
题目: 实现QQ新帐户申请和老帐户登陆的简化版功能.最大挑战是:据说现在的QQ号码已经有10位数了. 输入格式: 输入首先给出一个正整数N(≤10^5),随后给出N行指令.每行指令的格式为:“命令符( ...
- 【BZOJ】3576: [Hnoi2014]江南乐
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=3576 很显然,这是一个multi-nim游戏. 注意:1.一个点的SG值就是一个不等于它的 ...
- 【BZOJ】3209: 花神的数论题
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=3209 显然是按照二进制位进行DP. 考虑预处理$F[i][j]$表示到了二进制的第$i$位 ...
- STL_头文件
#include <string> #include <vector> #include <deque> #include <queue> #inclu ...
- Java String删除字符串中间的某部分
当你想删除字符串中的某部分时,java中并没有直接提供相关的方法,比如想删除 "cout<<\"Hello world\"<<endl" ...
- R语言 平滑连接
参考自 153分钟 使用平滑曲线,沿着X轴从左向右的顺序依次连接,可以使用spline样条函数线. x = 1:5 y = c(1,3,4,2.5,2) plot(x,y) sp = spline(x ...
- ubuntu 18.04编译opencv3.4.3 with python3.6 cuda9.2 gdal
惭愧,之前一直没在linux下编译过opencv,也没用过纯命令行版的cmake,现在咬牙编译一次.其实感觉还凑合. opencv官网文档还是那么烂:https://docs.opencv.org/m ...
- Qt5标准文件对话框类
getOpenFileName()函数返回用户选择的文件名,其函数形式如下: QString QFileDialog::getOpenFileName(QWidget *parent = Q_NULL ...