BYRBT

TC SRM 556

250pt:

最大xor和路径。

由于权值比较小,暴力就行了。

  1 #include<cstdio>
  2 #include<cstdlib>
  3 #include<cstring>
  4 #include<algorithm>
  5 #include<vector>
  6 #include<set>
  7 #include<map>
  8 #include<bitset>
  9 #include<ctime>
 10 #include<iostream>
 11 #include<string>
 12 #include<cctype>
 13 #include<queue>
 14 #include<stack>
 15 #include<list>
 16 
 17 using namespace std;
 18 
 19 int n;
 20 
 21 struct rec
 22 {
 23     int num,v;
 24     rec(){}
 25     rec(int a,int b)
 26     {
 27         num=a;v=b;
 28     }
 29 };
 30 
 31 queue<rec> que;
 32 
 33 bool use[1000][2000];
 34 
 35 class XorTravelingSalesman
 36 {
 37     public:
 38         int maxProfit(vector <int> v, vector <string> roads)
 39         {
 40             n=roads[0].size();
 41             que.push(rec(0,v[0]));
 42             int ans=v[0];
 43             use[0][v[0]]=true;
 44             while (que.size())
 45             {
 46                 rec now=que.front();
 47                 que.pop();
 48                 for (int a=0;a<n;a++)
 49                     if (roads[now.num][a]=='Y')
 50                     {
 51                         int vv=now.v ^ v[a];
 52                         if (!use[a][vv])
 53                         {
 54                             que.push(rec(a,vv));
 55                             use[a][vv]=true;
 56                             ans=max(ans,vv);
 57                         }
 58                     }
 59             }
 60             return ans;
 61         }        
 62 };
 63 
 64 // BEGIN KAWIGIEDIT TESTING
 65 // Generated by KawigiEdit 2.1.4 (beta) modified by pivanof
 66 bool KawigiEdit_RunTest(int testNum, vector <int> p0, vector <string> p1, bool hasAnswer, int p2) {
 67     cout << "Test " << testNum << ": [" << "{";
 68     for (int i = 0; int(p0.size()) > i; ++i) {
 69         if (i > 0) {
 70             cout << ",";
 71         }
 72         cout << p0[i];
 73     }
 74     cout << "}" << "," << "{";
 75     for (int i = 0; int(p1.size()) > i; ++i) {
 76         if (i > 0) {
 77             cout << ",";
 78         }
 79         cout << "\"" << p1[i] << "\"";
 80     }
 81     cout << "}";
 82     cout << "]" << endl;
 83     XorTravelingSalesman *obj;
 84     int answer;
 85     obj = new XorTravelingSalesman();
 86     clock_t startTime = clock();
 87     answer = obj->maxProfit(p0, p1);
 88     clock_t endTime = clock();
 89     delete obj;
 90     bool res;
 91     res = true;
 92     cout << "Time: " << double(endTime - startTime) / CLOCKS_PER_SEC << " seconds" << endl;
 93     if (hasAnswer) {
 94         cout << "Desired answer:" << endl;
 95         cout << "\t" << p2 << endl;
 96     }
 97     cout << "Your answer:" << endl;
 98     cout << "\t" << answer << endl;
 99     if (hasAnswer) {
100         res = answer == p2;
101     }
102     if (!res) {
103         cout << "DOESN'T MATCH!!!!" << endl;
104     } else if (double(endTime - startTime) / CLOCKS_PER_SEC >= 2) {
105         cout << "FAIL the timeout" << endl;
106         res = false;
107     } else if (hasAnswer) {
108         cout << "Match :-)" << endl;
109     } else {
110         cout << "OK, but is it right?" << endl;
111     }
112     cout << "" << endl;
113     return res;
114 }
115 int main() {
116     bool all_right;
117     all_right = true;
118     
119     vector <int> p0;
120     vector <string> p1;
121     int p2;
122     
123     {
124     // ----- test 0 -----
125     int t0[] = {0,7,11,5,2};
126             p0.assign(t0, t0 + sizeof(t0) / sizeof(t0[0]));
127     string t1[] = {"NYNYY","YNYNN","NYNNN","YNNNN","YNNNN"};
128             p1.assign(t1, t1 + sizeof(t1) / sizeof(t1[0]));
129     p2 = 14;
130     all_right = KawigiEdit_RunTest(0, p0, p1, true, p2) && all_right;
131     // ------------------
132     }
133     
134     {
135     // ----- test 1 -----
136     int t0[] = {556};
137             p0.assign(t0, t0 + sizeof(t0) / sizeof(t0[0]));
138     string t1[] = {"N"};
139             p1.assign(t1, t1 + sizeof(t1) / sizeof(t1[0]));
140     p2 = 556;
141     all_right = KawigiEdit_RunTest(1, p0, p1, true, p2) && all_right;
142     // ------------------
143     }
144     
145     {
146     // ----- test 2 -----
147     int t0[] = {0,4,8,32,512};
148             p0.assign(t0, t0 + sizeof(t0) / sizeof(t0[0]));
149     string t1[] = {"NYYYY","YNNNN","YNNNN","YNNNN","YNNNN"};
150             p1.assign(t1, t1 + sizeof(t1) / sizeof(t1[0]));
151     p2 = 556;
152     all_right = KawigiEdit_RunTest(2, p0, p1, true, p2) && all_right;
153     // ------------------
154     }
155     
156     {
157     // ----- test 3 -----
158     int t0[] = {37,1,19,64,42,41,64,64,54,16,256,36,64,2,4,2,62,29,58,64,1,32,16,256,17,2,17,4,1,64,21,8,256,63,3,1,43,15,8,39,41,8,16,8,16,256,64,512,45,64};
159             p0.assign(t0, t0 + sizeof(t0) / sizeof(t0[0]));
160     string t1[] = {"NNNNNNYYYYNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNN","NNNNNNNNNNNNNNNNYNNNNNNNYNNNNNNNNNNNNNNNNYYNNNYYNN","NNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN","NNNNNNNYNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN","NNNNNNNNNNNNNNNYNNYNYNNNNNNYNNNNNNNNNNYNNNNNNNNNNN","NNYNNNYNNNNNNNNYNNYNNNYYNNNYNYNNNNYNNNNNNNNYNNNNNN","YNYNNYNYNNNNNNNYNNNNNNNNNNNNNNNNNNNYNNNNNNNNYNNYNN","YNNYNNYNYNYYNNNNNNNNNNNNNNNNNNNNNNYNNYNNNNNNNNNNNN","YNNNNNNYNNNNNNNNNNNNNNYNYNNNNNNNNNNYYYNNNNNNNYNNNY","YNNNNNNNNNNNNNNNNYNYNYNYYNNNYNNNNYNNNNNNNNNNNNNNNY","NNNNNNNYNNNNYNNNNNNNNYYNNNYYNNNNYNYYNNNNNNNNNNNNNN","NNNNNNNYNNNNNNYNNNNYYNNNYNNYYNNNNNNNNNNNNNYNYNNNNN","NNNNNNNNNNYNNNNNYNNNNYNNNNNNNNNNYNYNNYNYNNNYNYNNNN","NNNNNNNNNNNNNNNYNNNNNNNNNYNNNNNNNNNNNNYNNNNNNNNYNN","NNNNNNNNNNNYNNNNNYNYNNYYNNNNNYNNNNNNNNNYNNYNNYNNNN","NNNNYYYNNNNNNYNNNYYNNYNNNYNYYNNNNNNNNNYYYNNYNNYNYN","NYNNNNNNNNNNYNNNNNNNYNNNYYNNNYNNNNYNNNNNNNNNNNNNNN","NNNNNNNNNYNNNNYYNNNNNNYNNNYNNNNNYNNYNYYNNNNYNNNYNN","NNNYYYNNNNNNNNNYNNNNNYNYNYNNNNNNNNYNNNNNNNNNNN"
161             "NNNN","NNNNNNNNNYNYNNYNNNNNNYNYYYNNNNNNNNNNNYNNYNNNNNYNNN","NNNNYNNNNNNYNNNNYNNNNYNNNYYNNNYNNNYNNNNNNNNNNYNYNY","NNNNNNNNNYYNYNNYNNYYYNYNNNNNNNNYNYNNNNNNNNNNYNNNNN","NNNNNYNNYNYNNNYNNYNNNYNNNNNNNNNNNYNNYNYNNYNNNNNNNN","NNNNNYNNNYNNNNYNNNYYNNNNNNNNNNNNNNNNNNNNNNYNNNYNNN","NYNNNNNNYYNYNNNNYNNYNNNNNNNNNNYNNNNNNYNNNYNNYNNNNN","NNNNNNNNNNNNNYNYYNYYYNNNNNNYNNNNNNNNNNNYYNNNNNNNYN","NNNNNNNNNNYNNNNNNYNNYNNNNNNNNYNNNNYNNNNNNYYNNNNYNN","NNNNYYNNNNYYNNNYNNNNNNNNNYNNNYYNYNNNNNNNNNNNNNNNNN","NNNNNNNNNYNYNNNYNNNNNNNNNNNNNYNNNNYNNNNNNNNYNNYNYN","NNNNNYNNNNNNNNYNYNNNNNNNNNYYYNNNNNNNNYNNNNYNNNNNNN","NNNNNNNNNNNNNNNNNNNNYNNNYNNYNNNNNYNNNNNNNNNNNNNNNY","NNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNYNNNNNNNNNYNNNNNNN","NNNNNNNNNNYNYNNNNYNNNNNNNNNYNNNYNNNYYNNNNNYNNNYNNN","NNNNNNNNNYNNNNNNNNNNNYYNNNNNNNYNNNNNNNYNNYNNNNNNNN","NNNNNYNYNNYNYNNNYNYNYNNNNNYNYNNNNNNYYNYNYNYNNNNNYN","YNNNNNYNYNYNNNNNNYNNNNNNNNNNNNNNYNYNNNNNYNNYNNNYNN","NNNNNNNNYNNNNNNNNNNNNNYNNNNNNNNNYNYNNNNNNYNNNNNNYN","NNNNNNNYYNNNYNNNNYNYNNNNYNNNNYNNNNNNNNNN"
162             "NYNNNNYNNN","NNNNYNNNNNNNNYNYNYNNNNYNNNNNNNNNNYYNNNNYNNNNNNNNNY","NNNNNNNNNNNNYNYYNNNNNNNNNYNNNNNNNNNNNNYNNNNNYNYYNN","NNNNNNNNNNNNNNNYNNNYNNNNNYNNNNNNNNYYNNNNNNNNNNNNNN","NYNNNNNNNNNNNNNNNNNNNNYNYNYNNNNNNYNNYYNNNNNNNNNNNN","NYNNNNNNNNNYNNYNNNNNNNNYNNYNNYNYYNYNNNNNNNNNYNNNNN","NNNNNYNNNNNNYNNYNYNNNNNNNNNNYNNNNNNYNNNNNNNNNNNNNY","NNNNNNYNNNNYNNNNNNNNNYNNYNNNNNNNNNNNNNNYNNYNNYNNNY","NNNNNNNNYNNNYNYNNNNNYNNNNNNNNNNNNNNNNNNNNNNNYNNNNN","NYNNNNNNNNNNNNNYNNNYNNNYNNNNYNNNYNNNNYNYNNNNNNNNNN","NYNNNNYNNNNNNYNNNYNNYNNNNNYNNNNNNNNYNNNYNNNNNNNNNN","NNNNNNNNNNNNNNNYNNNNNNNNNYNNYNNNNNYNYNNNNNNNNNNNNN","NNNNNNNNYYNNNNNNNNNNYNNNNNNNNNYNNNNNNNYNNNNYYNNNNN"};
163             p1.assign(t1, t1 + sizeof(t1) / sizeof(t1[0]));
164     p2 = 895;
165     all_right = KawigiEdit_RunTest(3, p0, p1, true, p2) && all_right;
166     // ------------------
167     }
168     
169     if (all_right) {
170         cout << "You're a stud (at least on the example cases)!" << endl;
171     } else {
172         cout << "Some of the test cases had errors." << endl;
173     }
174     return 0;
175 }
176 // END KAWIGIEDIT TESTING
View Code

 

