CodeVS第二次月赛
来源:互联网 发布:addictive drums2 mac 编辑:程序博客网 时间:2024/06/06 05:04
传送门
http://codevs.cn/problem/4109/
http://codevs.cn/problem/4110/
http://codevs.cn/problem/4111/
T1 TTY loves numbers
题目大意
给定一个模数m,构造一个最小01串,使其mod m=0
长度为len的01串满足,从第1位到第i位都为1,第i+1到第len位都为0 (1<=i<=len)
题解
根据欧拉定理,
要求10与m互质,那么我们假设m为1e7以内的最大素数10999997
所以长度不超过1e7,一定有解不存在输出’Impossible’的情况
所以,我们从小到大构造全是1的串,如果能整除就直接输出,
如果不能找到之前与其取模之后相等的数做差即为答案
var x:array[0..11000005]of longint; i,j,k:longint; m,ans,len:longint;begin readln(m); ans:=1; len:=1; for i:=1 to 100000000 do begin if ans mod m=0 then begin for j:=1 to len do write(1); writeln; halt; end else if x[ans mod m]<>0 then begin for j:=1 to len-x[ans mod m] do write(1); for j:=1 to x[ans mod m] do write(0); writeln; halt; end else x[ans mod m]:=len; inc(len); ans:=(ans*10+1) mod m; end;end.
T2 TTY Plants Sunflowers
题目大意
给你一棵n个点n-1条边的无根树和每个点的权值,询问任意两点间路线的LIS值
题解
回顾
var w:array[0..8000,1..2]of longint; ans:array[0..2005,0..2005]of longint; d,x,y:array[0..2005]of longint; i,j,k:longint; n,m,len,a,b,anss:longint;procedure init(a,b:longint);begin w[len,1]:=b; if w[a,2]=0 then w[a,2]:=len else w[w[a,1],2]:=len; w[a,1]:=len; inc(len);end;function find(a:longint):longint;var l,r,mid:longint;begin l:=1; r:=anss; while l<r do begin mid:=(l+r)>>1; if a<d[mid] then r:=mid else l:=mid+1; end; exit(l);end;procedure dfs(a,b:longint);var tt,temp,e,f,g:longint;begin y[a]:=1; if x[a]>d[anss] then begin inc(anss); d[anss]:=x[a]; e:=anss; f:=0; g:=-1; end else begin temp:=find(x[a]); e:=temp; f:=d[e]; g:=0; d[e]:=x[a]; end; ans[b,a]:=anss; tt:=w[a,2]; while tt<>0 do begin if y[w[tt,1]]=0 then begin dfs(w[tt,1],b); end; tt:=w[tt,2]; end; d[e]:=f; inc(anss,g);end;begin readln(n); len:=n+1; for i:=1 to n-1 do begin readln(a,b); init(a,b); init(b,a); end; for i:=1 to n do read(x[i]); for i:=1 to n do begin fillchar(y,sizeof(y),0); fillchar(d,sizeof(d),0); anss:=0; dfs(i,i); end; readln(m); for i:=1 to m do begin readln(a,b); writeln(ans[a,b]); end;end.
T3 TTY Saves Da’shgua
题目大意
给出一个序列,进行如下3个操作
1.
2.
3.
题解
[BZOJ3211] 花神游历各国/[BZOJ3038] 上帝造题的七分钟2
var x:array[0..100000]of longint; w:array[0..600000,1..3]of int64; i,j,k:longint; n,m:longint; a,b,c:longint;procedure build(a,l,r:longint);var mid:longint;begin w[a,1]:=l; w[a,2]:=r; if l=r then begin w[a,3]:=x[l]; exit; end; mid:=(l+r)>>1; build(a*2,l,mid); build(a*2+1,mid+1,r); w[a,3]:=w[a*2,3]+w[a*2+1,3];end;procedure update1(a,b,c:longint);var mid:longint;begin if (w[a,1]=w[a,2])//and(w[a,1]=b) then begin w[a,3]:=c; exit; end; mid:=(w[a,1]+w[a,2])>>1; if b<=mid then update1(a*2,b,c) else update1(a*2+1,b,c); w[a,3]:=w[a*2,3]+w[a*2+1,3];end;procedure update2(a,l,r:longint);var mid:longint;begin if w[a,3]=0 then exit; if (w[a,1]=w[a,2]) then begin w[a,3]:=trunc(ln(w[a,3])); exit; end; mid:=(w[a,1]+w[a,2])>>1; if r<=mid then update2(a*2,l,r) else if l>mid then update2(a*2+1,l,r) else begin update2(a*2,l,mid); update2(a*2+1,mid+1,r); end; w[a,3]:=w[a*2,3]+w[a*2+1,3];end;function query(a,l,r:longint):int64;var mid:longint;begin if (w[a,1]=l)and(w[a,2]=r) then exit(w[a,3]); mid:=(w[a,1]+w[a,2])>>1; if r<=mid then exit(query(a*2,l,r)) else if l>mid then exit(query(a*2+1,l,r)) else exit(query(a*2,l,mid)+query(a*2+1,mid+1,r));end;begin readln(n,m); for i:=1 to n do read(x[i]); build(1,1,n); for i:=1 to m do begin readln(a,b,c); case a of 1:update1(1,b,c); 2:update2(1,b,c); 3:writeln(query(1,b,c)); end; end;end.
0 0
- CodeVS第二次月赛
- CodeVS 第二次月赛 A
- CodeVS第二次月赛 B
- codeVS第二次月赛 C
- CodeVS第一次月赛
- CodeVS 第一次月赛 题解
- 大二第二次月赛--手速
- 大二第二次月赛--买水果
- QDU 第二次月赛 求最大值
- QDU第二次月赛 简单题
- 第二次月赛总结(11.27)
- codevs第一次月赛A题
- codevs月赛 奶牛的身高
- 大二第二次月赛--The number of maximum subset
- codevs月赛第一场(3943)数学奇才琪露诺
- codevs月赛第三场4245 Cww的作业
- 求最大值(qduoj)QDU创新实验室第二次月赛B题
- QDU第二次月赛 排在第几个(康拓展开)
- [LeetCode]Subsets
- hdu1599 find the mincost route
- 树莓派无线网卡配置
- Binary Tree Paths
- [LeetCode]Word Search
- CodeVS第二次月赛
- ubuntu 非长期支持版升级系统版本(ssh登录情况适用)
- hdu2064汉诺塔III
- 字符串排序(2015华为校招)
- [LeetCode]Remove Duplicates from Sorted Array II
- graph slam tutorial : g2o 的使用
- c++中类型转换积累(持续更新)
- [LeetCode]Search in Rotated Sorted Array
- HDU 5416 CRB and Tree (树形DP)