Codeforces Round #378 (Div. 2) D. Kostya the Sculptor __ data structures、map>

ProLightsfx 2016-11-13 116 11/13
D. Kostya the Sculptor data structures

Source

Codeforces Round #378 (Div. 2)

 

My Solution

题意:可以把2个长方体合并成1个(只能把尺寸相同的面合并),或者只选一个,然后搞出一个球,求选1个或者2个合并成1个,从而球的体积最大

 

data structures、map<ii, priority_queue > mp;

把长方体的分成地面和高来储存,

如果长宽高3条边都不相等,则每个面存一次,mp[ii(x, y)].push(ii(z, i)); mp[ii(y, z)].push(ii(x, i)); mp[ii(x, z)].push(ii(y, i));  并且确保mp.first.first >= mp.first.second

如果有2条边相等,则存2个面

如果长宽高都相等,则存1个面

存储完后,用迭代器访问一遍map,每个priority_queue,访问前1个和前2个,并用 a, b, ans分别维护选中的第一个长方体的编号、选中的第二个长方体的编号(如果有)、所求球体的直径。

复杂度 O(nlogn)

 

#include 
#include 
#include 




#include 
using namespace std;
typedef long long LL;
typedef pair<LL, LL> ii;
const int maxn = 1e6 + 8;

map<ii, priority_queue > mp;

int main()
{
    #ifdef LOCAL
    freopen("d.txt", "r", stdin);
    //freopen("d.out", "w", stdout);
    int T = 4;
    while(T--){
    #endif // LOCAL
    ios::sync_with_stdio(false); cin.tie(0);

    LL n, x, y, z;
    cin >> n;
    for(int i = 1; i <= n; i++){ cin >> x >> y >> z;
        if(x == y){
            mp[ii(x, y)].push(ii(z, i));
            if(x != z){
                if(x > z) mp[ii(x, z)].push(ii(y, i));
                else mp[ii(z, x)].push(ii(y, i));
            }
        }
        else if(x == z){
            mp[ii(x, z)].push(ii(y, i));
            if(x > y) mp[ii(x, y)].push(ii(z, i));
            else mp[ii(y, x)].push(ii(z, i));
        }
        else if(y == z){
            mp[ii(y, z)].push(ii(x, i));
            if(x > y) mp[ii(x, y)].push(ii(z, i));
            else mp[ii(y, x)].push(ii(z, i));
        }
        else{
            if(x > y) mp[ii(x, y)].push(ii(z, i));
            else mp[ii(y, x)].push(ii(z, i));

            if(x > z) mp[ii(x, z)].push(ii(y, i));
            else mp[ii(z, x)].push(ii(y, i));

            if(y > z) mp[ii(y, z)].push(ii(x, i));
            else mp[ii(z, y)].push(ii(x, i));            //..else mp[ii(y, z)].push(ii(x, i));
        }
    }

    LL a = -1, b = -1, ans = 0, ai, bi, c;
    for(auto i = mp.begin(); i != mp.end(); i++){
        if((i->second).size() >= 1){
            ai = (i->second).top().second, c = (i->second).top().first;
            (i->second).pop();
            if(ans < min((i->first).second, c)){
                ans = min((i->first).second, c);                  //前面写成ans = c 了⊙﹏⊙‖∣
                a = ai;
                b = -1;
            }

            if((i->second).size() >= 1){
                bi = (i->second).top().second, c += (i->second).top().first;
                (i->second).pop();
                if(ans < min((i->first).second, c)){
                    ans = min((i->first).second, c);              //前面写成ans = c 了⊙﹏⊙‖∣
                    a = ai;
                    b = bi;
                }
            }


        }
    }

    if(b == -1){
        cout << 1 << endl;
        cout << a << endl;
    }
    else{
        cout << 2 << endl;
        cout << a << " " << b << endl;
    }

    #ifdef LOCAL
    mp.clear();
    cout << endl;
    }
    #endif // LOCAL
    return 0;
}

 

 

 

 

非特殊说明,本博所有文章均为博主原创,未经许可不得转载。

https://www.prolightsfxjh.com/

Thank you!

                                                                                                                                             ------from ProLightsfx

- THE END -

ProLightsfx

11月26日17:19

最后修改:2024年11月26日
0

非特殊说明,本博所有文章均为博主原创,未经许可不得转载。

共有 0 条评论