Advertisement
Eather

785- Grid coloring

Apr 17th, 2011
626
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.67 KB | None | 0 0
  1.                            /*in the name of Allah */
  2. # include <list>
  3. # include <deque>
  4. # include <bitset>
  5. # include <algorithm>
  6. # include <functional>
  7. # include <numeric>
  8. # include <utility>
  9. # include <sstream>
  10. # include <iostream>
  11. # include <iomanip>
  12. # include <cstdio>
  13. # include <cmath>
  14. # include <cstdlib>
  15. # include <ctime>
  16. # include <set>
  17. # include <map>
  18. # include <cmath>
  19. # include <queue>
  20. # include <limits>
  21. # include <stack>
  22. # include <vector>
  23. # include <cstring>
  24. # include <cstdio>
  25. using namespace std;
  26.  
  27. # define MEM(array,w)   memset(array,w,sizeof array)
  28. # define ULL unsigned long long
  29. # define eps 1e-9
  30. # define SS stringstream
  31. # define PR pair<int , int>
  32. # define all(c) (c).begin(), (c).end()
  33. # define FOR(i, a, b) for (int i=a; i<b; i++)
  34. # define REP(i, a) FOR(i, 0, a)
  35. # define rive(s) reverse(s.begin(),s.end())
  36. # define OK(R,C) if(i>=0 && j>=0 && j<=C && i<=R)
  37.  
  38. # define MPSS map<string, string>
  39. # define MPIS map<int, string>
  40. # define MPSI map<string, int>
  41. # define MPII map<int, int>
  42. # define MPIC map<int,char>
  43. # define MPCI map<char, int>
  44.  
  45. # define VS vector<string>
  46. # define VI vector<int>
  47. # define VC vector<char>
  48. # define VB vector<bool>
  49. # define pb push_back
  50. # define mp make_pair
  51.  
  52.  
  53. template<class T> string toString(T n){ostringstream ost;ost<<n;ost.flush();return ost.str();}
  54.  
  55. int toInt(string s){int r=0;istringstream sin(s);sin>>r;return r;}
  56.  
  57. bool isprime(int n){if( n<2) return 0;for( int i=2; i*i<=n ; i++)if(n%i==0)return 0; return 1;return 0;}
  58.  
  59. int pel(string s){string t;t=s;reverse(t.begin(),t.end());if(s==t)return 1;return 0;}
  60.  
  61. int row,col;
  62. char maze[40][90];
  63. vector< pair<int, int> >vp;
  64. bool visited[40][90];
  65.  
  66. int dr [] = {1,-1,0,0};
  67.  
  68.  
  69. int dc [] = {0,0,1,-1};
  70.  
  71. void dfs(int i, int j, char ch)
  72. {
  73.  
  74.   if(i<0||j<0||i>vp[i].first|| j>vp[i].second||maze[i][j]=='X'||visited[i][j]==1)return;
  75.  
  76.   if(maze[i][j]==' ' || maze[i][j]==ch)
  77.     maze[i][j]=ch;
  78.   visited[i][j]=1;
  79.  
  80.   for ( int k = 0; k < 4; k++ )
  81.         dfs (i + dr [k], j + dc [k],ch);
  82. }
  83. int main()
  84. {
  85.  
  86. int test,Ctest=0;
  87.  
  88.   char s[90];
  89.   row=col=0;
  90.   MEM(visited,0);
  91.   char fin[81];
  92.   while(gets(s))
  93.   {
  94.     if(s[0]!='_'){
  95.     strcpy(maze[row],s);
  96.     col=strlen(s);
  97.     row++;
  98.     vp.push_back(mp(row,col));
  99.     }else
  100.     {
  101.       strcpy(fin,s);
  102.  
  103.   for(int i=0;i<vp.size();i++)
  104.   {
  105.    for(int j=0;j<vp[i].second;j++){
  106.    while(maze[i][j]==' ')j++;
  107.     if(maze[i][j]!=' '&&maze[i][j]!='X')
  108.     {
  109.       char ch;ch=maze[i][j];
  110.       dfs(i,j,ch);
  111.     }
  112.     }
  113.   }
  114.   for(int i=0;i<vp.size();i++){
  115.   for(int j=0;j<vp[i].second;j++)
  116.   cout<<maze[i][j];
  117.   cout<<endl;}cout<<fin<<endl; vp.clear();row=0;MEM(visited,0);}
  118. }
  119.  
  120. return 0;
  121. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement