[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个节点的颜色不能相同 的情况下进行染色 ...
随机推荐
- Javascript 日期格式化 相关操作
1.相关扩展函数 //--------------------------------------------------- // 判断闰年 //--------------------------- ...
- Model中时间格式化
MVC 中 @Html中的时间格式化 @Html.TextBoxFor(model => model.StartTime, "{0:yyyy-MM-dd HH:mm:ss}" ...
- Python 爬虫入门3种方法
Python 2.0 url = "http://www.baidu.com" print '第一种方法' response1 = urllib2.urlopen(url) pri ...
- 【Django】Django-REST-Framework
[创建简单的API] 1. cmd.exe >django-admin startproject django_rest>cd django_rest\django_rest>pyt ...
- gensim使用方法以及例子
来自:https://blog.csdn.net/u014595019/article/details/52218249 gensim是一个Python的自然语言处理库,能够将文档根据TF-IDF,L ...
- 设置本地虚拟域名windows+apache
C:\WINDOWS\system32\drivers\etc\hosts 在这个文件中 最下面添加. 127.0.0.1 localhost.com 127.0.0.1 cho.com 12 ...
- "不是内部或外部命令"
问题描述: 使用cmd 运行某个路径下(一般是C:PROGRAM FILES\...或者E:\program files\....或者D:\program files\......下面的某个)的exe ...
- 力扣(LeetCode)412. Fizz Buzz
写一个程序,输出从 1 到 n 数字的字符串表示. 如果 n 是3的倍数,输出"Fizz": 如果 n 是5的倍数,输出"Buzz": 3.如果 n 同时是3和 ...
- 温馨小程序前端布局Flex
伸缩容器支持的属性有: 1,display 2,flex-direction 3,flex-wrap 4,flex-flow 5,justify-content 6,align-items 7,ali ...
- 最新省市区数据,sql插入语句
--省数据 insert into Province (ProvinceName) values('北京市'); insert into Province (ProvinceName) value ...