A detailed explanation of the fork function in Linux (GO)

Source: Internet
Author: User

http://cdn.ac.nbutoj.com/Problem/view.xhtml?id=1541

When rain, Noclyt discovered a magical phenomenon and the rainwater always flow to the low-lying place.

I later in the problem put a short section of the topic, let people more easily search, there is no idea! (Ah, it seems that all the topics are more likely to be searched) (but that seems to be a bit messy AH)

[1541] Rainwater time limit: theMS Memory limit:262144K problem description When rain, Noclyt discovered a magical phenomenon that the rainwater always flow to the low-lying place. Now, there isA N *N grid matrix (four Unicom) and above, the first row was constantly raining. I have a to-tell you some rules:1. Each grid isSolid (represented asBlack) Initially, the rain cannot flow into the solid grid. 2. You can"Open"A grid,ifYou"Open"That grid, which grid would becomes hollow (represented asWhite ). 3. Rainwater can flow fromTop to bottom and fromLeft-to-right (also-left), but the precondition isThat they is both hollow grid. (Grid fill with rainwater represented asBlue) You canGetMore information frombelow picture. Figure: fromLeft-to-right is executed -Times -Times MaxTimes204Times"Open"operation. We have three operation:1. O I J:"Open"the Grid (I, j).2. F I j:you should tell me whether the grid (I, j) filled with rainwater. If Yes, you should output1, otherwise output0. 4. C:you should tell me whether the rainwater have flow to the last row. If Yes, you should output1, otherwise output0. Note:the Grid Matrix fromTop to bottom number1To N, fromLeft-to-right number1to N. Input there is multiple test cases, each test CaseContains positive integers N (1<= N <= the) and M (1<= M <=1000000). Following M lines, each line contain one of the three operation:1. O I J (1<= I, J <=N)2. F I J (1<= I, J <=N)3. C Output the answer. Sample Input3 7O1 1F2 1O2 1F2 1CO3 1C Sample Output0101tip no source Noclyt @SDAU
Topics

I hide the subject in a row so that it is not messy and seems to be able to be searched. However, this format is a bit funny, to see the topic or point link to watch.

OK, here's the question rainwater:

Look at the picture is easy to understand the meaning, is your three kinds of operation is to open a hole, check a hole there is no water, check the bottom row there is no. The water will appear from the top row and then flow randomly, looking at the last figure to know it will go up.

After reading the topic, this is not the deep search of super water!

Start the map from 1 and fill the No. 0 line with water first. Every time you open a piece, if there is no water in four directions, then this piece must have no water. If there is water, then fill this out with water, and a deep search for a wave, the place can be reached. This way, the maximum water per cell, the complexity of ultra-low. Then it asked a hole when the direct answer, ask the bottom of this line is also a direct answer, when searching remember the bottom of this line there is no water, do not check the time only to check a whole line, this is to ask 100W questions, map only 5000*5000, the bottom of the line has 5,000 lattice Ah, Do you dare to search every time!

In short, search on the past, deep search King, I Naaru wow!

1#include <iostream>2#include <cstdio>3#include <cstring>4 using namespacestd;5 #definell Long Long6 Const intmaxn=5555;7 Const intgx[4]={0,0,-1,1};8 Const intgy[4]={-1,1,0,0};9 intA[MAXN][MAXN];Ten intN,M,FLAGC; One  A voidDfsintXinty) - { -     inti; thea[x][y]=2; -     if(x==n) flagc=1; -      for(i=0;i<4; i++) -         if(a[x+gx[i]][y+gy[i]]==1) DFS (x+gx[i],y+gy[i]); + } -  + voidOpenintXinty) A { at     inti,j; -     if(a[x][y]!=0)return; -a[x][y]=1; -      for(i=0;i<4; i++) -         if(a[x+gx[i]][y+gy[i]]==2) {a[x][y]=2; Break;} -     if(a[x][y]==1)return; in dfs (x, y); - } to  + intMain () - { the     CharC; *     intx,y,i; $      while(SCANF ("%d%d", &n,&m)! =EOF)Panax Notoginseng     { -Memset (A,0,sizeof(a)); the          for(i=1; i<=n;i++) +a[0][i]=2; AFlagc=0; the          for(i=0; i<m;i++) +         { -             //cout<<i<< "!" <<endl; $              Do{scanf ("%c", &c);} while(c=='\ n'|| c==' '); $             if(c!='C') -             { -scanf"%d%d",&x,&y); the                 if(c=='O') Open (x, y); -                 Else if(c=='F')Wuyi                 { theprintf"%d\n", a[x][y]==2); -                 } Wu             } -             Else About             { $printf"%d\n", FLAGC); -             } -         } -     } A     return 0; +}
View Code

Related Article

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.