500pt:

给N张卡片组成的数,每次取出最左的卡片摆在左边或者右边组成一个新的N位数,要求新数大于等于原数并要求最少。

简单的区间DP,DP直接比较字典序即可。

  1 #include<cstdio>
  2 #include<cstdlib>
  3 #include<cstring>
  4 #include<algorithm>
  5 #include<vector>
  6 #include<set>
  7 #include<map>
  8 #include<bitset>
  9 #include<ctime>
 10 #include<iostream>
 11 #include<string>
 12 #include<cctype>
 13 #include<queue>
 14 #include<stack>
 15 #include<list>
 16 
 17 using namespace std;
 18 
 19 string f[60][60][3];
 20 
 21 int cmp(int a,int b)
 22 {
 23     if (a<b) return 0;
 24     if (a==b) return 1;
 25     return 2;
 26 }
 27 
 28 class LeftRightDigitsGame2
 29 {
 30     public:
 31         string minNumber(string s1, string s2)
 32         {
 33             int l=s1.size();
 34             for (int a=0;a<l;a++)
 35                 for (int b=0;b<l;b++)
 36                     for (int c=0;c<3;c++)
 37                         f[a][b][c]="A";
 38             for (int a=0;a<l;a++)
 39                 f[0][a][cmp(s1[0],s2[a])]=s1[0];
 40             for (int a=0;a<l-1;a++)
 41                 for (int b=0;b<l-a;b++)
 42                     for (int c=0;c<3;c++)
 43                         if (f[a][b][c]!="A")
 44                         {
 45                             if (b!=0)
 46                             {
 47                                 if (s1[a+1]<s2[b-1]) f[a+1][b-1][0]=min(f[a+1][b-1][0],s1[a+1]+f[a][b][c]);
 48                                 if (s1[a+1]==s2[b-1]) f[a+1][b-1][c]=min(f[a+1][b-1][c],s1[a+1]+f[a][b][c]);
 49                                 if (s1[a+1]>s2[b-1]) f[a+1][b-1][2]=min(f[a+1][b-1][2],s1[a+1]+f[a][b][c]);
 50                             }
 51                             if (b+a!=l-1)
 52                             {
 53                                 if (s1[a+1]>s2[b+a+1]) f[a+1][b][(c==0) ? 0 : 2]=min(f[a+1][b][(c==0) ? 0 : 2],f[a][b][c]+s1[a+1]);
 54                                 if (s1[a+1]==s2[b+a+1]) f[a+1][b][c]=min(f[a+1][b][c],f[a][b][c]+s1[a+1]);
 55                                 if (s1[a+1]<s2[b+a+1]) f[a+1][b][(c==2) ? 2 : 0]=min(f[a+1][b][(c==2) ? 2 : 0],f[a][b][c]+s1[a+1]);
 56                             }
 57                         }
 58             if (f[l-1][0][1]=="A" && f[l-1][0][2]=="A") return "";
 59             return min(f[l-1][0][1],f[l-1][0][2]);
 60         }
 61 };
 62 
 63 // BEGIN KAWIGIEDIT TESTING
 64 // Generated by KawigiEdit 2.1.4 (beta) modified by pivanof
 65 bool KawigiEdit_RunTest(int testNum, string p0, string p1, bool hasAnswer, string p2) {
 66     cout << "Test " << testNum << ": [" << "\"" << p0 << "\"" << "," << "\"" << p1 << "\"";
 67     cout << "]" << endl;
 68     LeftRightDigitsGame2 *obj;
 69     string answer;
 70     obj = new LeftRightDigitsGame2();
 71     clock_t startTime = clock();
 72     answer = obj->minNumber(p0, p1);
 73     clock_t endTime = clock();
 74     delete obj;
 75     bool res;
 76     res = true;
 77     cout << "Time: " << double(endTime - startTime) / CLOCKS_PER_SEC << " seconds" << endl;
 78     if (hasAnswer) {
 79         cout << "Desired answer:" << endl;
 80         cout << "\t" << "\"" << p2 << "\"" << endl;
 81     }
 82     cout << "Your answer:" << endl;
 83     cout << "\t" << "\"" << answer << "\"" << endl;
 84     if (hasAnswer) {
 85         res = answer == p2;
 86     }
 87     if (!res) {
 88         cout << "DOESN'T MATCH!!!!" << endl;
 89     } else if (double(endTime - startTime) / CLOCKS_PER_SEC >= 2) {
 90         cout << "FAIL the timeout" << endl;
 91         res = false;
 92     } else if (hasAnswer) {
 93         cout << "Match :-)" << endl;
 94     } else {
 95         cout << "OK, but is it right?" << endl;
 96     }
 97     cout << "" << endl;
 98     return res;
 99 }
