http://codeforces.com/contest/733/problem/D

给定n个长方体,然后每个长方体都能选择任何一个面,去和其他长方体接在一起,也可以自己一个,要求使得新的长方体的最短的那条边最大。

看样例2就知道,因为10、8、7和10、8、2组合后,min =  8,是最大的。

那么怎么做呢?

可以看到,一个长方体,能产生6种不同的摆放方式,然后排序后,排序的时候把a相同的尽可能排在一起,把b相同的尽可能地排在一起。因为这样就能分组了。

把数组分成若干组,相同的组里,a和b的值是一样的,(当然也可能是同一个id产生的不同放法,判断时需要排除相同id)

然后开始贪心了,在同一个组里,选两个出来,使得加起来的C最大(因为a和b固定了)。就是选两个最大的C了。

选的时候要注意,不能选同一id的,

而且:允许两个最大的C是相等的,这是个坑,不要认为mx1一定要>mx2.

接下来就是排除相同id的情况了,可以用Mx[id]表示这个id的最大值,然后判断过一次后,就vis掉就可以了。

FST。。感觉CF怎么一路都打不上去啊。唉,I so week。。。我要变强  ---- flag

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#define IOS ios::sync_with_stdio(false)
using namespace std;
#define inf (0x3f3f3f3f)
typedef long long int LL; #include <iostream>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
const int maxn = 2e6 + ;
bool book[maxn];
struct node {
int a, b, c;
int id;
node(int aa, int bb, int cc, int f) : a(aa), b(bb), c(cc), id(f) {}
node() {}
bool operator < (const struct node & rhs) const {
if (a != rhs.a) return a > rhs.a;
else if (b != rhs.b) return b > rhs.b;
else return c > rhs.c;
}
} arr[maxn], hehe[maxn];
int mx[maxn];
bool isok(struct node a, struct node b) {
return a.a == b.a && a.b == b.b;
} void work() {
int n;
scanf("%d", &n);
int tot = ;
int ans = ;
int p1, p2;
int k = ;
for (int i = ; i <= n; ++i) {
int a, b, c;
scanf("%d%d%d", &a, &b, &c);
arr[++tot] = node(a, b, c, i);
arr[++tot] = node(a, c, b, i);
arr[++tot] = node(b, a, c, i);
arr[++tot] = node(b, c, a, i);
arr[++tot] = node(c, a, b, i);
arr[++tot] = node(c, b, a, i);
int h = min(a, min(b, c));
if (h > ans) {
ans = h;
p1 = i;
}
}
sort(arr + , arr + + tot);
int to = ;
hehe[to] = arr[];
for (int i = ; i <= tot + ; ++i) { //tot + 1,因为最后一组
if (isok(arr[i - ], arr[i])) {
hehe[++to] = arr[i];
} else {
for (int j = ; j <= to; ++j) {
mx[hehe[j].id] = max(mx[hehe[j].id], hehe[j].c);
}
int mx1 = , mx2 = , id1 = , id2 = ;
for (int j = ; j <= to; ++j) {
if (book[hehe[j].id]) continue;
if (mx1 <= mx[hehe[j].id]) {
mx2 = mx1;
id2 = id1;
mx1 = mx[hehe[j].id];
id1 = hehe[j].id;
} else if (mx2 <= mx[hehe[j].id]) {
mx2 = mx[hehe[j].id];
id2 = hehe[j].id;
}
book[hehe[j].id] = ;
}
int mi = min(hehe[].a, hehe[].b);
mi = min(mi, mx1 + mx2);
if (mi > ans && id1 != id2 && id1 && id2) {
ans = mi;
p1 = id1;
p2 = id2;
k = ;
} for (int j = ; j <= to; ++j) {
mx[hehe[j].id] = ;
book[hehe[j].id] = ;
}
to = ;
hehe[to] = arr[i];
}
}
if (k == ) {
cout << k << endl;
cout << p1 << endl;
} else {
cout << k << endl;
cout << p1 << " " << p2 << endl;
}
} int main() {
#ifdef local
freopen("data.txt","r",stdin);
#endif
work();
return ;
}

