Advertisement
FHVirus

Untitled

May 19th, 2021
266
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.28 KB | None | 0 0
  1. // Knapsack DP is harder than FFT.
  2. #include<bits/stdc++.h>
  3. using namespace std;
  4. typedef long long ll; typedef pair<int,int> pii; typedef pair<ll,ll> pll;
  5. #define ff first
  6. #define ss second
  7. #define pb emplace_back
  8. #define AI(x) begin(x),end(x)
  9. template<class I>bool chmax(I&a,I b){return a<b?(a=b,true):false;}
  10. template<class I>bool chmin(I&a,I b){return b<a?(a=b,true):false;}
  11. #ifdef OWO
  12. #define debug(args...) SDF(#args, args)
  13. #define OIU(args...) ostream& operator<<(ostream&O,args)
  14. #define LKJ(S,B,E,F) template<class...T>OIU(S<T...>s){O<<B;int c=0;for(auto i:s)O<<(c++?", ":"")<<F;return O<<E;}
  15. LKJ(vector,'[',']',i)LKJ(deque,'[',']',i)LKJ(set,'{','}',i)LKJ(multiset,'{','}',i)LKJ(unordered_set,'{','}',i)LKJ(map,'{','}',i.ff<<':'<<i.ss)LKJ(unordered_map,'{','}',i.ff<<':'<<i.ss)
  16. template<class...T>void SDF(const char* s,T...a){int c=sizeof...(T);if(!c){cerr<<"\033[1;32mvoid\033[0m\n";return;}(cerr<<"\033[1;32m("<<s<<") = (",...,(cerr<<a<<(--c?", ":")\033[0m\n")));}
  17. template<class T,size_t N>OIU(array<T,N>a){return O<<vector<T>(AI(a));}template<class...T>OIU(pair<T...>p){return O<<'('<<p.ff<<','<<p.ss<<')';}template<class...T>OIU(tuple<T...>t){return O<<'(',apply([&O](T...s){int c=0;(...,(O<<(c++?", ":"")<<s));},t),O<<')';}
  18. #else
  19. #pragma GCC optimize("Ofast")
  20. #define debug(...) ((void)0)
  21. #endif
  22. // 以上為模板
  23. // signed 跟 int 一樣
  24. // 有時會需要用到 long long 時
  25. // 有些人會 #define int long long
  26. // 但是 main 一定要回傳 int 所以就用 signed
  27. // 這是不太好的習慣,建議不要這樣做
  28. signed main(){
  29.     // 這行可以加速 cin cout,不用知道他在幹嘛照抄就好了
  30.     ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  31.     // 宣告一些東西
  32.     // 大部分人會習慣把 i j k 留給 for 迴圈
  33.     // 所以我用 b
  34.     int n;
  35.     vector<int> a, b;
  36.  
  37.     cin >> n;
  38.     // resize(n): 調整大小為 n
  39.     // assign(n, v): 把整個 vector 設為 n 個 v
  40.     a.resize(n);
  41.     b.assign(n, 0);
  42.     for(int i = 0; i < n; ++i) cin >> a[i];
  43.  
  44.     for(int i = 0; i < n; ++i){
  45.         // 變數也可以宣告在裡面
  46.         int cnt = 0;
  47.         // 如果只有一行的話也可以不用大括弧
  48.         // 當然這看個人習慣啦
  49.         for(int j = 0; j < n; ++j)
  50.             if(a[j] < a[i]) ++cnt;
  51.         b[cnt] = a[i];
  52.     }
  53.     for(int i = 0; i < n; ++i) cout << b[i] << ' ';
  54.     return 0;
  55. }
  56.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement