Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- #include <vector>
- #include <queue>
- #include <algorithm>
- #include <string>
- #include <stack>
- #include <set>
- #include <map>
- #define pii pair <int,int>
- #define vec vector
- using namespace std;
- using ll = long long;
- using ld = long double;
- using db = double;
- void cv(vector <int> &v){
- for (auto x: v) cout<<x<<' ';
- cout<<"\n";
- }
- void cvl(vector <ll> &v){
- for (auto x: v) cout<<x<<' ';
- cout<<"\n";
- }
- void cvv(vector <vector <int> > &v){
- for (auto x: v) cv(x);
- cout<<"\n";
- }
- pii md1, md2, md3, md4;
- int t=1,n,m;
- int dst(pii a, pii b){
- return abs(a.first - b.first) + abs(a.second - b.second);
- }
- bool cmpR(pii a, pii b){
- return dst(a, md1) < dst(b, md1) || dst(a, md1) == dst(b, md1) && dst(a, md2) < dst(b, md2)
- || dst(a, md1) == dst(b, md1) && dst(a, md2) == dst(b, md2) && dst(a, md3) < dst(b, md3)
- || dst(a, md1) == dst(b, md1) && dst(a, md2) == dst(b, md2) && dst(a, md3) == dst(b, md3) && dst(a, md4) < dst(b, md4);
- }
- void cvp(vector <pii> v){
- for (auto x: v){
- cout<<x.first<<' '<<x.second<<"\n";
- }cout<<"\n";
- }
- int main()
- {
- ios::sync_with_stdio(0);
- cin.tie(0);
- cout.tie(0);
- cin>>t;
- vector <pii> R;//координаты Рахула
- vector <int> ans;
- vector <pii> T;//координаты Тины
- for (int act=0;act<t;++act){
- T.clear();
- R.clear();
- cin>>n>>m;
- for (int i = 0; i < n; ++i){
- for (int j = 0;j<m;++j){
- R.push_back({i, j});
- }
- }
- md1 = {(n-1)/2, (m-1)/2};
- md2 = {n/2, m/2};
- md4 = {(n-1)/2, m/2};
- md3 = {n/2, (m-1)/2};
- sort(R.begin(), R.end(), cmpR);
- T.resize(n*m);
- ans.resize(n*m);
- for (int i=0;i<n*m;++i){
- int x,y;
- if (R[i].first > md1.first){
- x = 0;
- }
- else x = n-1;
- if (R[i].second > md1.second){
- y = 0;
- }
- else y = m - 1;
- T[i] = {x,y};
- }
- for (int i=0;i<n*m;++i){
- //cout<<"k = "<<i<<"\n";
- ans[i] = dst(R[i], T[i]);
- }
- cv(ans);//вывести ответ
- }
- }
- /*
- 2
- 4 3
- 1 2
- */
Add Comment
Please, Sign In to add comment