Codeforces Round #378 (Div. 2) && codeforces 733D(思维枚举)

54 篇文章 0 订阅
42 篇文章 0 订阅



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
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.


题意:给你n个长方体,任意两个长方体如果有一个面长跟宽完全相同就可以把他黏在一起,让你找出让石头体积最大的方案,hint里提醒你体积由内接球决定,内接球又由长方体最短的边决定,输出由几个长方体构成的,如果是两个的话输出由哪两个长方体决定的;

思路:唉,其实差不多想到了方法,就是没转过弯来。。功力还是不够啊!求最大体积,就是求最大内接圆就行,也就是求某个长方体最短的那个边最大,所以记录每个长方体最短的边就行。如果两个长方体拼接在一起的话,那么有用的拼接就是拼最长的边跟第二长边的那个面,因为一开始单个长方体,已经用最短的边代表他的体积了。。如果你拼接有最短边的那个面,他的内接球根本不会变,就算你别的边再长,这个最短的还是不变。你拼接另外两个边,可以让最短的边变长。。。注意拼接后,要找拼接后边长的那个边跟原来第二长的边比较,因为这时候可能原来第二长的边就是最长的边了。。。所以按照最长的边 > 次长边 > 最短边的优先级顺序进行排序(因为我们要找的是最长跟次长边有没有相同的)

能想到不用管最短的那个边,只找其余两条边相同的就可以a了。。唉,路还很长、、、

#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
using namespace std;
const int maxn = 1e5 +5;
struct node
{
    int a, b, c, id;  //记录原来是第几个长方体
}edge[maxn];
int cmp(node a, node b)
{
    if(a.c == b.c)
    {
        if(a.b == b.b)
            return a.a > b.a;
        else
            return a.b > b.b;
    }
    else
        return a.c > b.c;
}
int temp[3];
int main()
{
    int n, index, flag = 0, max1 = -1;
    scanf("%d", &n);
    for(int i = 1; i <= n; i++)
    {
        scanf("%d%d%d", &temp[0], &temp[1], &temp[2]);
        sort(temp, temp+3);
        edge[i].a = temp[0]; edge[i].b = temp[1]; edge[i].c = temp[2],edge[i].id = i;
        if(max1 < edge[i].a)
        {
            index = i;
            max1 = edge[i].a;
        }
    }
    sort(edge+1, edge+1+n, cmp);
    for(int i = 2; i <= n; i++)
    {
        if(edge[i].b == edge[i-1].b && edge[i].c == edge[i-1].c)
        {
            int ans = min(edge[i].b, edge[i].a+edge[i-1].a); //这里很重要,因为最短的边可能会变化
          //  cout << ans << endl;
            if(ans > max1)
            {
                max1 = ans;
                flag = 1;
                index = i;
            }
        }
    }
    if(!flag)
        printf("1\n"), printf("%d\n", index);
    else
        printf("2\n"), printf("%d %d\n", edge[index].id, edge[index-1].id);
    return 0;
}<span style="color:#ff0000;">
</span>

q巨不到十分钟就给a了。。他用map写的,还不能很好的理解,希望日后可以理解:

#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<map>
using namespace std;
map<pair<int,int>,vector<pair<int,int> > >mp;
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        int r[3];
        for(int j=0;j<3;j++)
            scanf("%d",&r[j]);
        sort(r,r+3);
        for(int j=0;j<3;j++)
        {
            mp[make_pair(r[0],r[1])].push_back(make_pair(-r[2],i));
            mp[make_pair(r[0],r[2])].push_back(make_pair(-r[1],i));
            mp[make_pair(r[1],r[2])].push_back(make_pair(-r[0],i));
        }
    }
    for(auto itr=mp.begin();itr!=mp.end();itr++)
    {
        itr->second.push_back(make_pair(0,0));
        sort(itr->second.begin(),itr->second.end());
        itr->second.erase(unique(itr->second.begin(),itr->second.end()),itr->second.end());
    }
    int res=0;
    pair<int,int>ans=make_pair(0,0);
    for(auto itr=mp.begin();itr!=mp.end();itr++)
    {
        int tmp=min(itr->first.first,itr->first.second);
        tmp=min(tmp,-(itr->second[0].first+itr->second[1].first));
        if(res<tmp)
        {
            res=tmp;
            ans=make_pair(itr->second[0].second,itr->second[1].second);
        }
    }
    //printf("%d\n",res);
    if(!ans.second)printf("1\n%d\n",ans.first);
    else printf("2\n%d %d\n",ans.first,ans.second);
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值