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 ai, bi 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.
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.
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.
6 5 5 5 3 2 4 1 4 1 2 1 3 3 2 4 3 3 4
1 1
7 10 7 8 5 10 3 4 2 6 5 5 5 10 2 8 4 2 1 7 7 7
2 1 5
题目大意:
给出 n 个长方体,找出一个 或者两个拼接在一起的 最小边,使这个最小边最大。
思路:
贪心,排序后扫描一遍。需要注意的是贪心的规则:
如果两个长方体拼接在一起得到的最小边比原来的大 那么肯定是两个 较大的边拼接在一起。
如果存在多组 例如 2 7 8 3 7 8 5 7 8
那么最大的拼接长方体一定是 后面的两个,所以在扫描的时候只需要判断每个长方体后面的那个是否可以和当前拼接,如果可以,就去更新最大值
AC代码:
#include<bits/stdc++.h>
using namespace std;
struct node
{
int a,b,c;
int pos;
friend bool operator < (const node &aa,const node &bb)
{
if(aa.c==bb.c)
{
if(aa.b==bb.b)
{
return aa.a<bb.a;
}
return aa.b<bb.b;
}
return aa.c<bb.c;
}
}dd[100005];
void hehe(int &a,int &b,int &c)
{
int t;
if(a>b)
{
t=a;
a=b;
b=t;
}
if(a>c)
{
t=a;
a=c;
c=t;
}
if(b>c)
{
t=b;
b=c;
c=t;
}
return ;
}
int get_ans(int a,int b,int c)
{
int t;
t=min(a,b);
t=min(t,c);
return t;
}
void heheda(int &a,int &b)
{
int t;
if(a>b)
{
t=a;
a=b;
b=t;
}
}
int main()
{
int n;
scanf("%d",&n);
int tpp=0;
int aa,bb,cc;
for(int i=0;i<n;i++)
{
scanf("%d%d%d",&aa,&bb,&cc);
hehe(aa,bb,cc);
dd[i].a=aa;
dd[i].b=bb;
dd[i].c=cc;
dd[i].pos=i+1;
}
stable_sort(dd,dd+n);
int maxx=0;
int ff,ss;
int ans;
int tt;
for(int i=0;i<n;i++)
{
tt=get_ans(dd[i].a,dd[i].b,dd[i].c);
if(maxx<tt)
{
maxx=tt;
ans=1;
ff=dd[i].pos;
}
int j=i-1;
if(dd[i].b==dd[j].b)
{
if(dd[i].c==dd[j].c)
{
tt=dd[i].a+dd[j].a;
tpp=get_ans(dd[i].b,dd[i].c,tt);
if(maxx<tpp)
{
maxx=tpp;
ans=2;
ff=dd[i].pos;
ss=dd[j].pos;
}
}
}
}
printf("%d\n",ans);
if(ans==1)
printf("%d\n",ff);
else
{
heheda(ff,ss);
printf("%d %d",ff,ss);
}
}