zoukankan      html  css  js  c++  java
  • CodeForces 589B Layer Cake (暴力)

    题意:给定 n 个矩形是a*b的,问你把每一块都分成一样的,然后全放一块,高度都是1,体积最大是多少。

    析:这个题,当时并没有完全读懂题意,而且也不怎么会做,没想到就是一个暴力,先排序,先从大的开始选,如果大,那么数量少,如果小,数量就多,

    用一个multiset来排序,这样时间复杂度会低一点,每一个都算一下比它的大矩阵的数量,然后算体积,不断更新,最大值。

    代码如下:

    #pragma comment(linker, "/STACK:1024000000,1024000000")
    #include <cstdio>
    #include <string>
    #include <cstdlib>
    #include <cmath>
    #include <iostream>
    #include <cstring>
    #include <set>
    #include <queue>
    #include <algorithm>
    #include <vector>
    #include <map>
    #include <cctype>
    #include <stack>
    using namespace std ;
    
    typedef long long LL;
    typedef pair<int, int> P;
    const int INF = 0x3f3f3f3f;
    const double inf = 0x3f3f3f3f3f3f;
    const double PI = acos(-1.0);
    const double eps = 1e-8;
    const int maxn = 4e3 + 5;
    const int mod = 1e9 + 7;
    const int dr[] = {-1, 0, 1, 0};
    const int dc[] = {0, 1, 0, -1};
    int n, m;
    inline bool is_in(int r, int c){
        return r >= 0 && r < n && c >= 0 && c < m;
    }
    struct node{
        int x, y;
        bool operator < (const node &p) const{
            return x > p.x || (x == p.x && y < p.y);
        }
    };
    node a[maxn];
    multiset<int> sets;
    
    int main(){
        while(scanf("%d", &n) == 1){
            for(int i = 0; i < n; ++i){
                scanf("%d %d", &a[i].x, &a[i].y);
                if(a[i].x < a[i].y)  swap(a[i].x, a[i].y);
            }
            sort(a, a+n);
            sets.clear();
            int num = 0, ansx, ansy;
            LL ans = 0;
            for(int i = 0; i < n; ++i){
                sets.insert(a[i].y);
                ++num;
                int cnt = 0;
                for(auto &it : sets){
                    LL tmp = (LL)a[i].x * (LL)it * (LL)(num-cnt);
                    if(ans < tmp){
                        ans = tmp;
                        ansx = a[i].x;
                        ansy = it;
                    }
                    ++cnt;
                }
            }
    
            printf("%I64d
    ", ans);
            printf("%d %d
    ", ansx, ansy);
    
        }
        return 0;
    }
    
  • 相关阅读:
    个人作业——顶会热词进程1.3
    个人作业——顶会热词进程1.2
    每周总结(5.9)
    个人作业2——顶会热词进程1.1
    团队项目冲刺第10天
    CodeForces-1178F1 Short Colorful Strip 区间DP
    LOJ-2362 蚯蚓 队列优化
    Educational Codeforces Round 107 (Rated for Div. 2) G.Chips on a Board 倍增优化DP
    LOJ-2123 最短不公共子串 后缀自动机,子序列自动机
    LGR-084 C Reboot from Blue 贪心 DAG上DP最短路
  • 原文地址:https://www.cnblogs.com/dwtfukgv/p/5758584.html
Copyright © 2011-2022 走看看