Codeforces Round #378 (Div. 2) D. Kostya the Sculptor 分组 + 贪心的更多相关文章

  1. Codeforces Round #378 (Div. 2) D - Kostya the Sculptor

    Kostya the Sculptor 这次cf打的又是心累啊,果然我太菜,真的该认真学习,不要随便的浪费时间啦 [题目链接]Kostya the Sculptor &题意: 给你n个长方体, ...

  2. Codeforces Round #378 (Div. 2) D. Kostya the Sculptor map+pair

    D. Kostya the Sculptor time limit per test 3 seconds memory limit per test 256 megabytes input stand ...

  3. Codeforces Round #378 (Div. 2) D题(data structure)解题报告

    题目地址 先简单的总结一下这次CF,前两道题非常的水,可是第一题又是因为自己想的不够周到而被Hack了一次(或许也应该感谢这个hack我的人,使我没有最后在赛后测试中WA).做到C题时看到题目情况非常 ...

  4. Codeforces Round #378 (Div. 2) A B C D 施工中

    A. Grasshopper And the String time limit per test 1 second memory limit per test 256 megabytes input ...

  5. Codeforces Round #378 (Div. 2)F - Drivers Dissatisfaction GNU

    http://codeforces.com/contest/733/problem/F 题意:给你一些城市和一些路,每条路有不满意程度和每减少一点不满意程度的花费,给出最大花费,要求找出花费小于s的最 ...

  6. Codeforces Round #378 (Div. 2)

    A: 思路: 水题,没啥意思; B: 思路: 暴力,也没啥意思; C: 思路: 思维,可以发现从前往后和为b[i]的分成一块,然后这一块里面如果都相同就没法开始吃,然后再暴力找到那个最大的且能一开始就 ...

  7. Codeforces Round #378 (Div. 2) C D

    在实验室通宵 一边做水题一边准备随时躲起来以免被门卫大爷巡查发现..结果居然没来.. 本来以为可以加几分变个颜色..结果挂了CD...状态有点差...思维不太活跃 沉迷暴力不能自拔 D 给出n个长方体 ...

  8. Codeforces Round #378 (Div. 2) C. Epidemic in Monstropolis 模拟

    C. Epidemic in Monstropolis time limit per test 1 second memory limit per test 256 megabytes input s ...

  9. 暴力+树状数组维护 Codeforces Round #378 (Div. 2) C

    题目大意:给你一个长度为n的数组a,然后数值大的可以合并数值小的,且合并了以后该数组的长度-1.给你一个长度为k目标数组b,问,是否可以从a数组变到b数组,是就yes并且输出步骤.否就输出no 思路: ...

随机推荐

  1. mac下配置java运行环境

    1. oracle官网下载java se jdk地址 http://www.oracle.com/technetwork/java/javase/downloads/jdk9-downloads-38 ...

  2. 【Codeforces】Gym 101156G Non-Attacking Queens 打表

    题意 求$n\times n$的棋盘上放$3$个皇后使得互相不攻击的方案数 拓展是$m\times n$棋盘上放$k$皇后,暴力打表找到了公式 OEIS 代码 import java.math.Big ...

  3. listen 56

    Kettles Stop Whistling in the Dark British physicist Lord Rayleigh is best known for his discovery o ...

  4. hyperledger fabric学习(1)

    第一部分 环境搭建 说明 本次环境搭建是是现在虚拟机中,采用ubuntu 16.04版本,安装多次成功. 首先安装一些常用的工具 sudo apt-get update sudo apt-get in ...

  5. codevs 1531山峰

    传送门 1531 山峰  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 钻石 Diamond   题目描述 Description Rocky山脉有n个山峰,一字排开,从西向东 ...

  6. Merge into使用详解( 同时执行inserts和updates操作 )

    Merge是一个非常有用的功能,类似于MySQL里的insert into on duplicate key. Oracle在9i引入了merge命令, 通过这个merge你能够在一个SQL语句中对一 ...

  7. NLB

    http://www.cnblogs.com/allegro/archive/2011/02/11/1951171.html

  8. [MTC3]Cracking SHA1-Hashed Passwords

    题目地址:https://www.mysterytwisterc3.org/en/challenges/level-ii/cracking-sha1-hashed-passwords 解题关键:根据键 ...

  9. Eclipse&nbsp;安装插件

    Eclipse 安装插件 本文介绍Eclipse插件的安装方法.Eclipse插件的安装方法大体有三种:直接复制.使用link文件,以及使用eclipse自带的图形界面的插件安装方法. AD: 做为当 ...

  10. c程序实现unicode字符转utf-8字符

    下面是一个unicode字符转换为utf-8的c程序实现: /* * ================================================================= ...