codeforce#378D. Kostya the Sculptor

来源:互联网 发布:百度推广优化三尾狐 编辑:程序博客网 时间:2024/06/13 09:50

D. Kostya the Sculptor
time limit per test
3 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Kostya is a genial sculptor, he has an idea: to carve a marble sculpture in the shape of a sphere. Kostya has a friend Zahar who works at a career. Zahar knows about Kostya's idea and wants to present him a rectangular parallelepiped of marble from which he can carve the sphere.

Zahar has n stones which are rectangular parallelepipeds. The edges sizes of the i-th of them are aibi and ci. He can take no more than two stones and present them to Kostya.

If Zahar takes two stones, he should glue them together on one of the faces in order to get a new piece of rectangular parallelepiped of marble. Thus, it is possible to glue a pair of stones together if and only if two faces on which they are glued together match as rectangles. In such gluing it is allowed to rotate and flip the stones in any way.

Help Zahar choose such a present so that Kostya can carve a sphere of the maximum possible volume and present it to Zahar.

Input

The first line contains the integer n (1 ≤ n ≤ 105).

n lines follow, in the i-th of which there are three integers ai, bi and ci (1 ≤ ai, bi, ci ≤ 109) — the lengths of edges of the i-th stone. Note, that two stones may have exactly the same sizes, but they still will be considered two different stones.

Output

In the first line print k (1 ≤ k ≤ 2) the number of stones which Zahar has chosen. In the second line print k distinct integers from 1 to n — the numbers of stones which Zahar needs to choose. Consider that stones are numbered from 1 to n in the order as they are given in the input data.

You can print the stones in arbitrary order. If there are several answers print any of them.

题意:

给你n个长方形,让你找出2个或1个长方体,使得他们拼接成的长方体的内接圆半径最大(两个矩形拼接的条件是他们有一个面完全相同)

题解:

很容易想到一个长方体的内接圆半径是由他的最短的那条边决定的,

设长方体的边长从小到大分别为a,b,c,

只有用b*c这个面和别的长方体拼接,拼接后的长方体就是(a1+a2), b, c,这样才有可能使得拼接后的长方体内接圆半径更大,于是内接圆直径就是min(a1+a2, b, c).

于是,根据上述

我们读入的时候将长方体边长排序

然后sort 以c为第一关键字 以b为第二关键字 以a为第三关键字进行排序。

拍完序后的结构体中,i和i-1两个矩形要么有一个面相同,要么不相同,所以只要一个for的复杂度就可以了,不用两个for.


感悟:想多A两个题怎么就这么难。。。。


#include<bits/stdc++.h>using namespace std;const int maxn = 100005;struct Node{    long long l, mid, r, id;}a[maxn], b[maxn];bool cmp2(Node p, Node q){    if(p.r == q.r)    {        if(p.mid == q.mid)        {            return p.l < q.l;        }        else            return p.mid < q.mid;    }    else    {        return p.r < q.r;    }}int main(){    int n;    long long pp[4];    while(cin >> n)    {        long long ma = -1;        long long mama = -1;        int sel;        for(int i = 1; i <= n; i++)        {            scanf("%I64d%I64d%I64d", &a[i].l, &a[i].mid, &a[i].r);            a[i].id = i;            pp[0] = a[i].l;            pp[1] = a[i].mid;            pp[2] = a[i].r;            sort(pp, pp + 3);            a[i].l = pp[0];            a[i].mid = pp[1];            a[i].r = pp[2];            long long tem2 = pp[0];            if(tem2 > mama)            {                mama = tem2;                sel = i;            }        }        sort(a+1, a + n + 1, cmp2);        int id1 = -1, id2 = -1;        int pre = 1;        for(int i = 2; i <= n; i++)        {            if(a[i].r == a[pre].r && a[i].mid == a[pre].mid)            {                if(min(a[i].l + a[pre].l, min(a[i].mid, a[i].r)) > ma)                {                    ma = min(a[i].l + a[pre].l, min(a[i].mid, a[i].r));                    id1 = a[pre].id;                    id2 = a[i].id;                }            }            pre = i;        }        if(ma >= mama)        {            cout << 2 <<endl;            cout << id1 << " " << id2 << endl;        }        else        {            cout << 1 << endl;            cout << sel << endl;        }    }    return 0;}





0 0