Codeforces 733D D. Kostya the Sculptor By Assassin

D. Kostya the Sculptor
time limit per test3 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard 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 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.
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.5 respectively. 
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. 

思路:讲真的看到这个的时候真心有些蒙比,感谢胖巨的思路,
下面讲一下思路,很巧妙。

首先我们需要理解题意,我们要找到一个长方体的最大内切圆,首先我们明确这个内切圆的直径一定是最小的边长!那么我们这么存储,用一个结构体,有四个数,分别是从大到小的三个值,和当前是第几个。

然后我们排序!怎么排?按照第一位由大到小,之后按第二位由大到小,之后是第三位。为什么这样?我们看选取的过程,首先我们判断一下只是用1个的情况,就是枚举最大的最小边长。之后我们考虑组合的,每次只需要比较相邻的即可!而且只需要考虑两个结构体第一第二个数情况一样的情况!为甚恶魔?

我们去组合的时候怎么办,无非11对应是组合使最小值变大,那么如果出现其他对应情况呢?我们首先明确,第二个数一定大于等于第三个数,当这两个结构题存在一个第三个数值时,必定还是受这个第三个数的限制!而我们在遍历1的情况时的结果已经是这个最小值的情况,所以只需要考虑前两个相同最后一个都不同的组合情况!而且我们不难发现i和i+1的组合一定比1和i+2好!那么相当于每次主要比i和i+1就行了!
主要是这个思路真是神了!涨姿势!

#include<bits/stdc++.h>
#define input freopen("input.txt","r",stdin)
using namespace std;
typedef struct node{
    long long v1,v2,v3;
    long long pos;
}node;
int cmp(node x,node y){
    if(x.v1>y.v1) return 1;
    if(x.v1==y.v1&&x.v2>y.v2) return 1;
    if(x.v1==y.v1&&x.v2==y.v2&&x.v3>y.v3) return 1;
    return 0;
}
node a[100005];
long long bit[3];
int main(){
    //input;
    int n,i,j;
    while(scanf("%d",&n)!=EOF){
        for(i=1;i<=n;i++){
            scanf("%I64d%I64d%I64d",&bit[0],&bit[1],&bit[2]);
            sort(bit,bit+3);
            a[i].v1=bit[2];
            a[i].v2=bit[1];
            a[i].v3=bit[0];
            a[i].pos=i;
        }
        sort(a+1,a+1+n,cmp);
        long long ans=0,start,end,tmp=1;
        for(i=1;i<=n;i++){
            if(a[i].v3>ans){
                ans=a[i].v3;
                start=a[i].pos;
            }
        }
        for(i=1;i<n;i++){
            if(a[i].v1==a[i+1].v1&&a[i].v2==a[i+1].v2){
                if(min(a[i].v2,a[i].v3+a[i+1].v3)>ans){
                    ans=min(a[i].v2,a[i].v3+a[i+1].v3);
                    start=a[i].pos;
                    end=a[i+1].pos;
                    tmp=2;
                }
            }
        }
        if(tmp==1){
            cout<<tmp<<endl;
            cout<<start<<endl;
        }
        else{
            cout<<tmp<<endl;
            cout<<start<<" "<<end<<endl;
        }
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值