打个表然后暴力就行,也可以蔡勒公式。
Code const first:array[1582..2012] of shortint= (5,6,0,2,3,4,5,0,1,2,3,5,6,0,1,3,4,5,6,1,2,3,4,6,0,1,2,4,5,6,0,2,3,4,5,0,1,2,3, 5,6,0,1,3,4,5,6,1,2,3,4,6,0,1,2,4,5,6,0,2,3,4,5,0,1,2,3,5,6,0,1,3,4,5,6,1,2,3, 4,6,0,1,2,4,5,6,0,2,3,4,5,0,1,2,3,5,6,0,1,3,4,5,6,1,2,3,4,6,0,1,2,4,5,6,0,2,3, 4,5,6,0,1,2,4,5,6,0,2,3,4,5,0,1,2,3,5,6,0,1,3,4,5,6,1,2,3,4,6,0,1,2,4,5,6,0,2, 3,4,5,0,1,2,3,5,6,0,1,3,4,5,6,1,2,3,4,6,0,1,2,4,5,6,0,2,3,4,5,0,1,2,3,5,6,0,1, 3,4,5,6,1,2,3,4,6,0,1,2,4,5,6,0,2,3,4,5,0,1,2,3,4,5,6,0,2,3,4,5,0,1,2,3,5,6,0, 1,3,4,5,6,1,2,3,4,6,0,1,2,4,5,6,0,2,3,4,5,0,1,2,3,5,6,0,1,3,4,5,6,1,2,3,4,6,0, 1,2,4,5,6,0,2,3,4,5,0,1,2,3,5,6,0,1,3,4,5,6,1,2,3,4,6,0,1,2,4,5,6,0,2,3,4,5,0, 1,2,3,5,6,0,1,2,3,4,5,0,1,2,3,5,6,0,1,3,4,5,6,1,2,3,4,6,0,1,2,4,5,6,0,2,3,4,5, 0,1,2,3,5,6,0,1,3,4,5,6,1,2,3,4,6,0,1,2,4,5,6,0,2,3,4,5,0,1,2,3,5,6,0,1,3,4,5, 6,1,2,3,4,6,0,1,2,4,5,6,0,2,3,4,5,0,1,2,3,5,6,0,1,3,4,5,6,1,2,3,4,6,0,1,2,4,5,6,0); dom:array[1..12] of shortint=(31,28,31,30,31,30,31,31,30,31,30,31); word:array[0..6] of string=('sunday','monday','tuesday','wednesday','thursday','friday','saturday'); var c,y,m,d,now,i:longint; begin readln(y,m,d); if((y mod 100=0)and(y mod 400=0))or ((y mod 100<>0)and(y mod 4=0)) then dom[2]:=29; now:=first[y]; for i:=1 to m-1 do now:=(now+dom[i])mod 7; now:=(now+(d-1))mod 7; writeln(word[now]); //Zeller if(m<3) then begin m:=m+12;y:=y-1;end; c:=y div 100; y:=y mod 100; now:=y+y div 4+c div 4-c<<1+26*(m+1)div 10+d-1; inc(now,(abs(now)div 7+1)*7); writeln(word[now mod 7]); end.
树状数组+先序遍历,想到正解结果忘记写一个点被改变好几次。可怜的WA10了,日。
Code program Chess; CONST FileName='Chess'; maxn=100000; var u,Index,tot,n,m,i,a,b:longint; v,next:array[1..maxn*2] of longint; e,l,r,data:array[1..maxn] of longint; vis:array[1..maxn] of boolean; flag:char; function LowBit(x:longint):longint; begin LowBit:=x and -x; end; procedure add(i,x:longint); begin while i<=n do begin inc(data[i],x); i:=i+LowBit(i); end; end; function sum(i:longint):int64; begin sum:=0; while i>0 do begin inc(sum,data[i]); i:=i-Lowbit(i); end; end; procedure build(a,b:longint); begin inc(tot); v[tot]:=b; next[tot]:=e[a]; e[a]:=tot; end; procedure DFS(u:longint); var i:longint; begin vis[u]:=true; inc(Index); l[u]:=Index; i:=e[u]; while i<>0 do begin if not vis[v[i]] then DFS(v[i]); i:=next[i]; end; r[u]:=Index; end; BEGIN readln(n); for i:=1 to n-1 do begin readln(a,b); build(a,b); build(b,a); end; DFS(1); readln(m); fillchar(vis,sizeof(vis),false);//vis=black for i:=1 to m do begin readln(flag,u); case flag of 'Q':writeln(r[u]-l[u]+1-sum(r[u])+sum(l[u]-1)); 'C':if vis[u] then begin add(l[u],-1);vis[u]:=false;end else begin add(l[u], 1);vis[u]:=true; end; end; end; END.
writeln(n-1)有20分好开心。
如果点1不连边,其他点向树连一条边,那么最后这就是一刻树,对于每个点找出能使他连到树上以后满足最短路的边的条数,然后乘法原理。一开始SPFA写萎了T了4个点以为是数据猥琐,然后去找出题人(ym lyd大神),结果被人家发现是InQ忘记更新,然后存邻接表的数组开小了。
Codeprogram castle; CONST FileName='castle2'; maxn=1100; p=(1<<31)-1; var InQ,vis,vb:array[1..maxn] of boolean; num,pos,adjlist,d,Q,bian:array[1..maxn] of longint; v,w,next:array[1..maxn*maxn] of longint; cnt,x,y,l,tot,n,m,i,j:longint; ans:int64=1; map:array[1..maxn,1..maxn] of integer; procedure save(x,y,l:longint); begin if (map[x][y]>0)and(map[x][y]<l)then l:=map[x][y]; map[x][y]:=l; map[y][x]:=l; end; procedure build(x,y,l:longint); begin inc(tot); v[tot]:=y; w[tot]:=l; next[tot]:=Adjlist[x]; Adjlist[x]:=tot; end; procedure SPFA; var h,t,i:longint; begin Q[1]:=1;d[1]:=0;InQ[1]:=true;h:=0;t:=1; for i:=2 to n do d[i]:=maxlongint; while h<>t do begin inc(h);if h>maxn then h:=1; i:=Adjlist[Q[h]]; while i<>0 do begin if w[i]+d[Q[h]]<d[v[i]] then begin d[v[i]]:=w[i]+d[Q[h]]; if not InQ[v[i]] then begin inc(t);if t>maxn then t:=1; Q[t]:=v[i];inQ[v[i]]:=true; end; end; i:=next[i]; end; InQ[Q[h]]:=false; end; end; procedure swap(var a,b:longint); var t:longint;begin t:=a;a:=b;b:=t;end; procedure Qsort(l,r:longint); var i,j,mid:longint; begin i:=l;j:=r;mid:=d[(l+r)>>1]; repeat while(i<r)and(d[i]<mid)do inc(i); while(l<j)and(mid<d[j])do dec(j); if i<=j then begin swap(d[i],d[j]); pos[num[i]]:=j; pos[num[j]]:=i; swap(num[i],num[j]); inc(i);dec(j); end; until i>j; if(i<r)then Qsort(i,r); if(l<j)then Qsort(l,j); end; BEGIN Assign(input,FileName+'.in'); Assign(output,FileName+'.out'); Reset(input);Rewrite(output); readln(n,m);tot:=1; for i:=1 to n do begin num[i]:=i; pos[i]:=i; end; for i:=1 to m do begin readln(x,y,l); save(x,y,l); end; for i:=1 to n do for j:=i+1 to n do if map[i][j]>0 then begin build(i,j,map[i][j]); build(j,i,map[i][j]); end; SPFA;Qsort(2,n); for x:=2 to n do begin i:=Adjlist[num[x]];cnt:=0; while i<>0 do begin if d[pos[v[i]]]+w[i]=d[x] then inc(cnt); i:=next[i];end; ans:=(ans*cnt)mod p; if cnt=0 then writeln(x:5,'*'); end; writeln(ans); Close(input);Close(output); END.
总结
今天220是不难的,是可以rank29的,结果我拿了130,无奈的rank88。
果然写暴力就有收获,还有就是想到正解的题目要多造数据。