Codeforces 733D Kostya The sculptor

Source: Internet
Author: User

The test instructions of this topic is relatively simple: given n cuboid, two box can be glued to a new box condition is two box has a polygon size is the same (both length and width are the same), up to two boxes are allowed to stick together. It is required to find the largest cuboid of the inner cutting ball (it is possible that there are two new cuboid, and a single box that can be original).

The solution is also relatively simple, roughly speaking of ideas:

The key to this problem is how to quickly determine which of the n boxes are glued together. If 22 are judged separately and definitely timed out, I would like to think of each box as 6 different boxes (a box with a width and height of one arrangement), and then define the less-than number (in particular, the code of the structure is less than the number of overloads, it should be explained that when the length and width of the same time, it needs to be sorted This can be guaranteed after the sort, when there is a column of the length of the width of the same time, we only take the last two of the line. It is not difficult to think that when the length and width are the same, the size of the inner cut depends on the height, and because the last two will definitely correspond to the highest two. Then it is relatively simple, traversing a series, to determine whether the adjacent two can stick together, and to find the inradii after sticking together the radius can be (the minimum value of long and wide height). See the code for the specific process.


#include <cstdio> #include <cstring> #include <cmath> #include <queue> #include <vector> #

Include <algorithm> using namespace std;

const int MAX = 600010;

	struct node{int x, y, z, index;
		BOOL operator < (const node& RGS) const{if (x! = rgs.x) {return x < rgs.x;
		} if (Y! = rgs.y) {return y < Rgs.y;   }/* if (z! = rgs.z) {return Z < rgs.z;
	Write this wrong place, that is, you have just started to write, resulting in two identical cuboid, can not compare} */return Z < rgs.z;

}}p[max];

	int judge (int i, int j) {if (P[i].index = = P[j].index) return 0;
	if (p[i].x==p[j].x && p[i].y = = p[j].y) {return min (min (p[i].x, p[i].y), p[i].z+p[j].z);
} return 0;

	} int main () {/* code */int n;

		while (scanf ("%d", &n)! = EOF) {int res = 0, k;
		int x, y, Z;
			for (int i = 0, j = 0; i<n; i++) {scanf ("%d%d%d", &x, &y, &z);
			P[j++] = (Node) {x, y, z, i};
			P[j++] = (Node) {x, z, y, i};
			P[j++] = (Node) {y, x, z, i}; P[j++] = (Node)
			{y, z, x, i};
			P[j++] = (Node) {z, x, y, i};


			P[j++] = (Node) {z, y, x, i};

			int tmp = MIN (z, min (x, y));
				if (tmp > Res) {res = TMP;
			K = i+1;

		}} sort (P, p+n*6);
		/*for (int i = 0; i<n*6; i++) {printf ("%d%d%d%d\n", p[i].x, P[i].y, P[i].z, P[i].index);

		}*/int l = 0, r = 0;
			for (int i = 0; i<6*n-1; i++) {int tmp = judge (i, i+1);
				if (tmp > Res) {res = TMP;
				L = p[i].index+1;
			R = p[i+1].index+1;
			}} if (L > 0) {printf ("2\n");
		printf ("%d%d\n", L, R);
			}else{printf ("1\n");
		printf ("%d\n", K);
}} return 0; }




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.