100 int main() {
101     bool all_right;
102     all_right = true;
103     
104     string p0;
105     string p1;
106     string p2;
107     
108     {
109     // ----- test 0 -----
110     p0 = "565";
111     p1 = "556";
112     p2 = "556";
113     all_right = KawigiEdit_RunTest(0, p0, p1, true, p2) && all_right;
114     // ------------------
115     }
116     
117     {
118     // ----- test 1 -----
119     p0 = "565";
120     p1 = "566";
121     p2 = "655";
122     all_right = KawigiEdit_RunTest(1, p0, p1, true, p2) && all_right;
123     // ------------------
124     }
125     
126     {
127     // ----- test 2 -----
128     p0 = "565";
129     p1 = "656";
130     p2 = "";
131     all_right = KawigiEdit_RunTest(2, p0, p1, true, p2) && all_right;
132     // ------------------
133     }
134     
135     {
136     // ----- test 3 -----
137     p0 = "9876543210";
138     p1 = "5565565565";
139     p2 = "5678943210";
140     all_right = KawigiEdit_RunTest(3, p0, p1, true, p2) && all_right;
141     // ------------------
142     }
143     
144     {
145     // ----- test 4 -----
146     p0 = "8016352";
147     p1 = "1000000";
148     p2 = "1086352";
149     all_right = KawigiEdit_RunTest(4, p0, p1, true, p2) && all_right;
150     // ------------------
151     }
152     
153     if (all_right) {
154         cout << "You're a stud (at least on the example cases)!" << endl;
155     } else {
156         cout << "Some of the test cases had errors." << endl;
157     }
158     return 0;
159 }
160 // END KAWIGIEDIT TESTING
View Code

 

