[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个节点的颜色不能相同 的情况下进行染色 ...
随机推荐
- python bytes类型
python3中二进制数据则由bytes类型表示,8位一字节 格式化打印文件的二进制编码 with open('spiderman.mkv', "rb") as f: print( ...
- 【译】第21节---Fluent API
原文:http://www.entityframeworktutorial.net/code-first/fluent-api-in-code-first.aspx 在前面的学习中.我们已经看到不同的 ...
- C# Combobox联动
接上一篇博文,对界面做一个小修改,做4个combobox,形成窗口之间的联动: 界面如下: 选择combobox里的条件,单击查询获取数据 首先连接数据库,获取到数据到第一个combobox里,代码在 ...
- 小tip: margin:auto实现绝对定位元素的水平垂直居中
转载自:http://www.zhangxinxu.com/wordpress/?p=3794 一.绝对定位元素的居中实现 如果要问如何CSS实现绝对定位元素的居中效果,很多人心里已经有答案了. 兼容 ...
- activity 运行流程
图1 图2 图3 图四
- python 删除文件夹
只能删除空文件夹,删除非空文件夹会报错 >>> import os >>> os.rmdir("/tmp/ssh-GyoPWOFZ47") Tr ...
- Django中ORM简介与单表数据操作
一. ORM简介 概念:.ORM框架是用于实现面向对象编程语言种不同类型系统的数据之间的转换 构建模型的步骤:重点 (1).配置目标数据库信息,在seting.py中设置数据库信息 DATABASE ...
- es6 Set 结合 Array.from 用法
var arr=[1,2,3,2,3,4,5]; var set=new Set(arr) var arr1=Array.from(set) 重复数组 - Set 化 (去重) - 转回数组 上述 ...
- git 先创建本地仓库,再关联远程
之前都是先在GitHub或者bitbucket上创建repo,然后在本地直接git clone下来. 如果一定需要先在本地创建好文件夹,然后再关联远程仓库. 是这样: 1在远程创建仓库这步不变. 2 ...
- Java 8新特性探究(二)深入解析默认方法
什么是默认方法,为什么要有默认方法 简单说,就是接口可以有实现方法,而且不需要实现类去实现其方法.只需在方法名前面加个default关键字即可. 为什么要有这个特性?首先,之前的接口是个双刃剑,好处是 ...