Advertisement
Korotkodul

a_mosh

Jan 22nd, 2022 (edited)
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.37 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. #include <vector>
  4. #include <queue>
  5. #include <algorithm>
  6. #include <string>
  7. #include <stack>
  8. #include <set>
  9. #include <map>
  10. #define pii pair <int,int>
  11. #define vec vector
  12. using namespace std;
  13. using ll = long long;
  14. using ld = long double;
  15. using db = double;
  16. void cv(vector <int> &v){
  17. for (auto x: v) cout<<x<<' ';
  18. cout<<"\n";
  19. }
  20.  
  21. void cvl(vector <ll> &v){
  22. for (auto x: v) cout<<x<<'\n';
  23. cout<<"\n";
  24. }
  25.  
  26.  
  27. void cvv(vector <vector <int> > &v){
  28. for (auto x: v) cv(x);
  29. cout<<"\n";
  30. }
  31.  
  32. void cvb(vector <bool> v){
  33. for (bool x: v) cout<<x<<' ';
  34. cout<<"\n";
  35. }
  36.  
  37. vector <vector <bool> > num(10, vector <bool> (7, 1));// 1 - i-я палоча есть, 0 - нет
  38. vector <vector <int> > opr(10, vector <int> (10, 0)); //сколько операция нужно, чтобы перейти из числа a в число b
  39.  
  40.  
  41. ll mv(int x, int y){//move from num a to num b
  42. string a, b;
  43. a = to_string(x);
  44. b = to_string(y);
  45. ll res = 0;
  46. reverse(a.begin(), a.end());
  47. reverse(b.begin(), b.end());
  48. if (a.size() < b.size()) res += 2;
  49. for (int i = 0; i < a.size(); ++i){
  50. if (a[i] != b[i]){
  51. res += opr[a[i] - 48][b[i] - 48];
  52. }
  53. }
  54. return res;
  55. }
  56.  
  57. vector <ll> pref(1e9+5, 0);
  58.  
  59. int main()
  60. {
  61. /*ios::sync_with_stdio(0);
  62. cin.tie(0);
  63. cout.tie(0);*/
  64. //представить все цифры в виде палочек
  65. vector <int> del;
  66. vector <vector<int> > del_al;
  67. del = {1};
  68. del_al.push_back(del);
  69. del = {0, 1, 2, 3, 4};
  70. del_al.push_back(del);
  71. del = {3, 6};
  72. del_al.push_back(del);
  73. del = {3, 4};
  74. del_al.push_back(del);
  75. del = {0, 2, 4};
  76. del_al.push_back(del);
  77. del = {4,5};
  78. del_al.push_back(del);
  79. del = {5,};
  80. del_al.push_back(del);
  81. del = {1, 2, 3, 4};
  82. del_al.push_back(del);
  83. del = {};
  84. del_al.push_back(del);
  85. del = {4};
  86. del_al.push_back(del);
  87. for (auto v: del_al){
  88. // cv(v);
  89. }
  90. for (int i = 0; i < 10;++i){
  91. for (int idx: del_al[i]){
  92. num[i][idx] = 0;
  93. }
  94. }
  95. //cout<<"HELLO\n";
  96. //for (auto v: num) cvb(v);
  97. //посчитали, сколько палочек менять для перехода между числами
  98. for (int i = 0; i < 10; ++i){
  99. //cout <<"i= "<<i<<"\n";
  100. for (int j=0;j<10;++j){
  101. //cout<<"j= "<<j<<"\n";
  102. //cout<<"a b = "<<i<<' '<<j<<"\n";
  103. for (int idx = 0; idx < 7; ++idx){
  104. //cout<<"idx = "<<idx<<"\n";
  105. //cout<<"a(idx) b(idx) == "<<num[i][idx]<<' '<<num[j][idx]<<"\n";
  106. if (num[i][idx] != num[j][idx]){
  107. opr[i][j]++;
  108. //cout<<idx<<' ';
  109. }
  110. }
  111. //cout<<"\n need to change = "<<opr[i][j]<<"\n";
  112. //cout<<"\n\n";
  113. }
  114. }
  115. //cvv(opr);
  116. /*int t; cin>>t;
  117. for (int i=0;i<t;++i){
  118. int a,b; cin>>a>>b;
  119. cout<<opr[a][b]<<"\n\n";
  120. }*/
  121. //1e9+2
  122. //cout<<"GO\n";
  123. cout<<"conting prefix\n";
  124. for (int i = 1; i <= 1e9+2;++i){
  125. //if (i >= 1e6) cout<<i<<" ";
  126. pref[i] = pref[i-1] + mv(i-1, i);
  127. }cout<<"\n cin numbers \n";
  128. int t; cin>>t;
  129. vector <ll> ans;
  130. for (int i=0;i<t;++i){
  131. int k ; cin>>k;
  132. //cout<<pref[k]<<"\n";
  133. ans.push_back(pref[k]);
  134. }
  135. cout<<"ANSWER\n";
  136. cvl(ans);
  137. cout<<"DONE! \n";
  138. }
  139.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement