一道非常好的綜合題!
因爲有多組數據,要注意的是數組清零。
利用歐拉回路優美的性質構造異或方程組,詳見劉書。
program ex1; var l,u,a,b:array[0..20,0..20] of longint; f:array[0..600,0..600] of boolean; p,next,d,o,g,ans:array[-2000..2000] of longint; t,n,i,j,k,v,sx,sy,ss,tx,ty,tt,tot,task:longint; ok:boolean; procedure link(a,b:longint); begin inc(t);next[t]:=d[a];d[a]:=t;p[t]:=b; next[-t]:=d[b];d[b]:=-t;p[-t]:=a; end; procedure dfs(i:longint);var j,k:longint; begin k:=d[i];j:=p[k]; while k<>0 do begin if o[abs(k)]>0 then begin dec(o[abs(k)]);dfs(j); end; k:=next[k];j:=p[k]; end; inc(ans[0]);ans[ans[0]]:=i; end; procedure add(a,b,c,d:longint;e:boolean); begin fillchar(f[t+1],sizeof(f[0]),0); inc(t);f[t,0]:=e; if a<>0 then f[t,a]:=true; if b<>0 then f[t,b]:=true; if c<>0 then f[t,c]:=true; if d<>0 then f[t,d]:=true; end; begin assign(input,'turn.in');reset(input); assign(output,'turn.out');rewrite(output); readln(task); for task:=1 to task do begin readln(n);tot:=0;t:=0; fillchar(d,sizeof(d),0); fillchar(l,sizeof(l),0); fillchar(u,sizeof(u),0); for i:=1 to n do for j:=1 to n do read(a[i,j]); for i:=1 to n+1 do for j:=1 to n+1 do begin inc(tot);b[i,j]:=tot; if i>1 then begin link(b[i,j],b[i-1,j]); u[i,j]:=t; end; if j>1 then begin link(b[i,j],b[i,j-1]); l[i,j]:=t; end; end; readln(sx,sy);tot:=t;ok:=false; for tx:=1 to n+1 do for ty:=1 to n+1 do if not ok then begin ss:=b[sx,sy];tt:=b[tx,ty]; t:=0; if ss=tt then add(l[sx,sy],u[sx,sy],l[sx,sy+1],u[sx+1,sy],false) else begin add(l[sx,sy],u[sx,sy],l[sx,sy+1],u[sx+1,sy],true); add(l[tx,ty],u[tx,ty],l[tx,ty+1],u[tx+1,ty],true); end; for i:=1 to n+1 do for j:=1 to n+1 do if (b[i,j]<>ss)and(b[i,j]<>tt) then add(l[i,j],u[i,j],l[i,j+1],u[i+1,j],false); for i:=1 to n do for j:=1 to n do add(l[i+1,j+1],u[i+1,j+1],l[i,j+1],u[i+1,j],a[i,j]=1); j:=1;ok:=true; for i:=1 to tot do begin for k:=j to t do if f[k,i] then break; if f[k,i] then begin f[0]:=f[j];f[j]:=f[k];f[k]:=f[0]; for k:=j+1 to t do if f[k,i] then begin for v:=i to tot do f[k,v]:=f[k,v] xor f[j,v]; f[k,0]:=f[k,0] xor f[j,0]; end; g[i]:=j;inc(j); end else g[i]:=0; end; for j:=j to t do if f[j,0] then begin ok:=false; for i:=1 to tot do if f[j,i] then ok:=true; if not ok then break; end; if not ok then continue; for i:=tot downto 1 do if g[i]=0 then o[i]:=2 else begin o[i]:=2-ord(f[g[i],0]); for j:=1 to g[i]-1 do if f[j,i] then f[j,0]:=f[j,0]xor f[g[i],0]; end; ans[0]:=0;dfs(ss); for i:=ans[0]-1 downto 1 do begin if ans[i]+1=ans[i+1] then write('L') else if ans[i]-1=ans[i+1] then write('R') else if ans[i]>ans[i+1] then write('D') else write('U'); end; writeln;break; end; if not ok then writeln('No Solution!'); end; close(input);close(output); end.
一、前言 用ffmpeg做音視頻保存到mp4文件,都會遇到一個問題,尤其是在視頻監控行業,就是監控攝像頭設置的音頻是PCM/G711A/G711U,解碼後對應的格式是pcm_s16be/pcm_alaw/pcm_mulaw,將這個原始的音頻
今天看discuz源碼,在一個函數裏發現這麼個語句: http:// $output && print($ret); 其中$output是這個函數的一個參數,值爲true或false;$ret是一個字符串. 測試了一下,如果$output
將拼接的Sql查詢字串查詢結果賦值給變量@name。 DECLARE @sqlstr VARCHAR(500) DECLARE @name VARCHAR(500) SET @sqlstr='SELECT @nam
繼續運行 ?* 回憶上次內容 上次使用shell環境中的命令 命令 作用 c
前言 作爲表格產品的典型應用場景之一,幾乎所有的行業都會存在類 Excel 報表開發這樣的應用場景,而在這些應用場景中,經常會遇見下面的這些痛點: 報表數據往往來自多個不同的數據源,需要報表系統能夠同時連接多個數據源,並融合不同的數據格式
本文分享自華爲雲社區《GaussDB SQL基本語法示例-CASE表達式》,作者:Gauss松鼠會小助手2。 一、前言 SQL是用於訪問和處理數據庫的標準計算機語言。GaussDB支持SQL標準(默認支持SQL2、SQL3和SQL4的主要
step 1:設置root帳號密碼 輸入命令: sudo passwd root 根據提示輸入root帳號密碼。 step 2:保證以root帳號權限進行後續操作 如果不是用root帳號登錄系統 輸入命令: su ro
Date.parseDate( String input, String format ) : Date 將字符串string依指定的格式format轉換爲時間,其中格式定義詳見format方法 例:dt = Date.parseDat
cvCloneImage()每次使用時編譯器會分配新的內存空間,不會覆蓋以前的內容,所以如果在循環中使用內存會迅速減小,每次用完都需要用cvRelease來釋放。解決方法是使用cvCopy函數代替。cvCopy(pSrcImg,pImg,
關於UCS-2編碼就不多說了,Google一下就大把大把的了 直接上代碼 ;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> .386 .model flat , stdcall option
1)、類型比較和轉換問題 short和int類型之間直接比較或轉換都會出現內存錯誤;2)、判斷文件是否結束時,可能存在回車換行文件並沒真正介紹而內容已經結束了,需要用while (!feof(fp_signal_sort) && (fsc
養生需知:世上最健康的作息時間 7:30:起牀。英國威斯敏斯特大學的研究人員發現,那些在早上5:22―7:21 分起牀的人,其血液中有一種能引起心臟病的物質含量較高,因此,在7:21之後起牀對身體健康更加有益。 7:30―8:00:
hutchin 發表於 2006/10/31, 4:34 PM. 學習 用正則表達式突出顯示字符串中查詢到的單詞的函數<%'''''Function hs(aa,bb) ''建立函數hs,兩值:aa爲內容,bb爲需要查詢的字符Dim re
id="I7" marginwidth="0" marginheight="0" src="http://www.bookeba.cn/securi
1. Java Javasoft: http://www.javasoft.com Sun: www.sun.com Developer.com: http://java.developer.com Tutorial: http://