Advertisement
Guest User

programm

a guest
Oct 19th, 2017
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.47 KB | None | 0 0
  1. #define _CRT_SECURE_NO_DEPRECATE
  2. #include<iostream>
  3. #include<string>
  4. #include<conio.h>
  5. #include<vector>
  6. #include<algorithm>
  7.  
  8. using namespace std;
  9.  
  10. int main() {
  11. // freopen("out.txt", "wt", stdout); freopen("in.txt", "rt", stdin);
  12. vector<vector<int>> a;
  13. a.resize(3);
  14. bool contest = true;
  15. bool sport = true;
  16. int n;
  17. int g;
  18.  
  19. cin >> n;
  20. cin >> g;
  21. a[0].push_back(0);
  22. if (g == 0) {
  23. a[1].push_back(0);
  24. a[2].push_back(0);
  25. }
  26. if (g == 1) {
  27. a[1].push_back(1);
  28. a[2].push_back(0);
  29. contest = false;
  30. }
  31. if (g == 2) {
  32. a[1].push_back(0);
  33. a[2].push_back(1);
  34. sport = false;
  35. }
  36. if (g == 3) {
  37. a[1].push_back(1);
  38. a[2].push_back(1);
  39. contest = false;
  40. sport = false;
  41. }
  42. for (int i = 1; i < n; i++) {
  43. cin >> g;
  44. if (g == 0) {
  45. a[0].push_back(max(a[0][i - 1], max(a[1][i - 1], a[2][i - 1])));
  46. a[1].push_back(max(a[0][i - 1], max(a[1][i - 1], a[2][i - 1])));
  47. a[2].push_back(max(a[0][i - 1], max(a[1][i - 1], a[2][i - 1])));
  48. contest = true;
  49. sport = true;
  50. }
  51.  
  52.  
  53. if (g == 1) {
  54. a[0].push_back(max(a[0][i - 1], max(a[1][i - 1], a[2][i - 1])));
  55. if (contest == true) {
  56. a[1].push_back(max(a[0][i - 1], max(a[1][i - 1], a[2][i - 1]))+1);
  57. contest = false;
  58. }
  59. else {
  60. a[1].push_back(max(a[0][i - 1], max(a[1][i - 1], a[2][i - 1])));
  61. contest = true;
  62. }
  63. a[2].push_back(max(a[0][i - 1], max(a[1][i - 1], a[2][i - 1])));
  64. sport = true;
  65. }
  66.  
  67.  
  68. if (g == 2) {
  69. a[0].push_back(max(a[0][i - 1], max(a[1][i - 1], a[2][i - 1])));
  70. a[1].push_back(max(a[0][i - 1], max(a[1][i - 1], a[2][i - 1])));
  71. if (sport == true) {
  72. a[2].push_back(max(a[0][i - 1], max(a[1][i - 1], a[2][i - 1])) + 1);
  73. sport = false;
  74. }
  75. else {
  76. a[2].push_back(max(a[0][i - 1], max(a[1][i - 1], a[2][i - 1])));
  77. sport = true;
  78. }
  79. contest = true;
  80. }
  81.  
  82.  
  83. if (g == 3) {
  84. a[0].push_back(max(a[0][i - 1], max(a[1][i - 1], a[2][i - 1])));
  85. if (contest == true) {
  86. a[1].push_back(max(a[0][i - 1], max(a[1][i - 1], a[2][i - 1])) + 1);
  87. contest = false;
  88. }
  89. else {
  90. a[1].push_back(max(a[0][i - 1], max(a[1][i - 1], a[2][i - 1])));
  91. contest = true;
  92. }
  93. if (sport == true) {
  94. a[2].push_back(max(a[0][i - 1], max(a[1][i - 1], a[2][i - 1])) + 1);
  95. sport = false;
  96. }
  97. else {
  98. a[2].push_back(max(a[0][i - 1], max(a[1][i - 1], a[2][i - 1])));
  99. sport = true;
  100. }
  101. }
  102. }
  103.  
  104.  
  105. int k = (n - max(a[0][n - 1], max(a[1][n - 1], a[2][n - 1])));
  106. cout << k;
  107. return 0;
  108. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement