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

歡迎訪問 生活随笔!

生活随笔

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

编程问答

codeforces Labyrinth

發布時間:2023/12/1 编程问答 36 豆豆
生活随笔 收集整理的這篇文章主要介紹了 codeforces Labyrinth 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

codeforces Labyrinth

  Time Limit: 2 Sec
  Memory Limit: 512 MB

Description

   You are playing some computer game. One of its levels puts you in a maze consisting of n lines, each of which contains m cells. Each cell either is free or is occupied by an obstacle. The starting cell is in the row r and column c. In one step you can move one square up, left, down or right, if the target cell is not occupied by an obstacle. You can't move beyond the boundaries of the labyrinth.
   Unfortunately, your keyboard is about to break, so you can move left no more than x times and move right no more than y times. There are no restrictions on the number of moves up and down since the keys used to move up and down are in perfect condition.
   Now you would like to determine for each cell whether there exists a sequence of moves that will put you from the starting cell to this particular one. How many cells of the board have this property?
 

Input

   The first line contains two integers \(n, m (1?≤?n,?m?≤?2000)\) — the number of rows and the number columns in the labyrinth respectively.
   The second line contains two integers \(r, c (1?≤?r?≤?n, 1?≤?c?≤?m)\) — index of the row and index of the column that define the starting cell.
   The third line contains two integers \(x, y (0?≤?x,?y?≤?10^9)\) — the maximum allowed number of movements to the left and to the right respectively.
   The next n lines describe the labyrinth. Each of them has length of m and consists only of symbols '.' and ''. The \(j\)-th character of the \(i\)-th line corresponds to the cell of labyrinth at row i and column \(j\). Symbol '.' denotes the free cell, while symbol '' denotes the cell with an obstacle.
   It is guaranteed, that the starting cell contains no obstacles.
 

Output

   Print exactly one integer — the number of cells in the labyrinth, which are reachable from starting cell, including the starting cell itself.
 

Sample Input 1

   \(4\) \(5\)
   \(3\) \(2\)
   \(1\) \(2\)
   \(.....\)
   \(.***.\)
   \(...**\)
   \(*....\)
 

Sample Output 1

  \(10\)
    

Sample Input 2

   \(4\) \(4\)
   \(2\) \(2\)
   \(0\) \(1\)
   \(....\)
   \(..*.\)
   \(....\)
   \(....\)
  

Sample Output 2

  \(7\)
    

HINT

  Cells, reachable in the corresponding example, are marked with '+'.
  
  First example:
  \(+++..\)
  \(+***.\)
  \(+++**\)
  \(*+++.\)
  Second example:
  \(.++.\)
  \(.+*.\)
  \(.++.\)
  \(.++.\)
  

題目地址:codeforces Labyrinth

題目大意:

  讀入一個 \(n*m\) 的圖起點為 \((r,c)\)
  最多可以向左走 \(x\) 步,向右走 \(y\)
  問可以到那些點

題解:

  解法一 \((Dijkstra)\)
  從一個點到另一個點橫向走的步數 \(x\) 和縱向走的步數 \(y\)
  \(x-y\) 為定值
  所以對于一個點,我們只要向左右任意一個方向建一條距離為 \(1\) 的邊,其余三個方向都建距離為 \(0\) 的邊,然后跑 \(Dijkstra\) 就好了,最后時候算一下要向左向右走幾步判一下就好了
  解法二 \((deque)\)
  考試的時候寫了最暴力的 \(bfs ......\)
  因為可能會先做花一些代價的方案到某一個點而把不用花代價的方案給排掉了
  所以我們可以每次把不用花代價的方案放到隊首,把花代價的放到隊尾
  每次從隊首取點,就寫完了
  orz大神們


AC代碼

