Codeforces 525C Ilya and sticks

Source: Internet
Author: User

Test instructions: give you n lines, ask you how many of these segments can be composed of rectangles and the maximum. Each line segment can be-1,.

Problem-solving ideas: greed.

Problem Solving Code:

1 //File name:d.cpp2 //Author:darkdream3 //Created time:2015 March 27 Friday 16:05 31 seconds4 5#include <vector>6#include <list>7#include <map>8#include <Set>9#include <deque>Ten#include <stack> One#include <bitset> A#include <algorithm> -#include <functional> -#include <numeric> the#include <utility> -#include <cstdio> -#include <cmath> -#include <cstdlib> +#include <ctime> -#include <queue> + #defineLL Long Long A  at using namespacestd; - intN, M; - Charmp[2005][2005]; - BOOLvis[2005][2005]; - structnode{ -     intx, y; in node () {} -Nodeint_x,int_y) to     { +x =_x; -y =_y; the     } * }tmp; $ intlx, Ly, Rx,ry;Panax Notoginseng intXadd[] = {0,0,1,-1}; - intYadd[] = {1,-1,0,0}; theQueue<node>Qu; + voidBFsintXinty) A { the Qu.push (node (x, y)); +       intTx,ty; -        while(!qu.empty ()) $       { $TMP =Qu.front (); - Qu.pop (); -          if(MP[TMP.X][TMP.Y]! ='.') the              Continue; -          if(mp[tmp.x-1][TMP.Y] = ='.'&& mp[tmp.x][tmp.y+1] =='.'&& mp[tmp.x-1][tmp.y+1] =='*')Wuyi          { thetx = tmp.x-1; -ty = tmp.y +1;  WuMp[tx][ty] ='.'; - Qu.push (Node (tx,ty)); About             for(inti =0; I <=3; i + +) $Qu.push (Node (tx+xadd[i],ty+Yadd[i]))   ;  -          } -          if(mp[tmp.x-1][TMP.Y] = ='.'&& mp[tmp.x][tmp.y-1] =='.'&& mp[tmp.x-1][tmp.y-1] =='*') -          { Atx = tmp.x-1; +ty = tmp.y-1;  theMp[tx][ty] ='.'; - Qu.push (Node (tx,ty)); $             for(inti =0; I <=3; i + +) theQu.push (Node (tx+xadd[i],ty+Yadd[i]))   ;  the          } the          if(mp[tmp.x+1][TMP.Y] = ='.'&& mp[tmp.x][tmp.y+1] =='.'&& mp[tmp.x+1][tmp.y+1] =='*') the          { -tx = tmp.x +1; inty = tmp.y +1;  theMp[tx][ty] ='.'; the Qu.push (Node (tx,ty)); About             for(inti =0; I <=3; i + +) theQu.push (Node (tx+xadd[i],ty+Yadd[i]))   ;  the          } the          if(mp[tmp.x+1][TMP.Y] = ='.'&& mp[tmp.x][tmp.y-1] =='.'&& mp[tmp.x+1][tmp.y-1] =='*') +          { -tx = tmp.x +1; thety = tmp.y-1; BayiMp[tx][ty] ='.'; the Qu.push (Node (tx,ty)); the             for(inti =0; I <=3; i + +) -Qu.push (Node (tx+xadd[i],ty+Yadd[i]))   ;  -          } the       } the } the intMain () { thescanf"%d%d",&n,&m); -      for(inti =1; I <= N;i + +) the     { thescanf"%s", &mp[i][1]);  the     }94      for(inti =1; I <= N;i + +) the     { the          for(intj =1; J <= M;j + +) the         {98             if(Mp[i][j] = ='.') About             { - BFS (i,j);101             }102         }103     }104      for(inti =1; I <= N;i + +) thePuts (&mp[i][1]);106     return 0;107}
View Code

Codeforces 525C Ilya and sticks

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.