1000pt:

这题超好评。

给你一张图,有些边只能走2次,有些能走无数次,然后给出a1 a2 an b1 b2 bn六个数,你需要从a1走到a2再走回a1总共an次对b1 b2 bn也同理,问是否可行。

嘛,最基础的思路是直接把a1 b1当做起点然后a2 b2当做终点直接跑一遍网络流看是否可行,嘛,这样的话就能过掉所有样例了,然后就被坑了。

这样做的问题在哪里呢?原因是流的时候我有可能是从a1有部分流到了b2去,而b1流到了a2去,这样就导致了虽然满流但并不是符合题意的走法。

So how to solve it ?

嘛,其实解决的办法很简单,先做一遍网络流,不满流就GG了。如果满流的话,交换b1 b2,如果还满流,那就是对的了。

证明如下:

第一次未交换时,我们假设流出来的方案是又不合法的,那么我们设从a1流到b2的流量为x那么有:

a1到a2的流量=an-x

a1到b2的流量=x

b1到a2的流量=x

b1到b2的流量=bn-x

第二次我们交换b1,b2,那么由于都是无向边,那么首先b2从b1可以流bn-x的流量,a1到a2仍然可以流an-x的流量,也就是说两边都还差x的流量。由于第二次流出来是满流的,那么如果我们最后流出来的方案是a1给b1流了x的流量导致满流,那么我们有:

