CodeForces 733D - Kostya the Sculptor

题目大意: 给定 n 个长方体的长宽高,你可以选择一个,或者选择两个长方体拼成一个完整的长方体。
问你最后想要的长方体有最大的内接圆,问你如何选择?

思路: 长方体的内接圆取决于它的最短边。
所以,每次必然是两个长方体的长边和次长边组成的面进行合并,然后组成的新的长方体的最短边就是这个长方体能得到的最大直径。

用一个map<pair<ll,ll>,pair<ll,ll>> 来维护最长边和次长边情况下的最短边的最大值以及其对应的编号。
最后每次插入只要查询有没有对应的长方体,然后用一个 maxx 来维护最大值。
根据最大值来输出结果。

#include <cstdio>
#include <string>
#include<iostream>
#include<vector>
#include <stack>
#include <queue>
#include <map>
#include <cstdlib>
#include<string.h>
#include <cstring>
#include <algorithm>

using namespace std;

typedef long long ll;
typedef pair<int, int>pii;
typedef pair<ll, ll> pll;
typedef pair<int, ll> pil;


int main()
{
    int n;
    scanf("%d", &n);
    map<pll, pll>ma;
    ll nomaxx = -1; int pos = -1;
    ll tmaxx = -1; int p1 = -1, p2 = -1;
    for (int i = 0; i < n; i++)
    {
        ll a[3];
        for (int j = 0; j < 3; j++)scanf("%I64d", &a[j]);
        sort(a, a + 3);
        if (nomaxx < a[0])
        {
            nomaxx = a[0];
            pos = i + 1;
        }
        pll tmp = pll(a[2], a[1]);
        ll b[3];
        b[0] = a[2], b[1] = a[1], b[0] = ma[tmp].first + a[0];
        sort(b, b + 3);
        if (ma[tmp].first!=0&&tmaxx < b[0])
        {
            tmaxx = b[0];
            p1 = ma[tmp].second;
            p2 = i + 1;
        }
        if (ma[tmp].first < a[0])
        {
            ma[tmp].second = i + 1;
            ma[tmp].first = a[0];
        }
    }
    if (nomaxx>tmaxx)
    {
        printf("1\n%d\n", pos);
    }
    else
    {
        printf("2\n%d %d\n", p1,p2);
    }
    //system("pause");
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值