Topcoder SRM655 DIV2 250 BichromeBoard 水

题意:给你一个网格图 ,每个网格中是W,B,两种颜色和 ? 表示未知,相同颜色的网格不能相邻,问你能否满足条件

解题思路:W和B的位置 和 (i+j) 的奇偶有关。

解题代码:

  1 // BEGIN CUT HERE
  2 /*
  3
  4 */
  5 // END CUT HERE
  6 #line 7 "BichromeBoard.cpp"
  7 #include <cstdlib>
  8 #include <cctype>
  9 #include <cstring>
 10 #include <cstdio>
 11 #include <cmath>
 12 #include <algorithm>
 13 #include <vector>
 14 #include <string>
 15 #include <iostream>
 16 #include <sstream>
 17 #include <map>
 18 #include <set>
 19 #include <queue>
 20 #include <stack>
 21 #include <fstream>
 22 #include <numeric>
 23 #include <iomanip>
 24 #include <bitset>
 25 #include <list>
 26 #include <stdexcept>
 27 #include <functional>
 28 #include <utility>
 29 #include <ctime>
 30 using namespace std;
 31
 32 #define PB push_back
 33 #define MP make_pair
 34
 35 #define REP(i,n) for(i=0;i<(n);++i)
 36 #define FOR(i,l,h) for(i=(l);i<=(h);++i)
 37 #define FORD(i,h,l) for(i=(h);i>=(l);--i)
 38
 39 typedef vector<int> VI;
 40 typedef vector<string> VS;
 41 typedef vector<double> VD;
 42 typedef long long LL;
 43 typedef pair<int,int> PII;
 44
 45 int ok = 0 ;
 46
 47 class BichromeBoard
 48 {
 49         public:
 50         string ableToDraw(vector <string> str)
 51         {
 52             int n = str.size();
 53             int m = str[0].size();
 54             int st = 0 ;
 55             int ok = 1 ;
 56             for(int i = 0 ;i < n ; i ++)
 57                 for(int j = 0 ;j < m;j ++)
 58                 {
 59                     if(str[i][j] != ‘?‘){
 60                         if(str[i][j] == ‘B‘)
 61                         {
 62                            st = (i + j) % 2;
 63                            for(int i = 0;i < n;i ++)
 64                            {
 65                               for(int j = 0 ;j < m;j ++)
 66                               {
 67                                 if(str[i][j] == ‘W‘  && (i + j) % 2 == st)
 68                                     ok = 0 ;
 69                                 if(str[i][j] == ‘B‘  && (i + j) % 2 != st)
 70                                     ok = 0  ;
 71                               }
 72                            }
 73                         }else{
 74                            st = (i + j) % 2;
 75                            for(int i = 0;i < n;i ++)
 76                            {
 77                               for(int j = 0 ;j < m;j ++)
 78                               {
 79                                 if(str[i][j] == ‘B‘  && (i + j) % 2 == st)
 80                                     ok = 0 ;
 81                                 if(str[i][j] == ‘W‘  && (i + j) % 2 != st)
 82                                     ok = 0 ;
 83                               }
 84                            }
 85                         }
 86                         break;
 87                     }
 88                 }
 89             if(ok)
 90                 return "Possible";
 91             else return "Impossible";
 92         }
 93
 94 // BEGIN CUT HERE
 95     public:
 96     void run_test(int Case) { if ((Case == -1) || (Case == 0)) test_case_0(); if ((Case == -1) || (Case == 1)) test_case_1(); if ((Case == -1) || (Case == 2)) test_case_2(); if ((Case == -1) || (Case == 3)) test_case_3(); if ((Case == -1) || (Case == 4)) test_case_4(); if ((Case == -1) || (Case == 5)) test_case_5(); }
 97     private:
 98     template <typename T> string print_array(const vector<T> &V) { ostringstream os; os << "{ "; for (typename vector<T>::const_iterator iter = V.begin(); iter != V.end(); ++iter) os << ‘\"‘ << *iter << "\","; os << " }"; return os.str(); }
 99     void verify_case(int Case, const string &Expected, const string &Received) { cerr << "Test Case #" << Case << "..."; if (Expected == Received) cerr << "PASSED" << endl; else { cerr << "FAILED" << endl; cerr << "\tExpected: \"" << Expected << ‘\"‘ << endl; cerr << "\tReceived: \"" << Received << ‘\"‘ << endl; } }
100     void test_case_0() { string Arr0[] = {"W?W",
101  "??B",
102  "???"}; vector <string> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[0]))); string Arg1 = "Possible"; verify_case(0, Arg1, ableToDraw(Arg0)); }
103     void test_case_1() { string Arr0[] = {"W??W"}; vector <string> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[0]))); string Arg1 = "Impossible"; verify_case(1, Arg1, ableToDraw(Arg0)); }
104     void test_case_2() { string Arr0[] = {"??"}; vector <string> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[0]))); string Arg1 = "Possible"; verify_case(2, Arg1, ableToDraw(Arg0)); }
105     void test_case_3() { string Arr0[] = {"W???",
106  "??B?",
107  "W???",
108  "???W"}; vector <string> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[0]))); string Arg1 = "Possible"; verify_case(3, Arg1, ableToDraw(Arg0)); }
109     void test_case_4() { string Arr0[] = {"W???",
110  "??B?",
111  "W???",
112  "?B?W"}; vector <string> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[0]))); string Arg1 = "Impossible"; verify_case(4, Arg1, ableToDraw(Arg0)); }
113     void test_case_5() { string Arr0[] = {"B"}; vector <string> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[0]))); string Arg1 = "Possible"; verify_case(5, Arg1, ableToDraw(Arg0)); }
114
115 // END CUT HERE
116
117 };
118
119 // BEGIN CUT HERE
120 int main()
121 {
122         BichromeBoard ___test;
123         ___test.run_test(-1);
124         return 0;
125 }
126 // END CUT HERE

