CodeForces - 733D 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 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
 
   
题意: 给你一些长方体,其中如果两个长方体的一个面面积相等,则这两个长方体可以粘起来,但是一个大的长方体最多可以由两个小长方体粘起来吗,当然也可以是一个长方体。让你求这个长方体的内接圆【注意: 是内接圆,一开始以为是外接圆,唉~】的最大半径的长方体的坐标 ,
如果是一个小长方体则输出
1
index1
如果是两个长方体粘起来的则输出
2
index1 index2
思路: 分析一下可以得到内接圆的半径的限制条件就是这个长方体de最短的一条边,最短边越短,半径越小,最短边越大 半径越大。所以要使最短边尽可能的长。
所以如果是两个长方体粘起来的情况,则一定是两个长方体的最长边和次长边组成的那一面粘起来。所以直接对按重要性先以最长边,其次是次长边,最后是最短边排序   所以只需要比较最短边!!!!!!!!!  说了这么多  就是比较最短边,但是要把粘起来的情况考虑进去!!
 
   
代码:
 
   
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
#define N 100005

using namespace std;

struct node
{
	int x,y,z,index;
}a[N];

bool cmp(node a,node b)
{
	if(a.x==b.x&&a.y==b.y) return a.z>b.z;
	else if(a.x==b.x) return a.y>b.y;
	else return a.x>b.x;
}

int main()
{
	int n;
	int i,j;
	int x,y,z;
	scanf("%d",&n);
	int maxx=-1;
	int index1=-1,index2=-1;
	for(i=1;i<=n;i++)
	{
		scanf("%d %d %d",&x,&y,&z);
		int sum=x+y+z;
		a[i].x=max(max(x,y),z);
		a[i].z=min(min(x,y),z);
		a[i].y=sum-a[i].x-a[i].z;
		a[i].index=i;
		if(a[i].z>maxx )
		{
			 maxx=a[i].z;
			 index1=i;
		}
	}
	sort(a+1,a+n+1,cmp);
	/*for(i=1;i<=n;i++)
	{
		printf("%d %d %d %d\n",a[i].index,a[i].x,a[i].y,a[i].z);
	}
	*/
	int left=1;
	int right=1;
	while(1)
	{
		if(left==n+1) break;
		right=left;
		while(a[left].x==a[right].x&&a[left].y==a[right].y) right++;
		right--;
		int sum;
		if(left==right)
		{
			sum=min(a[left].x,min(a[left].y,a[left].z));
			if(sum>maxx)
			{
				index1=a[left].index;
				maxx=sum;
				index2=-1;
			}
		}
		else
		{
			sum=min(min(a[left].x,a[left].y),a[left].z+a[left+1].z);
			if(sum>maxx)
			{
				maxx=sum;
				index1=a[left].index;
				index2=a[left+1].index;
			}
		}
		left=right+1;
	}
	if(index2==-1) printf("1\n%d\n",index1);
	else printf("2\n%d %d\n",index1,index2);
	return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
CodeForces - 616D是一个关于找到一个序列中最长的第k好子段的起始位置和结束位置的问题。给定一个长度为n的序列和一个整数k,需要找到一个子段,该子段中不超过k个不同的数字。题目要求输出这个序列最长的第k好子段的起始位置和终止位置。 解决这个问题的方法有两种。第一种方法是使用尺取算法,通过维护一个滑动窗口来记录\[l,r\]中不同数的个数。每次如果这个数小于k,就将r向右移动一位;如果已经大于k,则将l向右移动一位,直到个数不大于k。每次更新完r之后,判断r-l+1是否比已有答案更优来更新答案。这种方法的时间复杂度为O(n)。 第二种方法是使用枚举r和双指针的方法。通过维护一个最小的l,满足\[l,r\]最多只有k种数。使用一个map来判断数的种类。遍历序列,如果当前数字在map中不存在,则将种类数sum加一;如果sum大于k,则将l向右移动一位,直到sum不大于k。每次更新完r之后,判断i-l+1是否大于等于y-x+1来更新答案。这种方法的时间复杂度为O(n)。 以上是两种解决CodeForces - 616D问题的方法。具体的代码实现可以参考引用\[1\]和引用\[2\]中的代码。 #### 引用[.reference_title] - *1* [CodeForces 616 D. Longest k-Good Segment(尺取)](https://blog.csdn.net/V5ZSQ/article/details/50750827)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^koosearch_v1,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* [Codeforces616 D. Longest k-Good Segment(双指针+map)](https://blog.csdn.net/weixin_44178736/article/details/114328999)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^koosearch_v1,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值