*cf.4 贪心
3 seconds
256 megabytes
standard input
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 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.
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.
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.
6
5 5 5
3 2 4
1 4 1
2 1 3
3 2 4
3 3 4
1
1
7
10 7 8
5 10 3
4 2 6
5 5 5
10 2 8
4 2 1
7 7 7
2
1 5
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.
题意:
给出N个长方体,如果有两个长方体有两条边对应相等,即两个面的面积相同就可以把两个长方体粘起来,最多两个相粘,问最后那个或那两个可以有的最大内切球;
代码:
//排序;普通的暴力会超时。后来看了别人的代码。神奇。
//把每个长方体三条边从小到大排一下存入,以每个长方体最大的那条边从小到大排序如下。这样两个最大值和次大值对应相等的面必然相邻
//这样每次比较相邻的两个就好了。如果最小的和第二大的对应相等怎么办如:(2 3 4),(1 2 5),(2 3 6),输入数据的时候就排除了,就算合起来还是2,3 小边。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int n,flag1,flag2;
struct cub
{
int a,b,c,ra;
}cu[];
bool cmp(cub x,cub y) //排序
{
if(x.a==y.a&&x.b==y.b) return x.c<y.c;
if(x.a==y.a) return x.b<y.b;
return x.a<y.a;
}
int main()
{
int x,y,z;
while(scanf("%d",&n)!=EOF)
{
int ans=;
for(int i=;i<=n;i++)
{
scanf("%d%d%d",&x,&y,&z);
int xx=max(x,max(y,z)),zz=min(x,min(y,z)),yy=x+y+z-xx-zz;
cu[i].a=xx;
cu[i].b=yy;
cu[i].c=zz;
cu[i].ra=i;
if(zz>ans)
{
ans=zz;
flag1=i;
flag2=;
}
}
sort(cu+,cu++n,cmp);
for(int i=;i<=n;i++)
{
if(cu[i].a==cu[i-].a&&cu[i].b==cu[i-].b)
{
int Min=min(cu[i].c+cu[i-].c,min(cu[i].a,cu[i].b));
if(Min>ans)
{
ans=Min;
flag1=cu[i].ra;
flag2=cu[i-].ra;
}
}
}
if(flag2==) printf("1\n%d\n",flag1);
else printf("2\n%d %d\n",min(flag1,flag2),max(flag1,flag2));
}
return ;
}
*cf.4 贪心的更多相关文章
- CF/div2c/贪心
题目链接[http://codeforces.com/contest/749/problem/C] 题意:给出一个长度为n序列包含D和R,每一轮操作的先后顺序是1-n,规则是每一轮每个人有一次机会杀掉 ...
- CF - 高精度 + 贪心
Last year Bob earned by selling memory sticks. During each of n days of his work one of the two foll ...
- CF #374 (Div. 2) D. 贪心,优先队列或set
1.CF #374 (Div. 2) D. Maxim and Array 2.总结:按绝对值最小贪心下去即可 3.题意:对n个数进行+x或-x的k次操作,要使操作之后的n个数乘积最小. (1)优 ...
- CF 628C --- Bear and String Distance --- 简单贪心
CF 628C 题目大意:给定一个长度为n(n < 10^5)的只含小写字母的字符串,以及一个数d,定义字符的dis--dis(ch1, ch2)为两个字符之差, 两个串的dis为各个位置上字符 ...
- CF 949D Curfew——贪心(思路!!!)
题目:http://codeforces.com/contest/949/problem/D 有二分答案的思路. 如果二分了一个答案,首先可知越靠中间的应该大约越容易满足,因为方便把别的房间的人聚集过 ...
- CF #296 (Div. 1) B. Clique Problem 贪心(构造)
B. Clique Problem time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...
- CF 435B Pasha Maximizes(贪心)
题目链接: [传送门][1] Pasha Maximizes time limit per test:1 second memory limit per test:256 megabytes ...
- CF 115B Lawnmower(贪心)
题目链接: 传送门 Lawnmower time limit per test:2 second memory limit per test:256 megabytes Description ...
- [CF #288-C] Anya and Ghosts (贪心)
题目链接:http://codeforces.com/contest/508/problem/C 题目大意:给你三个数,m,t,r,代表晚上有m个幽灵,我有无限支蜡烛,每支蜡烛能够亮t秒,房间需要r支 ...
随机推荐
- css 基础---选择器
1.css基础 selector {property: value} eg: h1 {color:red; font-size:14px;} p { text-align: center; color ...
- 【C语言入门教程】目录/大纲
第一章 C语言编程基础 1.1 基本程序结构 1.2 函数库 和 链接 1.3 C语言“32个”关键字 第二章 数据类型.运算符和表达式 2.1 数据类型(5种基本数据类型),聚合类型与修饰符 2.2 ...
- C和指针 第七章 函数递归与迭代
C语言通过运行时堆栈支持递归函数的实现,递归函数时直接或者间接调用自身的函数,经常有人拿斐波那契实现当做递归的实现,然后这样做效率并不高. n < 1; Fib(1) =1 n = 2; F ...
- 64位操作系统 通过ODP.NET 访问ORACLE 11g
摘要:64位操作系统部署.NET 程序访问oracle时,无法连接问题.(注意:客户端是64位系统 ,服务端是否64位 还是32位无关.) 1.到oracle 官网搜索相关版本的 ODAC网址: ht ...
- 多线程更新UITableView时容易导致的问题
我请求同一个接口两次, 第一次是那缓存, 第二次是那网络数据在请求成功回调的主线程异步的, 先赋值数据源, 然后调用uitableview reloaddata的方法, 这时候问题来了 reloadd ...
- XCTest各种断言
XCTFail(format…) 生成一个失败的测试: XCTAssertNil(a1, format...)为空判断,a1为空时通过,反之不通过: XCTAssertNotNil(a1, forma ...
- Eclipse下无法自动编译,或者WEB-INF/classes目录下没文件,编译失败的解决办法(转载)
文章来源:http://www.cnblogs.com/xfiver/archive/2010/07/07/1772764.html 1. IOException parsing XML docum ...
- ORA-27101: shared memory realm does not exist
Oracle Error Tips by Burleson Consulting Oracle docs note this about ORA-27101: ORA-27101: shared me ...
- HBASE列族不能太多的真相 (一个table有几个列族就有几个 Store)
HRegionServer内部管理了一系列HRegion对象,每个HRegion对 应了table中的一个region,HRegion中由多 个HStore组成.每个HStore对应了Table中的一 ...
- PHP基础之POST与GET
post 与 get区别 *.Post传输数据时,不需要在URL中显示出来,而Get方法要在URL中显示.*.Post传输的数据量大,可以达到2M,而Get方法由于受到URL长度的限制,只能传递大约1 ...