CodeForces 733D - Kostya the Sculptor

来源:互联网 发布:辐射4派普优化 编辑:程序博客网 时间:2024/06/06 04:04

题目大意: 给定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");}
0 0
原创粉丝点击