ZOJ 4033 CONTINUE...?(The 15th Zhejiang Provincial Collegiate Programming Contest Sponsored by TuSimple)

 1 #include <iostream>
 2 #include <algorithm>
 3 using namespace std;
 4 
 5 const int maxn = 1e5 + 5;
 6 int a[maxn];
 7 
 8 int main(){
 9     int t;
10     cin >> t;
11     while(t--){
12         int n;
13         cin >> n;
14         string s;
15         cin >> s;
16         int sum = 0;
17         bool l = true;
18         int i;
19         for(i = n-1;i >= 1;i -= 2){
20             sum += 2*i+1;
21             if(l){
22                 if(s[i] == '0'){
23                     a[i] = 2;
24                 }
25                 else
26                     a[i] = 4;
27                 if(s[i-1] == '0'){
28                     a[i-1] = 1;
29                 }
30                 else a[i-1] = 3;
31                 l = false;
32             }
33             else{
34                 if(s[i] == '0'){
35                     a[i] = 1;
36                 }
37                 else
38                     a[i] = 3;
39                 if(s[i-1] == '0'){
40                     a[i-1] = 2;
41                 }
42                 else a[i-1] = 4;
43                 l = true;
44             }
45         }
46         if(i == 0){
47             sum += 1;
48             if(l){
49                 if(s[0] == '0'){
50                     a[0] = 2;
51                 }
52                 else
53                     a[0] = 4;
54             }
55             else{
56                 if(s[0] == '0'){
57                     a[0] = 1;
58                 }
59                 else
60                     a[0] = 3;
61             }
62         }
63 
64         if(sum%2){
65             cout << -1 << endl;
66             continue;
67         }
68         else{
69             for(int j = 0;j < n;j++){
70                 cout << a[j] ;
71             }
72             cout << endl;
73         }
74 
75     }
76     return 0;
77 }

猜你喜欢

转载自www.cnblogs.com/jaydenouyang/p/9003397.html