时间: 2024-11-10 19:48:32

Topcoder SRM655 DIV2 250 BichromeBoard 水的相关文章

Topcoder SRM655 DIV2 950 NineEasy 状压 + 数位 dp

题意:要你构造一个n位的数子 ,给你m(1-5)个询问,每一次询问取一些位数的数组成一个新数且这个数 %9 ==  0 , 问你要满足这m个询问的数字有多少个(允许前缀0). 解题思路:把每一种情况状压,得到一个最多  9x9x9x9x9 的情况,然后根据 每个数的询问决定状态转移方程. 解题代码: 1 // BEGIN CUT HERE 2 /* 3 4 */ 5 // END CUT HERE 6 #line 7 "NineEasy.cpp" 7 #include <cstd

topcoder srm 628 div2 250 500

做了一道题,对了,但是还是掉分了. 第二道题也做了,但是没有交上,不知道对错. 后来交上以后发现少判断了一个条件,改过之后就对了. 第一道题爆搜的,有点麻烦了,其实几行代码就行. 250贴代码: 1 #include <iostream> 2 #include <cstring> 3 #include <queue> 4 #include <cmath> 5 #include <cstdio> 6 #include <algorithm&g

topcoder SRM628 div2 500(转)

Problem Statement      We have three types of brackets: "()", "[]", and "{}". We are now interested in some special strings. A string is special if all the following conditions hold: Each character of the string is one of the

Topcoder SRM632 DIV2 解题报告

250:乱搞 解题代码: 1 // BEGIN CUT HERE 2 /* 3 4 */ 5 // END CUT HERE 6 #line 7 "RunningAroundPark.cpp" 7 #include <cstdlib> 8 #include <cctype> 9 #include <cstring> 10 #include <cstdio> 11 #include <cmath> 12 #include <

[Topcoder]SRM632 div2 题解

TC第一次解出三题--当了次room leader-- 感觉这次的题比较弱,代码量也很小,都是在拼手速了 250 RunningAroundPark 题意很好懂,一圈跑道上有N棵树,现给你遇到这些树的顺序,问最少需要多少走圈才能遇到相应的序列 直接判断a[i]<=a[i+1]即可 首先假定走了一圈 #include <cstdlib> #include <cctype> #include <cstring> #include <cstdio> #inc

Topcoder SRM631 DIV2 解题报告

250:网格有两种颜色,网格中一列最长的连续的颜色相同的最大值. 解题思路:暴力. 解题代码: // BEGIN CUT HERE /* */ // END CUT HERE #line 7 "TaroGrid.cpp" #include <cstdlib> #include <cctype> #include <cstring> #include <cstdio> #include <cmath> #include <

Topcoder SRM633 DIV2 解题报告

250:乱搞. 1 // BEGIN CUT HERE 2 /* 3 4 */ 5 // END CUT HERE 6 #line 7 "Target.cpp" 7 #include <cstdlib> 8 #include <cctype> 9 #include <cstring> 10 #include <cstdio> 11 #include <cmath> 12 #include <algorithm> 1

TopCoder SRM500 Div1 250 其他

原文链接https://www.cnblogs.com/zhouzhendong/p/SRM500-250.html SRM500 Div1 250 题意 (看题用了半个小时--) 有 n 个人(编号从 0 到 n-1)玩游戏,要通过投票的方式确定谁输.现在已知有一些人有明确的意见,认为谁输.具体地用一个 vector decision 来描述,vector decision 的大小可能不足 n . 定义一个集合 S 包含一些人,初始的时候集合 S 包含所有人.他们会进行若干轮投票,每一轮中,一

topcoder 649 DIV2

8 A:模拟 9:B:终于看懂题目... 题意:最多分解K次 每分钟一个数可以分解成两个数 或者-1: 关键字:DP,记忆花搜索. DP[I][J]=min(dp[i][j],1+max(dp[ii][jj],dp[i-ii][j-jj-1]); 1 #include<iostream> 2 #include <string>  3 #include <vector>  4 #include<cmath>  5 #include <string.h&g