Invasion of tyvj 1030 milk grass

Source: Internet
Author: User
Tags define local

The Basic Search is finished with a simple BFs.

Give a grass, and then take the grass as the center of the Nine Palaces, spread to eight directions around each week, and ask how many weeks can fill the farm.

Traverse the entire map. The week number of the last outgoing queue is required.

 

 1 //#define LOCAL 2 #include <iostream> 3 #include <cstdio> 4 #include <cstring> 5 #include <queue> 6 using namespace std; 7  8 struct Point 9 {10     int x, y;11     int days;12 }start;13 14 char map[105][105];15 int r, c, ans;16 int dir[8][2] = {1,0,-1,0,0,1,0,-1,1,1,1,-1,-1,1,-1,-1};17 18 bool islegal(int x, int y)19 {20     return (x>=0 && x<r && y>=0 && y<c &&map[x][y]==‘.‘);21 }22 23 void BFS(void)24 {25     queue<Point> qu;26     Point cur, next;27     start.days = 0;28     qu.push(start);29     while(!qu.empty())30     {31         cur = qu.front();32         qu.pop();33         for(int i = 0; i < 8; ++i)34         {35             next = cur;36             next.x += dir[i][0], next.y += dir[i][1];37             if(islegal(next.x, next.y))38             {39                 next.days = ans = cur.days + 1;40                 map[next.x][next.y] = ‘*‘;41                 qu.push(next);42             }43         }44     }45 }46 47 int main(void)48 {49     #ifdef LOCAL50         freopen("1030in.txt", "r", stdin);51     #endif52 53     scanf("%d%d%d%d", &c, &r, &start.y, &start.x);54     --start.x, --start.y; 55     for(int i = r - 1; i >= 0; --i)56         scanf("%s", map[i]);57     map[start.x][start.y] = ‘*‘;58     ans = 0;59     BFS();60     printf("%d\n", ans);61     return 0;62 }
Code Jun

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.