Codeforces Round #378 (Div. 2) D Kostya the Sculptor

来源:互联网 发布:手机进销存软件 编辑:程序博客网 时间:2024/06/05 20:49
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.

Examples
input
65 5 53 2 41 4 12 1 33 2 43 3 4
output
11
input
710 7 85 10 34 2 65 5 510 2 84 2 17 7 7
output
21 5
Note

In the first example we can connect the pairs of stones:

  • 2 and 4, the size of the parallelepiped: 3 × 2 × 5, the radius of the inscribed sphere 1

  • 2 and 5, the size of the parallelepiped: 3 × 2 × 8 or 6 × 2 × 4 or 3 × 4 × 4, the radius of the inscribed sphere 1, or 1, or 1.5respectively.

  • 2 and 6, the size of the parallelepiped: 3 × 5 × 4, the radius of the inscribed sphere 1.5

  • 4 and 5, the size of the parallelepiped: 3 × 2 × 5, the radius of the inscribed sphere 1

  • 5 and 6, the size of the parallelepiped: 3 × 4 × 5, the radius of the inscribed sphere 1.5

Or take only one stone:

  • 1 the size of the parallelepiped: 5 × 5 × 5, the radius of the inscribed sphere 2.5

  • 2 the size of the parallelepiped: 3 × 2 × 4, the radius of the inscribed sphere 1

  • 3 the size of the parallelepiped: 1 × 4 × 1, the radius of the inscribed sphere 0.5

  • 4 the size of the parallelepiped: 2 × 1 × 3, the radius of the inscribed sphere 0.5

  • 5 the size of the parallelepiped: 3 × 2 × 4, the radius of the inscribed sphere 1

  • 6 the size of the parallelepiped: 3 × 3 × 4, the radius of the inscribed sphere 1.5

It is most profitable to take only the first stone.


题意:给出n个长方体,给出每个长方体的长宽高,可以选择两个长方体然后粘合成一个长方体(PS:要粘合两个长方体,两个长方体至少要有一个相同的面),也可以只选一个长方体。要使选出的长方体的内切球体的半径达到最大,输出球体半径。


分析:只选一个的情况只要,要输入数据的时候计算一下就行了,关键是考虑粘合的情况。只有有一个面相同的两个长方体才能粘合,那么可以用一个二维映射映射第3边,把两个长方体的第三边相加即是粘合后长方体的第三边,然后就可以算出粘合后长方体的内切球体的半径了,虽然1 ≤ ai, bi, ci ≤ 109 ,但是 1 ≤ n ≤ 105  ,所以要存的数并不多。


#include <bits/stdc++.h>using namespace std;typedef pair<int,int> pii;typedef vector<pii> VI;map<int, map<int,VI> > mp;int main(){    int n, f = -1, s = -1;    double ans = 0;    scanf("%d", &n);        int x[3];    for(int i = 0; i < n; i++)    {        scanf("%d%d%d", &x[0], &x[1], &x[2]);        sort(x, x+3);        mp[x[0]][x[1]].push_back(pii(x[2], i));        mp[x[0]][x[2]].push_back(pii(x[1], i));        mp[x[1]][x[2]].push_back(pii(x[0], i));        double r = (double)x[0] / 2;        if(r > ans)        {            f = i;            ans = r;        }    }        for(auto it1 = mp.begin(); it1 != mp.end(); ++it1)    {        for(auto it2 = it1->second.begin(); it2 != it1->second.end(); ++it2)        {            sort(it2->second.begin(), it2->second.end(), greater<pii>() );            for(int i = 0; i < it2->second.size() - 1; i++)            {                int j = i + 1;                if(it2->second[i].second == it2->second[j].second) continue;                int mr = min(it1->first, it2->second[i].first + it2->second[j].first);                double r = (double)mr / 2;                if(ans < r)                {                    ans = r;                    f = it2->second[i].second;                    s = it2->second[j].second;                }                break;            }        }    }    int k = s == -1 ? 1 : 2;    printf("%d\n", k);    printf("%d", f + 1);    if(k == 2)        printf(" %d", s + 1);    puts("");        return 0;}

0 0