Korotkodul

CF B

Jan 12th, 2022 (edited)
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.34 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<<' ';
  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. pii md1, md2, md3, md4;
  32. int t=1,n,m;
  33.  
  34. int dst(pii a, pii b){
  35. return abs(a.first - b.first) + abs(a.second - b.second);
  36. }
  37.  
  38.  
  39. bool cmpR(pii a, pii b){
  40. return dst(a, md1) < dst(b, md1) || dst(a, md1) == dst(b, md1) && dst(a, md2) < dst(b, md2)
  41. || dst(a, md1) == dst(b, md1) && dst(a, md2) == dst(b, md2) && dst(a, md3) < dst(b, md3)
  42. || dst(a, md1) == dst(b, md1) && dst(a, md2) == dst(b, md2) && dst(a, md3) == dst(b, md3) && dst(a, md4) < dst(b, md4);
  43. }
  44.  
  45.  
  46.  
  47. void cvp(vector <pii> v){
  48. for (auto x: v){
  49. cout<<x.first<<' '<<x.second<<"\n";
  50. }cout<<"\n";
  51. }
  52.  
  53.  
  54. int main()
  55. {
  56. ios::sync_with_stdio(0);
  57. cin.tie(0);
  58. cout.tie(0);
  59. cin>>t;
  60. vector <pii> R;//координаты Рахула
  61. vector <int> ans;
  62. vector <pii> T;//координаты Тины
  63. for (int act=0;act<t;++act){
  64. T.clear();
  65. R.clear();
  66. cin>>n>>m;
  67. for (int i = 0; i < n; ++i){
  68. for (int j = 0;j<m;++j){
  69. R.push_back({i, j});
  70.  
  71. }
  72. }
  73. md1 = {(n-1)/2, (m-1)/2};
  74. md2 = {n/2, m/2};
  75. md4 = {(n-1)/2, m/2};
  76. md3 = {n/2, (m-1)/2};
  77.  
  78. sort(R.begin(), R.end(), cmpR);
  79.  
  80. T.resize(n*m);
  81. ans.resize(n*m);
  82. for (int i=0;i<n*m;++i){
  83. int x,y;
  84.  
  85. if (R[i].first > md1.first){
  86. x = 0;
  87. }
  88. else x = n-1;
  89.  
  90. if (R[i].second > md1.second){
  91. y = 0;
  92. }
  93. else y = m - 1;
  94.  
  95. T[i] = {x,y};
  96. }
  97. for (int i=0;i<n*m;++i){
  98. //cout<<"k = "<<i<<"\n";
  99. ans[i] = dst(R[i], T[i]);
  100. }
  101. cv(ans);//вывести ответ
  102. }
  103. }
  104. /*
  105. 2
  106. 4 3
  107. 1 2
  108.  
  109. */
  110.  
Add Comment
Please, Sign In to add comment