• CodeForces 589B-Layer Cake-暴力模拟


    刚看到这个题的想法是建图搜路,写出来了才发现这个做法不行,不能把每一个矩形看成不可分的点,因为最终的矩形可能两条边出现在不同矩形里。

    后来看了题解才明白直接暴力就行。关键是明白最终的矩形两条边都在所给矩形中出现。

     1 #include <cstdio>
     2 #include <algorithm>
     3 #include <cstring>
     4 
     5 using namespace std;
     6 
     7 typedef long long ll;
     8 const int INF = 0x3f3f3f3f;
     9 const int maxn = 4e3+10;
    10 struct cake
    11 {
    12     int w,l;
    13     cake(){}
    14     bool operator < (const cake &b) const
    15     {
    16         return l > b.l;
    17     }
    18 }ck[maxn];
    19 
    20 int N,len[maxn];
    21 
    22 int main()
    23 {
    24     scanf("%d",&N);
    25 
    26     for(int i=0;i<N;i++)
    27     {
    28         scanf("%d%d",&ck[i].w,&ck[i].l);
    29         if(ck[i].w > ck[i].l) swap(ck[i].w,ck[i].l);
    30     }
    31 
    32     sort(ck,ck+N);
    33 
    34     int m;
    35     int answ,ansl;
    36     ll ans = -INF;
    37 
    38     for(int i=0;i<N;i++)
    39     {
    40         m = 0;
    41         for(int j=0;j<N;j++)
    42         {
    43             if(ck[j].w >= ck[i].w)
    44             {
    45                 len[m++] = ck[j].l;
    46             }
    47         }
    48         for(int j=0;j<m;j++)
    49         {
    50             ll res = (ll)ck[i].w*len[j]*(j+1);
    51             if(res > ans)
    52             {
    53                 ans = res;
    54                 answ = ck[i].w;
    55                 ansl = len[j];
    56             }
    57         }
    58     }
    59     printf("%I64d
    %d %d
    ",ans,answ,ansl);
    60 
    61 }
  • 相关阅读:
    Redis常见7种使用场景(PHP)
    阻塞式I/O实现简单TCP通信
    telnet客户端程序
    TCP简单回射程序
    getsockname和getpeername函数
    close函数
    TCP时间获取程序
    listen函数
    基本套接字编程
    readline.c
  • 原文地址:https://www.cnblogs.com/helica/p/5229277.html
Copyright © 2020-2023  润新知