日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

P2749 夜空繁星

發布時間:2024/3/13 编程问答 44 豆豆
生活随笔 收集整理的這篇文章主要介紹了 P2749 夜空繁星 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

USACO的搜索,不知道為什么和二維凸包扯上關系QAQ
剛看到這道題時無從下手…貌似很難呀,大概翻了一下題解…發現了一個玄學定理: 每一個點和別的點的距離相加,一樣的圖形總是一樣的

QAQ 前方水題警告
接下來就簡單了…

const z:array[1..8,1..2]of -1..1=((1,0),(0,1),(-1,0),(0,-1),(1,1),(1,-1),(-1,1),(-1,-1)); var i,j,k:longint;m,n:longint;ans:array[0..101,0..101]of longint;boo:array[0..101,0..101]of boolean;num:array[0..501]of real;sum2:array[0..501]of longint;x,y:array[0..161]of longint;lastx,lasty:array[0..501]of array[0..161]of longint;sum,add:longint;ch:char;out:array[0..26]of char; procedure same(p,q:longint);//第p個圖形和第q個圖形全等,且第q個圖形在之前出現過 var i:longint; beginfor i:=1 to sum2[q] do ans[lastx[q][i],lasty[q][i]]:=ans[lastx[p][1],lasty[p][1]];//把答案賦值成一樣的 end; procedure new(p:longint);//第p個圖形在之前沒有出現過 var i:longint; begininc(add);//種數++for i:=1 to sum2[p] doans[lastx[p][i],lasty[p][i]]:=add;//把該圖形賦值成這個 end; function long(x1,y1,x2,y2:longint):real;//計算兩點之間距離 beginexit(sqrt(sqr(x1-x2)+sqr(y1-y2))); end; procedure bfs(fx,fy:longint);//BFS最喜歡了,其實dfs也可以 var i,j,k,h,t:longint;have:boolean;from:longint=0; beginh:=1;t:=1;x[1]:=fx;y[1]:=fy;boo[fx,fy]:=false;repeatfor i:=1 to 8 doif boo[x[t]+z[i,1],y[t]+z[i,2]] thenbegininc(h);x[h]:=x[t]+z[i,1];y[h]:=y[t]+z[i,2];boo[x[h],y[h]]:=false;end;inc(t);until t>h;inc(sum);num[sum]:=0;for i:=1 to h dofor j:=1 to h donum[sum]:=num[sum]+long(x[i],y[i],x[j],y[j]);//計算出一個點和別的點的距離之和lastx[sum]:=x;//把經過的位置保留下來lasty[sum]:=y;have:=false;sum2[sum]:=h;for i:=1 to sum-1 doif abs(num[i]-num[sum])<0.0001 then//利用這個定理判斷這兩個圖形全等beginsame(i,sum);have:=true;from:=i;break;end;if not have then new(sum);//在之前沒有全等的圖形 end; beginreadln(n);readln(m);for i:=1 to m dobeginfor j:=1 to n dobeginread(ch);if ch='1' then boo[i,j]:=true;end;readln;end;for i:=1 to m dofor j:=1 to n doif boo[i,j] thenbfs(i,j);out[0]:='0';//這樣輸出簡單for i:=1 to 26 do out[i]:=chr(i+96);for i:=1 to m dobeginfor j:=1 to n do write(out[ans[i,j]]);//QAQwriteln;end; end.

偶爾背一些定理對于做題還是有好處的QAQ

總結

以上是生活随笔為你收集整理的P2749 夜空繁星的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。