[CF733D]Kostya the Sculptor(贪心)

题目链接:http://codeforces.com/contest/733/problem/D

题意:给n个长方体,允许最多两个拼在一起,拼接的面必须长宽相等。问想获得最大的内切圆的长方体序号是多少。最多拼2个,可以不拼。

最大内切圆与最短的边有关系,在读入的时候做只取一个的情况,接下来按照边长从大到小排序,之后按照最大边依次排序,取相邻的两个拼接在一起看看是否更大。

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 
 4 typedef struct S {
 5     int x, y, z, id;
 6     S(){}
 7     S(int xx, int yy, int zz) {
 8         if(xx < yy) swap(xx, yy);
 9         if(xx < zz) swap(xx, zz);
10         if(yy < zz) swap(yy, zz);
11         x = xx; y = yy; z = zz;
12     }
13     bool operator <(const S b) const {
14         if(x == b.x) {
15             if(y == b.y) return z > b.z;
16             return y > b.y;
17         }
18         return x > b.x;
19     }
20     bool operator ==(const S b) const {
21         return x == b.x && y == b.y && z == b.z;
22     }
23     S operator +(const S b) const {
24         return S(x,y,z+b.z);
25     }
26 }S;
27 typedef pair<int,int> pii;
28 const int maxn = 100100;
29 int n, ret, id1, id2;
30 S s[maxn];
31 
32 int main() {
33     // freopen("in", "r", stdin);
34     int x, y, z;
35     while(~scanf("%d", &n)) {
36         ret = 0; id2 = -1;
37         for(int i = 1; i <= n; i++) {
38             scanf("%d%d%d",&x,&y,&z);
39             s[i] = S(x, y, z);
40             s[i].id = i;
41             if(ret < s[i].z) {
42                 ret = s[i].z;
43                 id1 = i;
44             }
45         }
46         sort(s+1, s+n+1);
47         for(int i = 1; i <= n - 1; i++) {
48             if(s[i].x==s[i+1].x&&s[i].y==s[i+1].y) {
49                 S t = s[i] + s[i+1];
50                 if(ret < t.z) {
51                     ret = t.z;
52                     id1 = s[i].id; id2 = s[i+1].id;
53                     if(id1 > id2) swap(id1, id2);
54                 }
55             }
56         }
57         if(id2 == -1) {
58             printf("%d
%d
", 1, id1);
59         }
60         else {
61             printf("%d
%d %d
", 2, id1, id2);
62         }
63     }
64     return 0;
65 }
原文地址:https://www.cnblogs.com/kirai/p/6020119.html