Advertisement
theo830

guess

May 31st, 2019
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.05 KB | None | 0 0
  1. #include<iostream>
  2. #include<vector>
  3. #include <map>
  4. using namespace std;
  5. typedef pair<int, int> ii;
  6. int main(){
  7. int t;
  8. cin>>t;
  9. pair<int,int>b;
  10. for(int k=0;k<t;k++){
  11. int a;
  12. cin>>a;
  13. int r;
  14. vector<int>code;
  15. pair<int,int>b;
  16. for(int i=0;i<4;i++){
  17. code.push_back(-1);
  18. }
  19. int c[10][4];
  20. vector<int>vip;
  21. for(int i=0;i<10;i++){
  22. for(int j=0;j<4;j++){
  23. c[i][j] = -1;
  24. }
  25. }
  26. vector<pair<int,int> > vp;
  27. for(int i=0;i<a;i++){
  28. cin>>r;
  29. vip.push_back(r);
  30. cin>>b.first;
  31. cin>>b.second;
  32. vp.push_back(b);
  33. }
  34. int w1,w2;
  35. int one,two,three,four;
  36. int o=0;
  37. int ae=0;
  38. while(ae < 1000){
  39. ae++;
  40. for(int i=0;i<vip.size();i++){
  41. o=0;
  42. b = vp[i];
  43. w2 = b.second;
  44. w1 = b.first;
  45. one=vip[i]/1000;
  46. two=(vip[i]/100)%10;
  47. three = (vip[i]/10)%10;
  48. four=vip[i]%10;
  49. vector<pair<int,int> >y;
  50. /*
  51. for(int t1=0;t1<4;t1++){
  52. cout<<code[t1];
  53. }
  54. cout<<endl;
  55. */
  56. if(w1 == 0 && w2 == 0){
  57. for(int j=0;j<4;j++){
  58. c[one][j] = 0;
  59. c[two][j] = 0;
  60. c[three][j] = 0;
  61. c[four][j] = 0;
  62. }
  63. }
  64. else if(w1 == 0){
  65. c[one][0] = 0;
  66. c[two][1] = 0;
  67. c[three][2] = 0;
  68. c[four][3] = 0;
  69. }
  70. if(c[one][0] == 0){
  71. o++;
  72. }
  73. else{
  74. y.push_back(ii(one,0));
  75. }
  76. if(c[two][1] == 0){
  77. o++;
  78. }
  79. else{
  80. y.push_back(ii(two,1));
  81. }
  82. if(c[three][2] == 0){
  83. o++;
  84. }
  85. else{
  86. y.push_back(ii(three,2));
  87. }
  88. if(c[four][3] == 0){
  89. o++;
  90. }
  91. else{
  92. y.push_back(ii(four,3));
  93. }
  94. if(4 - o == w1 && o != 0){
  95. while(!y.empty()){
  96. b = y.back();
  97. y.pop_back();
  98. code[b.second] = b.first;
  99. for(int j=0;j<10;j++){
  100. if(i != b.first){
  101. c[i][b.second] = 0;
  102. }
  103. }
  104. }
  105. }
  106. y.clear();
  107. o=0;
  108. if(c[one][1] == -1 || c[one][2] == -1 || c[one][3] == -1){
  109. o++;
  110. y.push_back(ii(one,0));
  111. }
  112. if(c[two][0] == -1 || c[two][2] == -1 || c[two][3] == -1){
  113. o++;
  114. y.push_back(ii(two,1));
  115. }
  116. if(c[three][1] == -1 || c[three][1] == -1 || c[three][3] == -1){
  117. o++;
  118. y.push_back(ii(three,2));
  119. }
  120. if(c[four][1] == -1 || c[four][2] == -1 || c[four][0] == -1){
  121. o++;
  122. y.push_back(ii(four,3));
  123. }
  124. if(o == w2 && o != 0){
  125. while(!y.empty()){
  126. b = y.back();
  127. y.pop_back();
  128. code.push_back(b.first);
  129. }
  130. }
  131. y.clear();
  132. o=0;
  133. int y1=0;
  134. if(code.size() > 4){
  135. for(int k=4;k<code.size();k++){
  136. if(code[i] != -1){
  137. for(int w=0;w<4;w++){
  138. if(c[code[i]][w] == -1){
  139. o++;
  140. y1 = w;
  141. }
  142. }
  143. if(o == 1){
  144. c[code[i]][y1] = 1;
  145. code[y1] = code[i];
  146. code[i] = -1;
  147. }
  148. }
  149. }
  150. }
  151. }
  152. }
  153. bool w3=0;
  154. for(int i=0;i<4;i++){
  155. if(code[i] == -1){
  156. w3 = 1;
  157. }
  158. }
  159. if(w3){
  160. cout<<0<<endl;
  161. }
  162. else{
  163. for(int i=0;i<4;i++){
  164. cout<<code[i];
  165. }
  166. cout<<endl;
  167. }
  168. }
  169. return 0;
  170. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement