题意:
小K是个打磨高手,她能把所有的石头打磨成球形。
小Z是小K的好朋友,她有n块非常珍贵的石头,想在小K生日那天送给小K,但最多送两块. 石头是长方体状的,第 i 块石头的长宽高分别为 ai, bi , ci.
小Z有一瓶宇宙级强力粘合胶,它可以用于粘合石头。小Z知道小K的爱好,为了让小K打磨出更大的石球,他决定动用这瓶强力胶。当然,如果他只送一块石头,强力胶就派不上用场。
如果小Z要送两块石头,她会把石头先黏合成一块再送给小K,但是为了礼物的美观,黏合后的石头必须仍然是一个长方体,换而言之,这两块石头必须至少有一个面是完全相同的,黏合时,把两个相同的面对齐后黏合在一起,从而得到了一块新的石头。
请你帮助小Z,怎样选择石头,可以让小K打磨出最大的球呢?
第一行一个整数 n (1 ≤ n ≤ 105).
接下来n行 ,每行3个整数 ai, bi , ci (1 ≤ ai, bi, ci ≤ 109),表示第i块石头的长宽高. 要注意,可能存在两块或者多块完全相同的石头,它们也是可以黏合的。
第一行一个整数 k (1 ≤ k ≤ 2) 表示小Z选择的石头s数量. 第2行k个整数 ,表示要选的石头编号(1到n).
若有多解,任意输出一组。
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中,若选择两块石头,有以下方案:
- 2号 和 4号, 合为: 3 × 2 × 5, 内接球半径为1
- 2号和5号, 合为: 3 × 2 × 8 或6 × 2 × 4 或 3 × 4 × 4,内接球半径分别为 1, 1, 1.5.
- 2号和6号, 合为: 3 × 5 × 4, 半径 1.5
- 4,5, 合为: 3 × 2 × 5, 半径 1
- 5,6, 合为: 3 × 4 × 5, 半径1.5
若选一块:
- 1号 : 5 × 5 × 5, 半径 2.5
- 2号: 3 × 2 × 4,半径1
- 3号: 1 × 4 × 1,半径 0.5
- 4号: 2 × 1 × 3,半径 0.5
- 5号: 3 × 2 × 4,半径 1
- 6号: 3 × 3 × 4, 半径 1.5
综上,选第1块石头能获得最大的球。
思路:
维护 map < 每个不同的面 , set <相同的面中第三边的长度 和 id >
代码:
#include <bits/stdc++.h>
using namespace std;
const int MAXN=1e5;
typedef struct MIAN{
int fis;int sec;
MIAN(int f=0,int s=0){
fis=f;sec=s;
}
bool operator < (const MIAN &a)const{
if(fis==a.fis)
return sec>a.sec;
return fis>a.fis;
}
}MIAN;
typedef struct CHOS{
int h;int id;
CHOS(int hh=0,int ii=0){
h=hh;id=ii;
}
bool operator < (const CHOS &a)const{
if(h==a.h)
return id>a.id;
return h>a.h;
}
}CHOS;
typedef struct Node{
int x;int y;int z;
Node(int xx=0,int yy=0,int zz=0){
x=xx;y=yy;z=zz;
}
}Node;
MIAN k;
Node node[MAXN+100];
map <MIAN,set<CHOS> > mapp;
set <CHOS> temp;
set <CHOS>::iterator it1,it2;
map <MIAN,bool> vis;
int n,xt,yt,zt,ans,ans1,ans2,a[4];
int maxn,intemp,tesintemp;
void output(){
cout<<ans<<endl<<ans1;
if(ans==2) cout<<' '<<ans2;
cout<<endl;
}
void solve(){
temp=mapp[k];
if(temp.size()==1){
it1=temp.begin();
intemp=min(it1->h,k.fis);
if(intemp>maxn){
maxn=intemp;
ans=1;ans1=it1->id;
}
}else{
it2=it1=temp.begin();++it2;
intemp=it1->h+it2->h;
intemp=min(intemp,k.fis);
if(intemp>maxn){
maxn=intemp;
ans=2;ans1=it1->id;ans2=it2->id;
}
}
tesintemp=max(tesintemp,intemp);
}
int main()
{
ios::sync_with_stdio(false);
cin>>n;
memset(node,0,sizeof(node));
ans=0;ans1=-1;ans2=-1;maxn=-1;
mapp.clear();
vis.clear();
for(int i=1;i<=n;i++){
cin>>a[0]>>a[1]>>a[2];sort(a,a+3);xt=a[0];yt=a[1];zt=a[2];
if(xt>maxn){
maxn=xt;
ans=1;ans1=i;
}
mapp[MIAN(yt,zt)].insert(CHOS(xt,i));
node[i]=Node(xt,yt,zt);
}
for(int i=1;i<=n;i++){
k.fis=node[i].y;k.sec=node[i].z;
if(!vis[k]){
solve();
mapp[k].clear();
vis[k]=1;
}
}
output();
}