For n==100. 1,1,2 or 1,2,2 a large number of duplicate shapes of the same data, CMP function last item if the expression is equal, the entire program crashes
The Std::sort call process has not been carefully analyzed, so this is not a good idea. , Mark later studies
Because the title asks you to pick one or two parallelepiped, then go to the minimum of each parallelepiped length and width, and then go to the maximum value in the minimum value.
It's easy to think of violence, if two parallelepiped can be combined, then we calculate the minimum value of the merge directly, because we know at this point
After merging, the minimum value is added.
So we're going to find a collection of all the parallelepiped that can merge a polygon,
Here is a vague place, that is, for each parallelepiped, we choose which side of it, of course, only three different faces
We have found the following facts
1,2,3==3,2,1==2,3,1 size of the parallelepiped is the same thing, but this has brought us a lot of trouble.
Because we think of the same thing differently 3 times, and each time we think about three sides at first. It's messy.
But to think about it, we don't really have to think about the two sides of the 1,3, because you're stacking the two parallelepiped, adding only the second big or maximum value.
The minimum value has not changed. And only the minimum value contributes to the answer, so we want to make the other two dimensions in addition to the minimum to form a plane and then consider whether it can be
Parallelepiped overlay to increase the minimum value to achieve the purpose of increasing the contribution to the answer
So we need to sort each parallelepiped size from small to large, and then we want to sort the parallelepiped overall, and then the second big and the maximum are equal as close together as possible.
This is good to deal with, this is the dictionary order, to see you focus on which element of the priority selection, think carefully can understand
This code experience, remember to switch directories to the source file root directory, otherwise will error. Variables that can be manipulated with an array index (subscript operation) We try not to alias, with for simple operation
Code:
#include <cstdio>#include<algorithm>using namespacestd;intN;Const intmaxn=1e5+7;structnode{inta[3]; intindex;};BOOLCMP (node A,node b) {if(a.a[2]!=b.a[2]){ returna.a[2]<b.a[2]; } if(a.a[1]!=b.a[1]){ returna.a[1]<b.a[1]; } //if (a.a[2]!=b.a[2]) {//return a.a[2]<b.a[2]; // } returna.a[0]<b.a[0]; //all equal when it comes back to what//that's how I understand it now.//If the CMP is true then sort does not swap, and if sort is false then we will exchange//when exactly equal, I think there's no need to exchange//should we arrange them in the order of 2,1,0? //It turns out that the equals sign doesn't seem to work. }node A[MAXN];BOOLCheckintPreintnext) {Node A=a[pre],b=A[next]; if(a.a[1]==b.a[1]&&a.a[2]==b.a[2])return true; return false;}intMain () {scanf ("%d",&N); Registerinti; //int temp[3]; //printf ("there1\n"); for(i=0; i<n;++i) {scanf ("%d%d%d", &a[i].a[0],&a[i].a[1],&a[i].a[2]); Sort (a[i].a,a[i].a+3); A[i].index=i+1; } //printf ("there2\n");Sort (a,a+n,cmp); //Debug//For (i=0;i<n;++i) {//printf ("p:%d%d%d\n", a[i].a[0],a[i].a[1],a[i].a[2]); // } //printf ("there3\n"); intans,first=1; intans1=-1, ans2=-1; for(i=0; i<n;++i) { //printf ("There4 i:%d\n", i); intmi=a[i].a[0]; if(first) { first=0; Ans=mi; Ans1=A[i].index; Ans2=-1;//the first time the initialization is not fully updated } Else{ if(mi>ans) {ans=mi; Ans1=A[i].index; Ans2=-1; } } if(i+1<n&&check (i,i+1)){ intnow=a[i].a[0]+a[i+1].a[0]; Mi=min (a[i].a[1],min (a[i].a[2],now)); if(mi>ans) {ans=mi; Ans1=A[i].index; Ans2=a[i+1].index; } } } if(ans2==-1) {printf ("1\n%d\n", ans1); } Else{printf ("2\n%d%d\n", ANS1,ANS2); } return 0;}
codeforces733d. Kostya The sculptor Partial order CMP sequencing, data structure hash, code simplification