Kostya the Sculptor

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
6
5 5 5
3 2 4
1 4 1
2 1 3
3 2 4
3 3 4
output
1
1
input
7
10 7 8
5 10 3
4 2 6
5 5 5
10 2 8
4 2 1
7 7 7
output
2
1 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.

分析:map存储即可;

   其实只要把对于最大的两个,保存最小的即可,因为这样最小值才能变大,所以结构体就行;

代码:

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <climits>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <vector>
#include <list>
#define rep(i,m,n) for(i=m;i<=n;i++)
#define rsp(it,s) for(set<int>::iterator it=s.begin();it!=s.end();it++)
#define mod 1000000007
#define inf 0x3f3f3f3f
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ll long long
#define pi acos(-1.0)
#define pii pair<int,int>
#define Lson L, mid, ls[rt]
#define Rson mid+1, R, rs[rt]
#define sys system("pause")
#define freopen freopen("in.txt","r",stdin)
const int maxn=1e5+10;
using namespace std;
ll gcd(ll p,ll q){return q==0?p:gcd(q,p%q);}
ll qpow(ll p,ll q){ll f=1;while(q){if(q&1)f=f*p;p=p*p;q>>=1;}return f;}
inline ll read()
{
    ll x=0;int f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
int n,m,k,t,ans1,ans2;
map<pii,pii>pq;
double ma;
int main()
{
    int i,j;
    scanf("%d",&n);
    rep(i,1,n)
    {
        int a,b,c;
        a=read(),b=read(),c=read();
        if(a>b)swap(a,b);
        if(a>c)swap(a,c);
        if(b>c)swap(b,c);
        if(ma<min({((double)c+pq[mp(a,b)].fi)/2,(double)a/2,(double)b/2}))
        {
            ma=min({((double)c+pq[mp(a,b)].fi)/2,(double)a/2,(double)b/2});
            ans1=i,ans2=pq[mp(a,b)].se;
        }
        if(pq[mp(a,b)].fi<c)
        {
            pq[mp(a,b)]=mp(c,i);
        }
        //
        if(ma<min({((double)b+pq[mp(a,c)].fi)/2,(double)a/2,(double)c/2}))
        {
            ma=min({((double)b+pq[mp(a,c)].fi)/2,(double)a/2,(double)c/2});
            ans1=i,ans2=pq[mp(a,c)].se;
        }
        if(pq[mp(a,c)].fi<b)
        {
            pq[mp(a,c)]=mp(b,i);
        }
        //
        if(ma<min({((double)a+pq[mp(b,c)].fi)/2,(double)b/2,(double)c/2}))
        {
            ma=min({((double)a+pq[mp(b,c)].fi)/2,(double)b/2,(double)c/2});
            ans1=i,ans2=pq[mp(b,c)].se;
        }
        if(pq[mp(b,c)].fi<a)
        {
            pq[mp(b,c)]=mp(a,i);
        }
    }
    puts(ans2?"2":"1");
    printf("%d",ans1);
    if(ans2)printf(" %d",ans2);
    //system("Pause");
    return 0;
}
posted @ 2016-11-02 00:30  mxzf0213  阅读(323)  评论(0编辑  收藏  举报