a1到b1和b2都可以流x的流量,那么再交换之后,从a1流到b1的流量我们可以调整为先从b2流到了a1,再从a1流到了b1总共x的流量(关键之处是在于无向图),那么另外一边也可以对称的调整,所以一旦满流,就一定存在可行解。

  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 const int INF=0x3f3f3f3f;
 25 
 26 int s,t,depth[110],q[110],en;
 27 
 28 struct edge
 29 {
 30     int e,f;
 31     edge *next,*op;
 32 }*v[110],ed[21000];
 33 
 34 void add_edge(int s,int e,int f1,int f2)
 35 {
 36     en++;
 37     ed[en].next=v[s];v[s]=ed+en;v[s]->e=e;v[s]->f=f1;
 38     en++;
 39     ed[en].next=v[e];v[e]=ed+en;v[e]->e=s;v[e]->f=f2;
 40     v[s]->op=v[e];v[e]->op=v[s];
 41 }
 42 
 43 bool bfs()
 44 {
 45     memset(depth,0,sizeof(depth));
 46     depth[s]=1;
 47     q[1]=s;
 48     int front=1,tail=1;
 49     for (;front<=tail;)
 50     {
 51         int now=q[front++];
 52         for (edge *e=v[now];e;e=e->next)
 53             if (e->f && !depth[e->e])
 54             {
 55                 depth[e->e]=depth[now]+1;
 56                 if (e->e==t) return true;
 57                 q[++tail]=e->e;
 58             }
 59     }
 60     return false;
 61 }
 62 
 63 int dfs(int now,int cur_flow)
 64 {
 65     if (now==t) return cur_flow;
 66     int rest=cur_flow;
 67     for (edge *e=v[now];e && rest;e=e->next)
 68         if (e->f && depth[e->e]==depth[now]+1)
 69         {
 70             int new_flow=dfs(e->e,min(rest,e->f));
 71             e->f-=new_flow;
 72             e->op->f+=new_flow;
 73             rest-=new_flow;
 74         }
 75     if (rest==cur_flow) depth[now]=-1;
 76     return cur_flow-rest;
 77 }
 78 
 79 int dinic()
 80 {
 81     int ans=0;
 82     while (bfs())
 83         ans+=dfs(s,INF);
 84     return ans;
 85 }
 86 
 87 class OldBridges {
 88 public:
 89     string isPossible(vector <string> bridges, int a1, int a2, int an, int b1, int b2, int bn) {
 90         int n=bridges.size();
 91         //a1++;a2++;b1++;b2++;
 92         an<<=1;bn<<=1;
 93         s=n;t=n+1;
 94         en=0;
 95         memset(v,0,sizeof(v));
 96         for (int a=0;a<n;a++)
 97             for (int b=a+1;b<n;b++)
 98                 if (bridges[a][b]=='O') add_edge(a,b,2,2);
 99                 else
100                 {
101                     if (bridges[a][b]=='N') add_edge(a,b,INF,INF);
102                 }
103         add_edge(s,a1,an,0);
104         add_edge(a2,t,an,0);
105         add_edge(s,b1,bn,0);
106         add_edge(b2,t,bn,0);
107         if (dinic()!=an+bn) return "No";
108         swap(b1,b2);
109         en=0;
110         memset(v,0,sizeof(v));
111         for (int a=0;a<n;a++)
112             for (int b=a+1;b<n;b++)
113                 if (bridges[a][b]=='O') add_edge(a,b,2,2);
114                 else
115                 {
116                     if (bridges[a][b]=='N') add_edge(a,b,INF,INF);
117                 }
118         add_edge(s,a1,an,0);
119         add_edge(a2,t,an,0);
120         add_edge(s,b1,bn,0);
121         add_edge(b2,t,bn,0);
122         if (dinic()!=an+bn) return "No";
123         return "Yes";
124     }
125 };
126 
127 
128 //<%:testing-code%>
129 //Powered by KawigiEdit 2.1.4 (beta) modified by pivanof!
130 
131 // BEGIN KAWIGIEDIT TESTING
132 // Generated by KawigiEdit 2.1.4 (beta) modified by pivanof
133 bool KawigiEdit_RunTest(int testNum, vector <string> p0, int p1, int p2, int p3, int p4, int p5, int p6, bool hasAnswer, string p7) {
134     cout << "Test " << testNum << ": [" << "{";
135     for (int i = 0; int(p0.size()) > i; ++i) {
136         if (i > 0) {
137             cout << ",";
138         }
139         cout << "\"" << p0[i] << "\"";
140     }
141     cout << "}" << "," << p1 << "," << p2 << "," << p3 << "," << p4 << "," << p5 << "," << p6;
142     cout << "]" << endl;
143     OldBridges *obj;
144     string answer;
145     obj = new OldBridges();
146     clock_t startTime = clock();
147     answer = obj->isPossible(p0, p1, p2, p3, p4, p5, p6);
148     clock_t endTime = clock();
149     delete obj;
150     bool res;
151     res = true;
152     cout << "Time: " << double(endTime - startTime) / CLOCKS_PER_SEC << " seconds" << endl;
153     if (hasAnswer) {
154         cout << "Desired answer:" << endl;
155         cout << "\t" << "\"" << p7 << "\"" << endl;
156     }
157     cout << "Your answer:" << endl;
158     cout << "\t" << "\"" << answer << "\"" << endl;
159     if (hasAnswer) {
160         res = answer == p7;
161     }
162     if (!res) {
163         cout << "DOESN'T MATCH!!!!" << endl;
164     } else if (double(endTime - startTime) / CLOCKS_PER_SEC >= 2) {
165         cout << "FAIL the timeout" << endl;
166         res = false;
167     } else if (hasAnswer) {
168         cout << "Match :-)" << endl;
169     } else {
170         cout << "OK, but is it right?" << endl;
171     }
172     cout << "" << endl;
173     return res;
174 }
175 int main() {
176     bool all_right;
177     all_right = true;
178     
179     vector <string> p0;
180     int p1;
181     int p2;
182     int p3;
183     int p4;
184     int p5;
185     int p6;
186     string p7;
187     
188     {
189     // ----- test 0 -----
190     string t0[] = {"XOXX","OXOX","XOXO","XXOX"};
191             p0.assign(t0, t0 + sizeof(t0) / sizeof(t0[0]));
192     p1 = 0;
193     p2 = 1;
194     p3 = 1;
195     p4 = 2;
196     p5 = 3;
197     p6 = 1;
198     p7 = "Yes";
199     all_right = KawigiEdit_RunTest(0, p0, p1, p2, p3, p4, p5, p6, true, p7) && all_right;
200     // ------------------
201     }
202     
203     {
204     // ----- test 1 -----
205     string t0[] = {"XOXX","OXOX","XOXO","XXOX"};
206             p0.assign(t0, t0 + sizeof(t0) / sizeof(t0[0]));
207     p1 = 0;
208     p2 = 2;
209     p3 = 1;
210     p4 = 1;
211     p5 = 3;
212     p6 = 1;
213     p7 = "No";
214     all_right = KawigiEdit_RunTest(1, p0, p1, p2, p3, p4, p5, p6, true, p7) && all_right;
215     // ------------------
216     }
217     
218     {
219     // ----- test 2 -----
220     string t0[] = {"XOXO","OXOX","XOXO","OXOX"};
221             p0.assign(t0, t0 + sizeof(t0) / sizeof(t0[0]));
222     p1 = 0;
223     p2 = 2;
224     p3 = 1;
225     p4 = 1;
226     p5 = 3;
227     p6 = 1;
228     p7 = "Yes";
229     all_right = KawigiEdit_RunTest(2, p0, p1, p2, p3, p4, p5, p6, true, p7) && all_right;
230     // ------------------
231     }
232     
233     {
234     // ----- test 3 -----
235     string t0[] = {"XNXO","NXOX","XOXO","OXOX"};
236             p0.assign(t0, t0 + sizeof(t0) / sizeof(t0[0]));
237     p1 = 0;
238     p2 = 2;
239     p3 = 1;
240     p4 = 1;
241     p5 = 3;
242     p6 = 2;
243     p7 = "No";
244     all_right = KawigiEdit_RunTest(3, p0, p1, p2, p3, p4, p5, p6, true, p7) && all_right;
245     // ------------------
246     }
247     
248     {
249     // ----- test 4 -----
250     string t0[] = {"XOXOO","OXOXO","XOXOO","OXOXO","OOOOX"};
251             p0.assign(t0, t0 + sizeof(t0) / sizeof(t0[0]));
252     p1 = 0;
253     p2 = 2;
254     p3 = 2;
255     p4 = 1;
256     p5 = 3;
257     p6 = 2;
258     p7 = "Yes";
259     all_right = KawigiEdit_RunTest(4, p0, p1, p2, p3, p4, p5, p6, true, p7) && all_right;
260     // ------------------
261     }
262     
263     {
264     // ----- test 5 -----
265     string t0[] = {"XOOOX","OXOOX","OOXOX","OOOXN","XXXNX"};
266             p0.assign(t0, t0 + sizeof(t0) / sizeof(t0[0]));
267     p1 = 0;
268     p2 = 4;
269     p3 = 3;
270     p4 = 1;
271     p5 = 2;
272     p6 = 2;
273     p7 = "No";
274     all_right = KawigiEdit_RunTest(5, p0, p1, p2, p3, p4, p5, p6, true, p7) && all_right;
275     // ------------------
276     }
277     
278     {
279     // ----- test 6 -----
280     string t0[] = {"XOXOOX", "OXXXNO", "XXXOOX", "OXOXOO", "ONOOXO", "XOXOOX"};
281             p0.assign(t0, t0 + sizeof(t0) / sizeof(t0[0]));
282     p1 = 0;
283     p2 = 1;
284     p3 = 3;
285     p4 = 5;
286     p5 = 3;
287     p6 = 3;
288     p7 = "No";
289     all_right = KawigiEdit_RunTest(5, p0, p1, p2, p3, p4, p5, p6, true, p7) && all_right;
290     // ------------------
291     }
292     
293     if (all_right) {
294         cout << "You're a stud (at least on the example cases)!" << endl;
295     } else {
296         cout << "Some of the test cases had errors." << endl;
297     }
298     return 0;
299 }
300 // END KAWIGIEDIT TESTING
View Code

 

posted @ 2013-09-01 13:53  zhonghaoxi  阅读(1346)  评论(0编辑  收藏  举报
BYRBT