TC SRM 588
这套题做的挺顺的……
250pt:
给N首歌,每首歌需要一定的时间演唱,两首歌之间会花音高差的时间进行调整,问在给定时间内最多能唱多少首歌。
首先唱歌的顺序最优方案的音高肯定是单调的,所以排序之后直接DP就行了。
1 #include <vector>
2 #include <list>
3 #include <map>
4 #include <set>
5 #include <queue>
6 #include <deque>
7 #include <stack>
8 #include <bitset>
9 #include <algorithm>
10 #include <functional>
11 #include <numeric>
12 #include <utility>
13 #include <sstream>
14 #include <iostream>
15 #include <iomanip>
16 #include <cstdio>
17 #include <cmath>
18 #include <cstdlib>
19 #include <ctime>
20 #include<cstring>
21
22 using namespace std;
23
24 int f[100][100];
25
26 struct rec
27 {
28 int d,t;
29 rec(){}
30 rec(int a,int b)
31 {
32 d=a;t=b;
33 }
34 bool operator<(const rec &a)const
35 {
36 return t<a.t;
37 }
38 }z[100];
39
40 class GUMIAndSongsDiv1 {
41 public:
42 int maxSongs(vector <int> duration, vector <int> tone, int T) {
43 int n=duration.size();
44 for (int a=0;a<n;a++)
45 z[a]=rec(duration[a],tone[a]);
46 sort(z,z+n);
47 memset(f,0x3f,sizeof(f));
48 f[0][0]=0;
49 f[0][1]=z[0].d;
50 for (int a=1;a<n;a++)
51 for (int b=0;b<=a+1;b++)
52 if (!b) f[a][b]=0;
53 else
54 {
55 for (int c=0;c<a;c++)
56 f[a][b]=min(f[a][b],f[c][b-1]+z[a].d+(b==1 ? 0 : z[a].t-z[c].t));
57 }
58 int ans=0;
59 for (int a=0;a<n;a++)
60 for (int b=1;b<=n;b++)
61 if (f[a][b]<=T) ans=max(ans,b);
62 return ans;
63
64 }
65 };
66
67
68 //<%:testing-code%>
69 //Powered by KawigiEdit 2.1.4 (beta) modified by pivanof!
70 // BEGIN KAWIGIEDIT TESTING
71 // Generated by KawigiEdit 2.1.4 (beta) modified by pivanof
72 bool KawigiEdit_RunTest(int testNum, vector <int> p0, vector <int> p1, int p2, bool hasAnswer, int p3) {
73 cout << "Test " << testNum << ": [" << "{";
74 for (int i = 0; int(p0.size()) > i; ++i) {
75 if (i > 0) {
76 cout << ",";
77 }
78 cout << p0[i];
79 }
80 cout << "}" << "," << "{";
81 for (int i = 0; int(p1.size()) > i; ++i) {
82 if (i > 0) {
83 cout << ",";
84 }
85 cout << p1[i];
86 }
87 cout << "}" << "," << p2;
88 cout << "]" << endl;
89 GUMIAndSongsDiv1 *obj;
90 int answer;
91 obj = new GUMIAndSongsDiv1();
92 clock_t startTime = clock();
93 answer = obj->maxSongs(p0, p1, p2);
94 clock_t endTime = clock();
95 delete obj;
96 bool res;
97 res = true;
98 cout << "Time: " << double(endTime - startTime) / CLOCKS_PER_SEC << " seconds" << endl;
99 if (hasAnswer) {
100 cout << "Desired answer:" << endl;
101 cout << "\t" << p3 << endl;
102 }
103 cout << "Your answer:" << endl;
104 cout << "\t" << answer << endl;
105 if (hasAnswer) {
106 res = answer == p3;
107 }
108 if (!res) {
109 cout << "DOESN'T MATCH!!!!" << endl;
110 } else if (double(endTime - startTime) / CLOCKS_PER_SEC >= 2) {
111 cout << "FAIL the timeout" << endl;
112 res = false;
113 } else if (hasAnswer) {
114 cout << "Match :-)" << endl;
115 } else {
116 cout << "OK, but is it right?" << endl;
117 }
118 cout << "" << endl;
119 return res;
120 }
121 int main() {
122 bool all_right;
123 all_right = true;
124
125 vector <int> p0;
126 vector <int> p1;
127 int p2;
128 int p3;
129
130 {
131 // ----- test 0 -----
132 int t0[] = {3,5,4,11};
133 p0.assign(t0, t0 + sizeof(t0) / sizeof(t0[0]));
134 int t1[] = {2,1,3,1};
135 p1.assign(t1, t1 + sizeof(t1) / sizeof(t1[0]));
136 p2 = 17;
137 p3 = 3;
138 all_right = KawigiEdit_RunTest(0, p0, p1, p2, true, p3) && all_right;
139 // ------------------
140 }
141
142 {
143 // ----- test 1 -----
144 int t0[] = {100,200,300};
145 p0.assign(t0, t0 + sizeof(t0) / sizeof(t0[0]));
146 int t1[] = {1,2,3};
147 p1.assign(t1, t1 + sizeof(t1) / sizeof(t1[0]));
148 p2 = 99;
149 p3 = 0;
150 all_right = KawigiEdit_RunTest(1, p0, p1, p2, true, p3) && all_right;
151 // ------------------
152 }
153
154 {
155 // ----- test 2 -----
156 int t0[] = {1,2,3,4};
157 p0.assign(t0, t0 + sizeof(t0) / sizeof(t0[0]));
158 int t1[] = {1,1,1,1};
159 p1.assign(t1, t1 + sizeof(t1) / sizeof(t1[0]));
160 p2 = 100;
161 p3 = 4;
162 all_right = KawigiEdit_RunTest(2, p0, p1, p2, true, p3) && all_right;
163 // ------------------
164 }
165
166 {
167 // ----- test 3 -----
168 int t0[] = {9,11,13,17};
169 p0.assign(t0, t0 + sizeof(t0) / sizeof(t0[0]));
170 int t1[] = {2,1,3,4};
171 p1.assign(t1, t1 + sizeof(t1) / sizeof(t1[0]));
172 p2 = 20;
173 p3 = 1;
174 all_right = KawigiEdit_RunTest(3, p0, p1, p2, true, p3) && all_right;
175 // ------------------
176 }
177
178 {
179 // ----- test 4 -----
180 int t0[] = {87,21,20,73,97,57,12,80,86,97,98,85,41,12,89,15,41,17,68,37,21,1,9,65,4,67,38,91,46,82,7,98,21,70,99,41,21,65,11,1,8,12,77,62,52,69,56,33,98,97};
181 p0.assign(t0, t0 + sizeof(t0) / sizeof(t0[0]));
182 int t1[] = {88,27,89,2,96,32,4,93,89,50,58,70,15,48,31,2,27,20,31,3,23,86,69,12,59,61,85,67,77,34,29,3,75,42,50,37,56,45,51,68,89,17,4,47,9,14,29,59,43,3};
183 p1.assign(t1, t1 + sizeof(t1) / sizeof(t1[0]));
184 p2 = 212;
185 p3 = 12;
186 all_right = KawigiEdit_RunTest(4, p0, p1, p2, true, p3) && all_right;
187 // ------------------
188 }
189
190 if (all_right) {
191 cout << "You're a stud (at least on the example cases)!" << endl;
192 } else {
193 cout << "Some of the test cases had errors." << endl;
194 }
195 return 0;
196 }
197 // END KAWIGIEDIT TESTING
450pt:
红绿白三种颜色的钥匙,白色钥匙可以随意变成红色或者绿色,开每扇门会消耗掉一定的红色或者绿色钥匙,然后又会得到一定的钥匙数,问能得到的最多的钥匙总数是多少。
首先因为门的数量不多所以直接状压,并且我们发现如果没有白钥匙是很好做的,所以我们第二维记录将多少白色钥匙变为红色钥匙,这样可以就将白色钥匙的影响成功消除掉,然后每次枚举下一个选哪扇门并且如何分配白钥匙即可。
1 #include <vector>
2 #include <list>
3 #include <map>
4 #include <set>
5 #include <queue>
6 #include <deque>
7 #include <stack>
8 #include <bitset>
9 #include <algorithm>
10 #include <functional>
11 #include <numeric>
12 #include <utility>
13 #include <sstream>
14 #include <iostream>
15 #include <iomanip>
16 #include <cstdio>
17 #include <cmath>
18 #include <cstdlib>
19 #include <ctime>
20 #include<cstring>
21
22 using namespace std;
23
24 int sum[1<<13][3];
25
26 bool f[1<<13][200];
27
28 class KeyDungeonDiv1 {
29 public:
30 int maxKeys(vector <int> doorR, vector <int> doorG, vector <int> roomR, vector <int> roomG, vector <int> roomW, vector <int> keys) {
31 int n=doorR.size();
32 int sumw=keys[2];
33 for (int a=0;a<n;a++)
34 sumw+=roomW[a];
35 for (int a=0;a<(1<<n);a++)
36 {
37 for (int b=0;b<3;b++)
38 sum[a][b]=keys[b];
39 for (int b=0;b<n;b++)
40 if (a&(1<<b)) sum[a][0]+=roomR[b]-doorR[b],sum[a][1]+=roomG[b]-doorG[b],sum[a][2]+=roomW[b];
41 }
42 memset(f,false,sizeof(f));
43 for (int a=0;a<=keys[2];a++)
44 f[0][a]=true;
45 for (int a=0;a<(1<<n)-1;a++)
46 for (int b=0;b<=sumw;b++)
47 if (f[a][b])
48 {
49 int r=sum[a][0]+b,g=sum[a][1]+sum[a][2]-b;
50 for (int c=0;c<n;c++)
51 if (!((a>>c)&1) && r>=doorR[c] && g>=doorG[c])
52 {
53 for (int d=0;d<=roomW[c];d++)
54 f[a|(1<<c)][b+d]=true;
55 }
56 }
57 int ans=0;
58 for (int a=0;a<(1<<n);a++)
59 {
60 bool exist=false;
61 for (int b=0;b<=sumw;b++)
62 if (f[a][b])
63 {
64 exist=true;
65 break;
66 }
67 if (exist) ans=max(ans,sum[a][0]+sum[a][1]+sum[a][2]);
68 }
69 return ans;
70 }
71 };
72
73
74 //<%:testing-code%>
75 //Powered by KawigiEdit 2.1.4 (beta) modified by pivanof!
76 // BEGIN KAWIGIEDIT TESTING
77 // Generated by KawigiEdit 2.1.4 (beta) modified by pivanof
78 bool KawigiEdit_RunTest(int testNum, vector <int> p0, vector <int> p1, vector <int> p2, vector <int> p3, vector <int> p4, vector <int> p5, bool hasAnswer, int p6) {
79 cout << "Test " << testNum << ": [" << "{";
80 for (int i = 0; int(p0.size()) > i; ++i) {
81 if (i > 0) {
82 cout << ",";
83 }
84 cout << p0[i];
85 }
86 cout << "}" << "," << "{";
87 for (int i = 0; int(p1.size()) > i; ++i) {
88 if (i > 0) {
89 cout << ",";
90 }
91 cout << p1[i];
92 }
93 cout << "}" << "," << "{";
94 for (int i = 0; int(p2.size()) > i; ++i) {
95 if (i > 0) {
96 cout << ",";
97 }
98 cout << p2[i];
99 }
100 cout << "}" << "," << "{";
101 for (int i = 0; int(p3.size()) > i; ++i) {
102 if (i > 0) {
103 cout << ",";
104 }
105 cout << p3[i];
106 }
107 cout << "}" << "," << "{";
108 for (int i = 0; int(p4.size()) > i; ++i) {
109 if (i > 0) {
110 cout << ",";
111 }
112 cout << p4[i];
113 }
114 cout << "}" << "," << "{";
115 for (int i = 0; int(p5.size()) > i; ++i) {
116 if (i > 0) {
117 cout << ",";
118 }
119 cout << p5[i];
120 }
121 cout << "}";
122 cout << "]" << endl;
123 KeyDungeonDiv1 *obj;
124 int answer;
125 obj = new KeyDungeonDiv1();
126 clock_t startTime = clock();
127 answer = obj->maxKeys(p0, p1, p2, p3, p4, p5);
128 clock_t endTime = clock();
129 delete obj;
130 bool res;
131 res = true;
132 cout << "Time: " << double(endTime - startTime) / CLOCKS_PER_SEC << " seconds" << endl;
133 if (hasAnswer) {
134 cout << "Desired answer:" << endl;
135 cout << "\t" << p6 << endl;
136 }
137 cout << "Your answer:" << endl;
138 cout << "\t" << answer << endl;
139 if (hasAnswer) {
140 res = answer == p6;
141 }
142 if (!res) {
143 cout << "DOESN'T MATCH!!!!" << endl;
144 } else if (double(endTime - startTime) / CLOCKS_PER_SEC >= 2) {
145 cout << "FAIL the timeout" << endl;
146 res = false;
147 } else if (hasAnswer) {
148 cout << "Match :-)" << endl;
149 } else {
150 cout << "OK, but is it right?" << endl;
151 }
152 cout << "" << endl;
153 return res;
154 }
155 int main() {
156 bool all_right;
157 all_right = true;
158
159 vector <int> p0;
160 vector <int> p1;
161 vector <int> p2;
162 vector <int> p3;
163 vector <int> p4;
164 vector <int> p5;
165 int p6;
166
167 {
168 // ----- test 0 -----
169 int t0[] = {1,2,3};
170 p0.assign(t0, t0 + sizeof(t0) / sizeof(t0[0]));
171 int t1[] = {0,4,9};
172 p1.assign(t1, t1 + sizeof(t1) / sizeof(t1[0]));
173 int t2[] = {0,0,10};
174 p2.assign(t2, t2 + sizeof(t2) / sizeof(t2[0]));
175 int t3[] = {0,8,9};
176 p3.assign(t3, t3 + sizeof(t3) / sizeof(t3[0]));
177 int t4[] = {1,0,8};
178 p4.assign(t4, t4 + sizeof(t4) / sizeof(t4[0]));
179 int t5[] = {3,1,2};
180 p5.assign(t5, t5 + sizeof(t5) / sizeof(t5[0]));
181 p6 = 8;
182 all_right = KawigiEdit_RunTest(0, p0, p1, p2, p3, p4, p5, true, p6) && all_right;
183 // ------------------
184 }
185
186 {
187 // ----- test 1 -----
188 int t0[] = {1,1,1,2};
189 p0.assign(t0, t0 + sizeof(t0) / sizeof(t0[0]));
190 int t1[] = {0,2,3,1};
191 p1.assign(t1, t1 + sizeof(t1) / sizeof(t1[0]));
192 int t2[] = {2,1,0,4};
193 p2.assign(t2, t2 + sizeof(t2) / sizeof(t2[0]));
194 int t3[] = {1,3,3,1};
195 p3.assign(t3, t3 + sizeof(t3) / sizeof(t3[0]));
196 int t4[] = {1,0,2,1};
197 p4.assign(t4, t4 + sizeof(t4) / sizeof(t4[0]));
198 int t5[] = {0,4,0};
199 p5.assign(t5, t5 + sizeof(t5) / sizeof(t5[0]));
200 p6 = 4;
201 all_right = KawigiEdit_RunTest(1, p0, p1, p2, p3, p4, p5, true, p6) && all_right;
202 // ------------------
203 }
204
205 {
206 // ----- test 2 -----
207 int t0[] = {2,0,4};
208 p0.assign(t0, t0 + sizeof(t0) / sizeof(t0[0]));
209 int t1[] = {3,0,4};
210 p1.assign(t1, t1 + sizeof(t1) / sizeof(t1[0]));
211 int t2[] = {0,0,9};
212 p2.assign(t2, t2 + sizeof(t2) / sizeof(t2[0]));
213 int t3[] = {0,0,9};
214 p3.assign(t3, t3 + sizeof(t3) / sizeof(t3[0]));
215 int t4[] = {8,5,9};
216 p4.assign(t4, t4 + sizeof(t4) / sizeof(t4[0]));
217 int t5[] = {0,0,0};
218 p5.assign(t5, t5 + sizeof(t5) / sizeof(t5[0]));
219 p6 = 27;
220 all_right = KawigiEdit_RunTest(2, p0, p1, p2, p3, p4, p5, true, p6) && all_right;
221 // ------------------
222 }
223
224 {
225 // ----- test 3 -----
226 int t0[] = {5,3,0,0};
227 p0.assign(t0, t0 + sizeof(t0) / sizeof(t0[0]));
228 int t1[] = {0,1,2,1};
229 p1.assign(t1, t1 + sizeof(t1) / sizeof(t1[0]));
230 int t2[] = {0,9,2,4};
231 p2.assign(t2, t2 + sizeof(t2) / sizeof(t2[0]));
232 int t3[] = {2,9,2,0};
233 p3.assign(t3, t3 + sizeof(t3) / sizeof(t3[0]));
234 int t4[] = {0,9,1,1};
235 p4.assign(t4, t4 + sizeof(t4) / sizeof(t4[0]));
236 int t5[] = {1,1,0};
237 p5.assign(t5, t5 + sizeof(t5) / sizeof(t5[0]));
238 p6 = 32;
239 all_right = KawigiEdit_RunTest(3, p0, p1, p2, p3, p4, p5, true, p6) && all_right;
240 // ------------------
241 }
242
243 {
244 // ----- test 4 -----
245 int t0[] = {9,5,10,8,4,3,0,8,4,1,3,9};
246 p0.assign(t0, t0 + sizeof(t0) / sizeof(t0[0]));
247 int t1[] = {9,10,0,8,9,4,3,8,1,8,10,4};
248 p1.assign(t1, t1 + sizeof(t1) / sizeof(t1[0]));
249 int t2[] = {1,2,0,2,3,3,5,3,1,3,0,5};
250 p2.assign(t2, t2 + sizeof(t2) / sizeof(t2[0]));
251 int t3[] = {5,2,5,0,5,2,3,4,0,0,5,2};
252 p3.assign(t3, t3 + sizeof(t3) / sizeof(t3[0]));
253 int t4[] = {1,5,1,2,0,4,4,0,3,3,1,3};
254 p4.assign(t4, t4 + sizeof(t4) / sizeof(t4[0]));
255 int t5[] = {5,0,1};
256 p5.assign(t5, t5 + sizeof(t5) / sizeof(t5[0]));
257 p6 = 16;
258 all_right = KawigiEdit_RunTest(4, p0, p1, p2, p3, p4, p5, true, p6) && all_right;
259 // ------------------
260 }
261
262 {
263 // ----- test 5 -----
264 int t0[] = {8, 4, 3, 6, 1, 8, 0, 3, 6, 2, 1, 5};
265 p0.assign(t0, t0 + sizeof(t0) / sizeof(t0[0]));
266 int t1[] = {1, 7, 5, 9, 0, 3, 9, 1, 9, 3, 0, 8};
267 p1.assign(t1, t1 + sizeof(t1) / sizeof(t1[0]));
268 int t2[] = {2, 1, 2, 1, 0, 2, 2, 3, 3, 0, 2, 0};
269 p2.assign(t2, t2 + sizeof(t2) / sizeof(t2[0]));
270 int t3[] ={0, 2, 1, 0, 3, 2, 2, 2, 3, 0, 2, 0};
271 p3.assign(t3, t3 + sizeof(t3) / sizeof(t3[0]));
272 int t4[] = {2, 0, 1, 3, 1, 3, 3, 2, 0, 1, 0, 1};
273 p4.assign(t4, t4 + sizeof(t4) / sizeof(t4[0]));
274 int t5[] = {1, 3, 0};
275 p5.assign(t5, t5 + sizeof(t5) / sizeof(t5[0]));
276 p6 = 11;
277 all_right = KawigiEdit_RunTest(4, p0, p1, p2, p3, p4, p5, true, p6) && all_right;
278 // ------------------
279 }
280
281 {
282 // ----- test 6 -----
283 int t0[] = {6, 7, 7, 5, 5, 6, 9, 7, 4, 8, 7, 9};
284 p0.assign(t0, t0 + sizeof(t0) / sizeof(t0[0]));
285 int t1[] = {5, 4, 3, 2, 4, 4, 3, 2, 3, 3, 5, 2};
286 p1.assign(t1, t1 + sizeof(t1) / sizeof(t1[0]));
287 int t2[] = {4, 5, 5, 3, 2, 6, 4, 3, 6, 3, 2, 6};
288 p2.assign(t2, t2 + sizeof(t2) / sizeof(t2[0]));
289 int t3[] ={10, 10, 7, 7, 10, 7, 10, 8, 9, 5, 8, 10};
290 p3.assign(t3, t3 + sizeof(t3) / sizeof(t3[0]));
291 int t4[] ={1, 1, 1, 2, 1, 2, 1, 2, 2, 2, 1, 2};
292 p4.assign(t4, t4 + sizeof(t4) / sizeof(t4[0]));
293 int t5[] ={3, 1, 7};
294 p5.assign(t5, t5 + sizeof(t5) / sizeof(t5[0]));
295 p6 = 61;
296 all_right = KawigiEdit_RunTest(4, p0, p1, p2, p3, p4, p5, true, p6) && all_right;
297 // ------------------
298 }
299
300 if (all_right) {
301 cout << "You're a stud (at least on the example cases)!" << endl;
302 } else {
303 cout << "Some of the test cases had errors." << endl;
304 }
305 return 0;
306 }
307 // END KAWIGIEDIT TESTING
1100pt:
两个人在一棵树上玩游戏,轮流动。如果两人处在同一个位置,第一个人赢,如果一定回合之后第一个人没赢那么就算第二个人赢。第一个人会在游戏开始前确定他每一步的移动,并且第二个人会根据他的移动来做出相应的策略,问谁胜。
分情况讨论证明证明什么的……证明和结论都好复杂的样子……看TC上的题解吧……
1 #include <vector>
2 #include <list>
3 #include <set>
4 #include <queue>
5 #include <deque>
6 #include <stack>
7 #include <bitset>
8 #include <algorithm>
9 #include <functional>
10 #include <numeric>
11 #include <utility>
12 #include <sstream>
13 #include <iostream>
14 #include <iomanip>
15 #include <cstdio>
16 #include <cmath>
17 #include <cstdlib>
18 #include <ctime>
19 #include<cstring>
20
21 using namespace std;
22
23 char map[100][100];
24
25 int dist[2][100][100],bx[5],by[5];
26
27 void calc(int x,int y,int z,int d,int prex,int prey)
28 {
29 if (map[x][y]=='#') return;
30 dist[z][x][y]=d;
31 for (int a=1;a<=4;a++)
32 {
33 int xx=x+bx[a];
34 int yy=y+by[a];
35 if (xx!=prex || yy!=prey) calc(xx,yy,z,d+1,x,y);
36 }
37 }
38
39 int calc(int x,int y,int prex,int prey)
40 {
41 if (map[x][y]=='#') return 0;
42 int d=0;
43 for (int a=1;a<=4;a++)
44 {
45 int xx=x+bx[a];
46 int yy=y+by[a];
47 if (xx!=prex || yy!=prey) d=max(d,calc(xx,yy,x,y));
48 }
49 return d+1;
50 }
51
52 class GameInDarknessDiv1 {
53 public:
54 string check(vector <string> field) {
55 bx[1]=1;bx[2]=-1;by[3]=1;by[4]=-1;
56 int n=field.size();
57 int m=field[0].size();
58 for (int a=0;a<n;a++)
59 for (int b=0;b<m;b++)
60 map[a+1][b+1]=field[a][b];
61 for (int a=0;a<=n+1;a++)
62 map[a][0]=map[a][m+1]='#';
63 for (int a=0;a<=m+1;a++)
64 map[0][a]=map[n+1][a]='#';
65 memset(dist,0,sizeof(dist));
66 for (int a=1;a<=n;a++)
67 for (int b=1;b<=m;b++)
68 if (map[a][b]=='A') calc(a,b,0,0,-1,-1);
69 else
70 {
71 if (map[a][b]=='B') calc(a,b,1,0,-1,-1);
72 }
73 for (int a=1;a<=n;a++)
74 for (int b=1;b<=m;b++)
75 if (dist[0][a][b]-dist[1][a][b]>=2)
76 {
77 int cnt=0;
78 for (int c=1;c<=4;c++)
79 cnt+=(calc(a+bx[c],b+by[c],a,b)>=3);
80 if (cnt>=3) return "Bob wins";
81 }
82 return "Alice wins";
83
84 }
85 };
86
87
88 //<%:testing-code%>
89 //Powered by KawigiEdit 2.1.4 (beta) modified by pivanof!
90 // BEGIN KAWIGIEDIT TESTING
91 // Generated by KawigiEdit 2.1.4 (beta) modified by pivanof
92 bool KawigiEdit_RunTest(int testNum, vector <string> p0, bool hasAnswer, string p1) {
93 cout << "Test " << testNum << ": [" << "{";
94 for (int i = 0; int(p0.size()) > i; ++i) {
95 if (i > 0) {
96 cout << ",";
97 }
98 cout << "\"" << p0[i] << "\"";
99 }
100 cout << "}";
101 cout << "]" << endl;
102 GameInDarknessDiv1 *obj;
103 string answer;
104 obj = new GameInDarknessDiv1();
105 clock_t startTime = clock();
106 answer = obj->check(p0);
107 clock_t endTime = clock();
108 delete obj;
109 bool res;
110 res = true;
111 cout << "Time: " << double(endTime - startTime) / CLOCKS_PER_SEC << " seconds" << endl;
112 if (hasAnswer) {
113 cout << "Desired answer:" << endl;
114 cout << "\t" << "\"" << p1 << "\"" << endl;
115 }
116 cout << "Your answer:" << endl;
117 cout << "\t" << "\"" << answer << "\"" << endl;
118 if (hasAnswer) {
119 res = answer == p1;
120 }
121 if (!res) {
122 cout << "DOESN'T MATCH!!!!" << endl;
123 } else if (double(endTime - startTime) / CLOCKS_PER_SEC >= 2) {
124 cout << "FAIL the timeout" << endl;
125 res = false;
126 } else if (hasAnswer) {
127 cout << "Match :-)" << endl;
128 } else {
129 cout << "OK, but is it right?" << endl;
130 }
131 cout << "" << endl;
132 return res;
133 }
134 int main() {
135 bool all_right;
136 all_right = true;
137
138 vector <string> p0;
139 string p1;
140
141 {
142 // ----- test 0 -----
143 string t0[] = {"A.B..","##.##","##.##"};
144 p0.assign(t0, t0 + sizeof(t0) / sizeof(t0[0]));
145 p1 = "Alice wins";
146 all_right = KawigiEdit_RunTest(0, p0, true, p1) && all_right;
147 // ------------------
148 }
149
150 {
151 // ----- test 1 -----
152 string t0[] = {"A.B..",".#.#.","#..##"};
153 p0.assign(t0, t0 + sizeof(t0) / sizeof(t0[0]));
154 p1 = "Bob wins";
155 all_right = KawigiEdit_RunTest(1, p0, true, p1) && all_right;
156 // ------------------
157 }
158
159 {
160 // ----- test 2 -----
161 string t0[] = {"#...#",".#A#.","..B..",".#.#.","#...#"};
162 p0.assign(t0, t0 + sizeof(t0) / sizeof(t0[0]));
163 p1 = "Alice wins";
164 all_right = KawigiEdit_RunTest(2, p0, true, p1) && all_right;
165 // ------------------
166 }
167
168 {
169 // ----- test 3 -----
170 string t0[] = {"##..#","A.#..","#B..#","#.##.","....."};
171 p0.assign(t0, t0 + sizeof(t0) / sizeof(t0[0]));
172 p1 = "Alice wins";
173 all_right = KawigiEdit_RunTest(3, p0, true, p1) && all_right;
174 // ------------------
175 }
176
177 {
178 // ----- test 4 -----
179 string t0[] = {"##################################################","###..................#................#........###","###.################.########.#######.########.###","###.################.########.#######.########.###","###.################.########.#######.########.###","###.################.########.#######.########.###","###.################.########.#######.########.###","###.################.########.#######.########.###","###.################.########.#######.########.###","###.################.########.#######.########.###","###..........#######........#.#######........#.###","############.#######.########.#######.########.###","############.#######.########.#######.########.###","############.#######.########.#######.########.###","############.#######.########.#######.########.###","############.#######.########.#######.########.###","############.#######.########.#######.########.###","############.#######.########.#######.########.###","############.#######.########.#######.########"
180 ".###","###B.........#######..........#######..A.......###","##################################################"};
181 p0.assign(t0, t0 + sizeof(t0) / sizeof(t0[0]));
182 p1 = "Bob wins";
183 all_right = KawigiEdit_RunTest(4, p0, true, p1) && all_right;
184 // ------------------
185 }
186
187 {
188 // ----- test 5 -----
189 string t0[] = {"###.#","###..","A..B#","###..","###.#"};
190 p0.assign(t0, t0 + sizeof(t0) / sizeof(t0[0]));
191 p1 = "Alice wins";
192 all_right = KawigiEdit_RunTest(5, p0, true, p1) && all_right;
193 // ------------------
194 }
195
196 {
197 // ----- test 6 -----
198 string t0[] = {".....#.##.##.#.#",".###.#.##.##....","#......B#...#.#.","#.#A#.#.#.#..##.","...#..#....#...."};
199 p0.assign(t0, t0 + sizeof(t0) / sizeof(t0[0]));
200 p1 = "Alice wins";
201 all_right = KawigiEdit_RunTest(6, p0, true, p1) && all_right;
202 // ------------------
203 }
204
205 {
206 // ----- test 7 -----
207 string t0[] = {"...#.....###....#.....#...#.#.",".#..#.##..#..#.#..###...#.....","..#..#..#...#.#..#....##.#.###",".#.#...###.#..#.#..###....#...","...##.###..#.#..#.#...#.##..#.",".#..#..#..#...#.#.#.#.#..#.#..","..#..#.#.#..#..##.#.#..#.##..#",".#.###.#.##..#.....A##......#.","#.........#.#..#.###..###.#...","..###.#.#.#..#.#....#.....#.#.",".#..#.#.####.#..#.#..#.#.###..","..#...#...#..#.#...#.#..#.#..#","#..#.#..#.#.#..###.#.#.#....#.","..#..##.##...#....#..#.#.####.","#..#...#...#..#.#..###.#......","#.#.##...#..#..#.#....#..#.#.#","....#..##.#..#....#.#.#.#...#.",".#.#..#....#.#.##..#..##..#.#.","..##.#..##.#..#..#..#...#.#...","#.#..##..#..#..#..#..##.#.#.#.","..#.#.#.#.#..#...##.#...#..#..",".##.....#..#.#.#.#..#.##.#..#.","...#.#.#..#..#.###.#..#...#.#.",".#..#....#..#.#...###.#.#..#..",".#.#.#####.#....#..#..#.##.#.#",".#...#......#.#..###B#....#...","..###..####.#..#.#...#.#.#..#.","#.#..#.#..#.#.#..#.#..#....#..","..#.##..#.#.#.####..#.#####..#","#.....#...#.#......#.......#.."};
208 p0.assign(t0, t0 + sizeof(t0) / sizeof(t0[0]));
209 p1 = "Bob wins";
210 all_right = KawigiEdit_RunTest(7, p0, true, p1) && all_right;
211 // ------------------
212 }
213
214 if (all_right) {
215 cout << "You're a stud (at least on the example cases)!" << endl;
216 } else {
217 cout << "Some of the test cases had errors." << endl;
218 }
219 return 0;
220 }
221 // END KAWIGIEDIT TESTING