Codeforces Round #378 (Div. 2) D. Kostya the Sculptor【贪心】

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 thei-th of them areai,bi andci. He can takeno 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 andci (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 printk distinct integers from1 to n — the numbers of stones which Zahar needs to choose. Consider that stones are numbered from1 ton 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 sphere1
  • 2 and 5, the size of the parallelepiped:3 × 2 × 8 or6 × 2 × 4 or3 × 4 × 4, the radius of the inscribed sphere1, or 1, or 1.5 respectively.
  • 2 and 6, the size of the parallelepiped:3 × 5 × 4, the radius of the inscribed sphere1.5
  • 4 and 5, the size of the parallelepiped:3 × 2 × 5, the radius of the inscribed sphere1
  • 5 and 6, the size of the parallelepiped:3 × 4 × 5, the radius of the inscribed sphere1.5

Or take only one stone:

  • 1 the size of the parallelepiped:5 × 5 × 5, the radius of the inscribed sphere2.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个长方体,我们可以选择,也可以不选择将两个长方体拼接起来(拼接需要两个长方体有一个面完全吻合的贴在一起),问怎样分配能够使得雕刻出来的球体最大。


思路:


1、首先找到了度娘,知道了这样一个道理:一个长方体的内接球的最大半径是长方体中最短边/2.那么我们将问题锁定到这个我们找到的长方体的最短边上来。


2、此时我们可以先处理不拼接时候,只选择一个长方体的最大方案,那么我们在输入的同时,维护一个最短边最大即可。

问题难在当拼接两个长方体的时候怎么办?

我们首先将每个长方体的三条边从大到小排序,分别存入a【i】.x,a【i】.y,a【i】.z,此时a【i】.z就是这个长方体的最短边。


3、然后我们考虑对a【i】进行排序 ,首先按照优先级为:

a【i】.x,a【i】.y,a【i】.z的顺序将a【i】从大到小的进行多元化排序。

那么此时得到的a【i】,如果有两个长方体的最长的两个边长度相同,那么这两个长方体的编号一定是相邻的,那我们此时将两个长方体拼接起来,这样使得两个长方体中的最小边变的更大了,达到贪心目的。

注意这里一个点,将这两条边长相加之后,可能就不是拼接出来的长方体的最小边长了,那么此时再将合并之后,判断一下哪个是最小边,进行维护即可。


Ac代码:

#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
struct node
{
    int x,y,z,pos;
}a[100050];
int w[5];
int cmp(node a,node b)
{
    if(a.x==b.x)
    {
        if(a.y==b.y)
        {
            return a.z>b.z;
        }
        else return a.y>b.y;
    }
    else return a.x>b.x;
}
int main()
{
    int n;
    while(~scanf("%d",&n))
    {
        int maxn=0;
        int ans1;
        for(int i=1;i<=n;i++)
        {
            scanf("%d%d%d",&w[0],&w[1],&w[2]);
            sort(w,w+3);
            a[i].x=w[2];
            a[i].y=w[1];
            a[i].z=w[0];
            a[i].pos=i;
            if(maxn<a[i].z)
            {
                maxn=a[i].z;
                ans1=i;
            }
        }
        sort(a+1,a+1+n,cmp);
        int contans=1;
        int ans2=-1;
        for(int i=1;i<=n-1;i++)
        {
            if(a[i].x==a[i+1].x&&a[i].y==a[i+1].y)
            {
                w[0]=a[i].z+a[i+1].z;
                w[1]=a[i].x;
                w[2]=a[i].y;
                sort(w,w+3);
                if(w[0]>maxn)
                {
                    contans=2;
                    ans2=a[i].pos;
                    ans1=a[i+1].pos;
                    maxn=w[0];
                }
            }
        }
        if(ans2==-1)
        {
            printf("%d\n%d\n",contans,ans1);
        }
        else
        {
            printf("%d\n%d %d\n",contans,ans1,ans2);
        }
    }
}





  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值