#include <cstdio> #include <deque> using namespace std; const int N=2005; int n,m,R,C,x,y,ans; char ch[N][N]; bool vis[N][N]; struct note{int x,y,a,b; }; deque<note> q; int main(){scanf("%d%d",&n,&m);scanf("%d%d",&R,&C);scanf("%d%d",&x,&y);for(int i=1;i<=n;i++)scanf("%s",ch[i]+1);q.push_back((note){R,C,x,y});while(!q.empty()){note tmp=q.front();q.pop_front();int x=tmp.x,y=tmp.y;if(vis[x][y])continue;vis[x][y]=1;ans++;if(1<=x-1 && ch[x-1][y]=='.')q.push_front((note){x-1,y,tmp.a,tmp.b});if(x+1<=n && ch[x+1][y]=='.')q.push_front((note){x+1,y,tmp.a,tmp.b});if(1<=y-1 && ch[x][y-1]=='.' && tmp.a)q.push_back((note){x,y-1,tmp.a-1,tmp.b});if(y+1<=m && ch[x][y+1]=='.' && tmp.b)q.push_back((note){x,y+1,tmp.a,tmp.b-1});}printf("%d\n",ans);return 0; }


  作者:skl_win
  出處:https://www.cnblogs.com/shaokele/
  本文版權歸作者和博客園共有,歡迎轉載,但未經作者同意必須保留此段聲明,且在文章頁面明顯位置給出原文連接,否則保留追究法律責任的權利。

轉載于:https://www.cnblogs.com/shaokele/p/9791063.html

總結

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

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

主站蜘蛛池模板: 精人妻一区二区三区 | 91爱爱影院 | 中文字幕一区二区三区人妻在线视频 | 激情五月综合色婷婷一区二区 | 亚洲成人自拍网 | 香蕉尹人网 | 久久影院精品 | ⅹxxxxhd亚洲日本hd老师 | 欧美绿帽交换xxx | 2017狠狠干 | 免费91视频 | 91久久精品一区二区三 | 国产精品18p | 亚洲免费成人在线 | 国产freexxxx性播放麻豆 | 欧美日韩中文字幕一区二区 | 成人欧美一区二区三区在线播放 | 精品国产鲁一鲁一区二区张丽 | 在线看视频 | 日韩字幕在线观看 | 亚洲区第一页 | 日本一区二区免费高清视频 | 欧美性爱视频久久 | 中文字幕亚洲欧美日韩在线不卡 | 又大又粗弄得我出好多水 | 日韩手机看片 | 最新av不卡 | 加勒比av在线播放 | 88国产精品视频一区二区三区 | 自拍偷拍欧美视频 | 国产欧美精品一区二区 | 国产二三区 | 日韩av一区在线观看 | 婷婷亚洲精品 | 激情免费av | 亚洲美女色 | 波多野吉衣中文字幕 | 日韩一级精品 | 日本后进式猛烈xx00动态图 | 黄色三级在线播放 | 扒开女人屁股进去 | 免费在线观看黄色av | 91小宝寻花一区二区三区 | 国产免费观看久久黄av片 | avtt香蕉久久 | 久久久久久久 | 神马午夜久久 | 在线观看入口 | 六十路息与子猛烈交尾 | 美女又爽又黄视频 | 成年人网站在线 | 亚洲精品v日韩精品 | 国产福利一区在线观看 | 六月婷婷av| 国产第一区第二区 | 99精品小视频 | 国产第一页在线观看 | 麻豆三级视频 | 色五丁香| 开心激情婷婷 | 久久首页 | 久久久久亚洲av片无码v | 草草影院在线免费观看 | 免费在线视频观看 | 国产精品久久久久电影 | 涩涩视频免费在线观看 | 成人综合一区二区 | 国产伦精品一区二区三区视频我 | 精品人妻无码一区二区色欲产成人 | 中文字幕无产乱码 | 亚洲综合第一页 | 91av在| 国产99对白在线播放 | 美国av大片| 国产精品高潮呻吟久久久 | 欧美激情在线一区二区 | 成人免费播放 | 奇米影视999 | 久久久久影视 | 粉嫩小泬无遮挡久久久久久 | 欧美.com| 国产日韩欧美激情 | 国产精品久久久久久吹潮 | 国产美女一区二区三区 | 日本老妇性生活 | 欧美大片一区二区 | 射久久 | 波多野结衣伦理 | 一出一进一爽一粗一大视频 | www国产精品内射老熟女 | 另类视频一区 | 日日爱夜夜爱 | 亚洲精品乱码久久久久久9色 | 91aaaa| 精品国产亚洲AV | 人妻少妇一区二区三区 | 日毛片 | 永久免费毛片 | 一本到视频 |