Korotkodul

C

Jan 10th, 2022 (edited)
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.17 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. using namespace std;
  12. using ll = long long;
  13. using ld = long double;
  14. using db = double;
  15. void cv(vector <int> &v){
  16. for (auto x: v) cout<<x<<' ';
  17. cout<<"\n";
  18. }
  19.  
  20. void cvl(vector <ll> &v){
  21. for (auto x: v) cout<<x<<' ';
  22. cout<<"\n";
  23. }
  24.  
  25.  
  26. void cvv(vector <vector <int> > &v){
  27. for (auto x: v) cv(x);
  28. cout<<"\n";
  29. }
  30. int t,n;
  31. vector <int> v;
  32.  
  33. vector <vector<int>> nd;
  34. map <int, vector<int>> var;
  35. vector <pair <int, vector<int> > > varV, ndV;
  36. map <int, int> bs, fr; //busy , free
  37.  
  38.  
  39. bool cmp( vector <int> a, vector <int> b){
  40. return a.size() < b.size();
  41. }
  42.  
  43. bool cmpV(pair <int, vector <int> > a, pair <int, vector <int> > b){
  44. return a.second.size() < b.second.size();
  45. //return a_sz < b_sz;
  46. }
  47.  
  48. map <int, int> cap; //capacity
  49. map <int, int> req; //reqired
  50.  
  51. bool cmpR(pair <int, vector <int>>a, pair <int, vector <int>>b){
  52. return req[a.first] < req[b.first];
  53. }
  54. //vector <int, int>
  55.  
  56. void ch(int x){
  57. int st=x;
  58. //cout<<"x y = "<<x<<' '<<y<<"\n";
  59. while (x >= 1){
  60. //cout<<"x = "<<x<<"\n";
  61. if (x >= 1 && x <= n){
  62. //cout<<"ok\n";
  63. nd[x-1].push_back(st);
  64. req[x]++;
  65. var[st].push_back(x);
  66.  
  67. }
  68. x /= 2;
  69. }
  70. //return 0;
  71. }
  72.  
  73. int main()
  74. {
  75. /*ios::sync_with_stdio(0);
  76. cin.tie(0);
  77. cout.tie(0);*/
  78. cin>>t;
  79. for (int i=0;i<t;++i){
  80. bool can = 1;
  81. cin>>n;
  82. cap.clear();
  83. req.clear();
  84. v.clear(); nd.clear();
  85. fr.clear();
  86. bs.clear();
  87. v.resize(n);
  88. nd.resize(n);
  89. var.clear();
  90. ndV.clear();
  91. varV.clear();
  92. //var.resize(n);
  93. //cout<<"v\n";
  94. for (int j=0;j<n;++j) cin>>v[j];
  95. for (int j = 0;j< n;++j){
  96. fr[v[j]]+=1;
  97. ch(v[j]);
  98. }
  99. //cv(v);
  100. sort(v.begin(), v.end());
  101. cout<<"v\n";
  102. cv(v);
  103.  
  104. cout<<"\n";
  105. //cout<<"var\n";
  106. for (auto x: var){
  107. //cout<<"("<<x.first<<"): "; cv(x.second);
  108. varV.push_back(x);
  109. }
  110.  
  111. cout<<"\n\n";
  112. for (int j = 0; j < n;++j){
  113. ndV.push_back({j+1, nd[j]});
  114. }
  115. sort(ndV.begin(), ndV.end(),cmpV);
  116. //sort(varV.begin(), varV.end(), cmpV);
  117. cout<<"nd\n";
  118. for (int j=0;j<n;++j){
  119. cout<<"("<<ndV[j].first<<"): ";
  120. cv(ndV[j].second);
  121. }
  122. cout<<"Var\n";
  123. for (int j=0;j<varV.size();++j){
  124. cout<<varV[j].first<<" : "; cv(varV[j].second);
  125. }
  126. cout<<"\n\n";
  127. //for (int )
  128. for (int j = 0; j < n;++j){
  129. if (ndV[j].second.empty()){
  130. can = 0;
  131. break;
  132. }
  133. sort(ndV.begin(), ndV.end() , cmpR);
  134. }
  135. if (can){
  136. cout<<"YES\n";
  137. }
  138. else cout<<"NO\n";
  139. }
  140. }
  141. /*
  142. 6
  143. 4
  144. 1 8 25 2
  145. 2
  146. 1 1
  147. 9
  148. 9 8 3 4 2 7 1 5 6
  149. 3
  150. 8 2 1
  151. 4
  152. 24 7 16 7
  153. 5
  154. 22 6 22 4 22
  155.  
  156. */
  157.  
Add Comment
Please, Sign In to add comment