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

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

Wang Xifeng's Little Plot (poj 5024 DFS)

發(fā)布時(shí)間:2023/12/20 编程问答 46 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Wang Xifeng's Little Plot (poj 5024 DFS) 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

Wang Xifeng's Little Plot

Time Limit: 2000/1000 MS (Java/Others)????Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 133????Accepted Submission(s): 89


Problem Description 《Dream of the Red Chamber》(also 《The Story of the Stone》) is one of the Four Great Classical Novels of Chinese literature, and it is commonly regarded as the best one. This novel was created in Qing Dynasty, by Cao Xueqin. But the last 40 chapters of the original version is missing, and that part of current version was written by Gao E. There is a heart breaking story saying that after Cao Xueqin died, Cao's wife burned the last 40 chapter manuscript for heating because she was desperately poor. This story was proved a rumor a couple of days ago because someone found several pages of the original last 40 chapters written by Cao.

In the novel, Wang Xifeng was in charge of Da Guan Yuan, where people of Jia family lived. It was mentioned in the newly recovered pages that Wang Xifeng used to arrange rooms for Jia Baoyu, Lin Daiyu, Xue Baochai and other teenagers. Because Jia Baoyu was the most important inheritor of Jia family, and Xue Baochai was beautiful and very capable , Wang Xifeng didn't want Jia Baoyu to marry Xue Baochai, in case that Xue Baochai might take her place. So, Wang Xifeng wanted Baoyu's room and Baochai's room to be located at two ends of a road, and this road should be as long as possible. But Baoyu was very bad at directions, and he demanded that there could be at most one turn along the road from his room to Baochai's room, and if there was a turn, that turn must be ninety degree. There is a map of Da Guan Yuan in the novel, and redists (In China English, one whose job is studying 《Dream of the Red Chamber》is call a "redist") are always arguing about the location of Baoyu's room and Baochai's room. Now you can solve this big problem and then become a great redist.
Input The map of Da Guan Yuan is represented by a matrix of characters '.' and '#'. A '.' stands for a part of road, and a '#' stands for other things which one cannot step onto. When standing on a '.', one can go to adjacent '.'s through 8 directions: north, north-west, west, south-west, south, south-east,east and north-east.

There are several test cases.

For each case, the first line is an integer N(0<N<=100) ,meaning the map is a N × N matrix.

Then the N × N matrix follows.

The input ends with N = 0.
Output For each test case, print the maximum length of the road which Wang Xifeng could find to locate Baoyu and Baochai's rooms. A road's length is the number of '.'s it includes. It's guaranteed that for any test case, the maximum length is at least 2.
Sample Input 3 #.# ##. ..# 3 ... ##. ..# 3 ... ### ..# 3 ... ##. ... 0
Sample Output 3 4 3 5
Source 2014 ACM/ICPC Asia Regional Guangzhou Online
Recommend hujie???|???We have carefully selected several similar problems for you:??5031?5030?5029?5028?5027? 題意:求兩點(diǎn)使它們的距離最大,只能轉(zhuǎn)一次彎,并且是90度。 思路:遍歷全圖,找最大值,注意dir數(shù)組按照一個(gè)圓寫,這樣好控制方向,搜的時(shí)候有三個(gè)方向:直走,左轉(zhuǎn)90度,右轉(zhuǎn)90度。另外注意從邊界進(jìn)入開(kāi)始搜。 代碼: #include <iostream> #include <cstdio> using namespace std;int dir[8][2]={-1,-1,-1,0,-1,1,0,1,1,1,1,0,1,-1,0,-1}; char mp[110][110]; int N,maxx;bool ISok(int x,int y) {if (x>=0&&x<N&&y>=0&&y<N&&mp[x][y]!='#')return true;return false; }void dfs(int Dir,int x,int y,int step,int number) {int flag=0,dx,dy;dx=x+dir[Dir][0]; //直走dy=y+dir[Dir][1];if (ISok(dx,dy)){flag=1;dfs(Dir,dx,dy,step+1,number);}if (number){int D=(Dir+2)%8; //左轉(zhuǎn)dx=x+dir[D][0];dy=y+dir[D][1];if (ISok(dx,dy)){flag=1,number=0;dfs(D,dx,dy,step+1,number);}D=(Dir+6)%8; //右轉(zhuǎn)dx=x+dir[D][0];dy=y+dir[D][1];if (ISok(dx,dy)){flag=1,number=0;dfs(D,dx,dy,step+1,number);}}if (flag&&step>maxx)maxx=step; }int main() {int i,j;while (scanf("%d",&N),N){for (i=0;i<N;i++)scanf("%s",mp[i]);maxx=0;for (i=0;i<N;i++){for (j=0;j<N;j++){if (i==0||j==0||i==(N-1)||j==(N-1)) //從邊界進(jìn)入{if (mp[i][j]!='#'){for (int t=0;t<8;t++)dfs(t,i,j,1,1);}}}}printf("%d\n",maxx+1);}return 0; }

轉(zhuǎn)載于:https://www.cnblogs.com/i8888/p/4044016.html

總結(jié)

以上是生活随笔為你收集整理的Wang Xifeng's Little Plot (poj 5024 DFS)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。