codeforces 733D Kostya the Sculptor(贪心)

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.

题意:给你n个矩形,当它们任意一个面积相同时可以合并,最多合并两个,问你组成最大内切求需要哪几个矩形组合,如果一个矩形就能组成

最大那么就输出1然后它的下表,如果需要两个(最多两个)输出2然后它们的下标。

这题作为d题是挺简单的,思路简单构成的矩形内切圆大小取决于它的最小边,所以如果拿最小边那个面去合成的话最多也不会超过最小边,

所以要拿最大边和次大边组合才有可能得到大的。于是处理一下3个边从大到小排序一下,在将这些点从大到小排序一下。先记录一个矩形时

最大结果的下标是多少, 再考虑两个的时候大边于次大边这个面组合,最大内切圆半径为min(sum , s[i].y) (sum表示两最小边之和,s[i].y

表示次小边)。大致就是这样的思路。

#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
const int M = 1e5 + 10;
typedef long long ll;
struct ss {
    ll x , y , z , num;
}s[M];
bool cmp(ss a , ss b) {
    if(a.x == b.x)
        return a.y > b.y;
    return a.x > b.x;
}
int main()
{
    int n;
    cin >> n;
    ll MAX = 0;
    int temp = 0;
    for(int i = 0 ; i < n ; i++) {
        ll a , b , c;
        cin >> a >> b >> c;
        ll sum = a + b + c;
        s[i].x = max(a , max(b , c));
        s[i].z = min(a , min(b , c));
        s[i].y = (sum - s[i].x - s[i].z);
        s[i].num = i;
        if(MAX < s[i].z) {
            temp = i;
            MAX = s[i].z;
        }
    }
    sort(s , s + n , cmp);
    ll sum2 = 0;
    int l = 0;
    int r = l;
    int l2 = l;
    for(int i = 0 ; i < n - 1 ; i++) {
        if(s[i].x == s[i + 1].x && s[i].y == s[i + 1].y) {
            l = i;
            sum2 = s[i].z + s[i + 1].z;
            if(MAX < min(sum2 , s[i].y)) {
                MAX = min(sum2 , s[i].y);
                r = i + 1;
                l2 = l;
            }
        }
    }
    if(r - l2 >= 1) {
        cout << r - l2 + 1 << endl;
        for(int i = l2 ; i <= r ; i++) {
            cout << s[i]. num + 1 << ‘ ‘;
        }
    }
    else {
        cout << 1 << endl;
        cout << temp + 1 << endl;
    }
    return 0;
}
时间: 2024-12-18 22:07:14

codeforces 733D Kostya the Sculptor(贪心)的相关文章

CodeForces 733D Kostya the Sculptor

排序.把每一个长方体拆成$6$个做,然后排序做即可. #pragma comment(linker, "/STACK:1024000000,1024000000") #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> #include<vector> #include<map> #include<set> #inc

CF733D 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 frien

Kostya the Sculptor

Kostya the Sculptor 题目链接:http://codeforces.com/problemset/problem/733/D 贪心 以次小边为第一关键字,最大边为第二关键字,最小边为第三关键字排序,每次只需要找次小边和最大边均相同,最小边最大的两项即可. 因为用Python遇到很多问题,切片操作a[i:j]是左闭右开区间[i,j) 代码如下: 1 n = int(input()) 2 a = [] 3 ans,u,v = 0,-1,-1 4 for i in range(n):

Codeforces 442B Andrey and Problem(贪心)

题目链接:Codeforces 442B Andrey and Problem 题目大意:Andrey有一个问题,想要朋友们为自己出一道题,现在他有n个朋友,每个朋友想出题目的概率为pi,但是他可以同时向多个人寻求帮助,不过他只能要一道题,也就是如果他向两个人寻求帮助,如果两个人都成功出题,也是不可以的. 解题思路:贪心,从概率最大的人开始考虑,如果询问他使得概率变大,则要询问. #include <cstdio> #include <cstring> #include <a

Codeforces Round #300-Tourist&#39;s Notes(贪心)

Tourist's Notes Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submit Status Description A tourist hiked along the mountain range. The hike lasted for n days, during each day the tourist noted height above the sea level

Codeforces 432E Square Tiling(构造+贪心)

我们通常这么写 using (SqlDataReader drm = sqlComm.ExecuteReader()) { drm.Read();//以下把数据库中读出的Image流在图片框中显示出来. MemoryStream ms = new MemoryStream((byte[])drm["Logo"]); Image img = Image.FromStream(ms); this.pictureBox1.Image = img; } 我的写数据 private void b

Codeforces 798D Mike and distribution - 贪心

Mike has always been thinking about the harshness of social inequality. He's so obsessed with it that sometimes it even affects him while solving problems. At the moment, Mike has two sequences of positive integers A = [a1, a2, ..., an] and B = [b1, 

codeforces 349B Color the Fence 贪心,思维

1.codeforces 349B    Color the Fence 2.链接:http://codeforces.com/problemset/problem/349/B 3.总结: 刷栅栏.1-9每个字母分别要ai升油漆,问最多可画多大的数字. 贪心,也有点考思维. #include<bits/stdc++.h> using namespace std; #define LL long long #define INF 0x3f3f3f3f int main() { int v,a[1

codeforces 343C Read Time 二分 + 贪心

http://codeforces.com/problemset/problem/343/C 题意: 有一些磁头,给出了起始的位置,给出了一些磁盘中需要访问的地点.求这些磁头移动的最小的次数. 思路: 二分找出满足要求的最小的时间,对于当前尝试的时间进行贪心判断是否可用.对于贪心,因为每一个磁头都需要读到还没有人读过的最左边的地方.如果这个都不能满足,那么这个时间是不可以的. 在这基础上,对于同样的这么多时间,尽可能的让这个磁头读到能读到的最右边,这样就可以将还没有读过的地方尽可能的往右推. 如