Codeforces Round #378 (Div. 2) D. Kostya the Sculptor
来源:互联网 发布:广联达软件官网 编辑:程序博客网 时间:2024/05/16 17:36
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.
65 5 53 2 41 4 12 1 33 2 43 3 4
11
710 7 85 10 34 2 65 5 510 2 84 2 17 7 7
21 5
题目大意:
给出 n 个长方体,找出一个 或者两个拼接在一起的 最小边,使这个最小边最大。
思路:
贪心,排序后扫描一遍。需要注意的是贪心的规则:
如果两个长方体拼接在一起得到的最小边比原来的大 那么肯定是两个 较大的边拼接在一起。
如果存在多组 例如 2 7 8 3 7 8 5 7 8
那么最大的拼接长方体一定是 后面的两个,所以在扫描的时候只需要判断每个长方体后面的那个是否可以和当前拼接,如果可以,就去更新最大值
AC代码:
#include<bits/stdc++.h>using namespace std;struct node{ int a,b,c; int pos; friend bool operator < (const node &aa,const node &bb) { if(aa.c==bb.c) { if(aa.b==bb.b) { return aa.a<bb.a; } return aa.b<bb.b; } return aa.c<bb.c; }}dd[100005];void hehe(int &a,int &b,int &c){ int t; if(a>b) { t=a; a=b; b=t; } if(a>c) { t=a; a=c; c=t; } if(b>c) { t=b; b=c; c=t; } return ;}int get_ans(int a,int b,int c){ int t; t=min(a,b); t=min(t,c); return t;}void heheda(int &a,int &b){ int t; if(a>b) { t=a; a=b; b=t; }}int main(){ int n; scanf("%d",&n); int tpp=0; int aa,bb,cc; for(int i=0;i<n;i++) { scanf("%d%d%d",&aa,&bb,&cc); hehe(aa,bb,cc); dd[i].a=aa; dd[i].b=bb; dd[i].c=cc; dd[i].pos=i+1; } stable_sort(dd,dd+n); int maxx=0; int ff,ss; int ans; int tt; for(int i=0;i<n;i++) { tt=get_ans(dd[i].a,dd[i].b,dd[i].c); if(maxx<tt) { maxx=tt; ans=1; ff=dd[i].pos; } int j=i-1; if(dd[i].b==dd[j].b) { if(dd[i].c==dd[j].c) { tt=dd[i].a+dd[j].a; tpp=get_ans(dd[i].b,dd[i].c,tt); if(maxx<tpp) { maxx=tpp; ans=2; ff=dd[i].pos; ss=dd[j].pos; } } } } printf("%d\n",ans); if(ans==1) printf("%d\n",ff); else { heheda(ff,ss); printf("%d %d",ff,ss); }}
- Codeforces Round #378 (Div. 2) D. Kostya the Sculptor【贪心】
- Codeforces Round #378 (Div. 2)-D. Kostya the Sculptor(multiset)
- Codeforces Round #378 (Div. 2)D. Kostya the Sculptor
- Codeforces Round #378 (Div. 2) D. Kostya the Sculptor(乱搞)
- Codeforces Round #378 (Div. 2) D. Kostya the Sculptor
- Codeforces Round #378 (Div. 2) D Kostya the Sculptor
- Codeforces Round #378 (Div. 2) -- D. Kostya the Sculptor (STL水题)
- Codeforces Round #378 (Div. 2) D. Kostya the Sculptor(STL运用)
- Codeforces Round #378 (Div. 2) D. Kostya the Sculptor __ data structures、map<ii, priority_queue<ii>>
- Kostya the Sculptor Codeforces Round#378-D(逻辑+排序)
- 【25.47%】【codeforces 733D】Kostya the Sculptor
- 【Codeforces 733D】 Kostya the Sculptor【贪心】
- Codeforces 733D Kostya the Sculptor 贪心
- codeforces 733D Kostya the Sculptor
- Codeforces 733D Kostya the Sculptor
- CodeForces 733D Kostya the Sculptor
- codeforces 733D. Kostya the Sculptor
- CodeForces 733D - Kostya the Sculptor
- Python菜鸟--continue 语句
- Java单例设计模式
- 二值化连通区域相关matlab命令
- Java 计算日期相隔天数和相差的小时数
- hiho1284机会渺茫-map
- Codeforces Round #378 (Div. 2) D. Kostya the Sculptor
- WordPress在SAE环境上传文件至storage存储
- 网站被挂木马与777权限的奥妙
- innodb存储引擎中不同sql在不同隔离级别下锁的比较
- 宏观角度看数字编码
- jfinal事物回滚,@Before(Tx.class)和Db.tx(new IAtom() { })
- 廖雪峰Python教程 学习笔记4 Python基础
- Qt调用quazip来解压和压缩文件
- VS 2015 编译一些库的时候,出现 error “fatal error C1189: #error: Macro definition of snprintf conflicts with St