Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- const int N = 5e3+5;
- struct pt{
- int c, r, d, cs;
- };
- bool temp1(pt a, pt b){
- return a.d > b.d || (a.d == b.d && a.r >= b.r);
- }
- bool temp2(pt a, pt b){
- return a.r*a.d > b.r*b.d;
- }
- int n;
- pt a[N];
- void Tower1(){
- freopen("TOWERi.txt", "w", stdout);
- int TowerMax[N];
- int res, trace[N];
- sort(a+1, a+n+1, temp1);
- for(int i = 1; i <= n; ++i){
- TowerMax[i] = 1;
- for(int j = 1; j <= i-1; ++j){
- if(a[j].r >= a[i].r && a[j].d >= a[i].d)
- if(TowerMax[i] < TowerMax[j]+1){
- TowerMax[i] = TowerMax[j]+1;
- trace[i] = j;
- }
- }
- }
- res = max_element(TowerMax + 1, TowerMax + n + 1) - TowerMax;
- vector<pt> kq;
- while(res != 0){
- kq.push_back(a[res]);
- res = trace[res];
- }
- cout << kq.size() << '\n';
- for(int i = kq.size()-1; i >= 0; --i)
- cout << kq[i].cs << ' ' << kq[i].d << ' ' << kq[i].r << ' ' << kq[i].c << '\n';
- }
- void Tower2(){
- freopen("TOWER2.txt", "w", stdout);
- int TowerMax[N];
- int res, trace[N];
- sort(a+1, a+n+1, temp2);
- for(int i = 1; i <= n; ++i){
- TowerMax[i] = a[i].c;
- for(int j = 1; j <= i-1; ++j){
- if(a[j].r >= a[i].r && a[j].d >= a[i].d)
- if(TowerMax[i] < TowerMax[j]+a[i].c){
- TowerMax[i] = TowerMax[j]+a[i].c;
- trace[i] = j;
- }
- }
- }
- res = max_element(TowerMax + 1, TowerMax + n + 1) - TowerMax;
- vector<pt> kq;
- while(res != 0){
- kq.push_back(a[res]);
- res = trace[res];
- }
- cout << kq.size() << '\n';
- for(int i = kq.size()-1; i >= 0; --i)
- cout << kq[i].cs << ' ' << kq[i].d << ' ' << kq[i].r << ' ' << kq[i].c << '\n';
- }
- int main()
- {
- //freopen("a.txt", "r", stdin);
- ios_base::sync_with_stdio(false);
- cin.tie(0); cout.tie(0);
- cin >> n;
- for(int i = 1; i <= n; ++i){
- vector<int> t(3);
- for(int j = 0; j < 3; ++j)
- cin >> t[j];
- sort(t.begin(), t.end());
- a[i].c = t[0];
- a[i].r = t[1];
- a[i].d = t[2];
- a[i].cs = i;
- }
- Tower1();
- Tower2();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment