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. linux进程学习-进程描述符的存储

    当进程被新建时,内核会给进程分配一个8K的空间作为进程的内核堆栈.同时我们知道task_struct结构体也会被创建,但有意思的是,内核不会给task_struct单独分别空间,而是直接将其扔到8k的 ...

  2. mongodb 常用操作符

    最近常用mongodb数据库,但是很多操作符不清楚或不知道,所有抽空根据手册整理下,以便于以后查阅(基于3.4版本) 1.查询和投影操作符 1.1比较操作符 $eq 匹配字段值等于指定值的文档 { & ...

  3. EntityFramework Code First 构建外键关系,数据库不生成外键约束

    创建 ExtendedSqlGenerator类 public class ExtendedSqlGenerator : SqlServerMigrationSqlGenerator { #regio ...

  4. 打开关闭tomcat的目录浏览功能

    目录浏览功能 conf/web.xml中init-param中有对于listing的定义,设置为true即可实现tomcat的目录浏览: tomcat的管理用户设置 conf/tomcat-users ...

  5. selenium+python中,框架中,怎么返回上一个菜单

    /退回上一级表单 driver.switchTo().defaultContent();

  6. 【原】SQLPLUS支持上下翻页

    作者:david_zhang@sh [转载时请以超链接形式标明文章] 链接:http://www.cnblogs.com/david-zhang-index/p/4191650.html 适用:RHE ...

  7. Java日志:集成slf4j和logback

    Java日志方案有很多,包括:java.util.logging.Apache的commons-logging和log4j.slf4j以及logback. 一个大型项目会用到众多第三方jar包,这些j ...

  8. elasticsearch2.x安装部署

    目录 一.安装es以及插件 二.建立索引和映射,添加数据 三.备注 一.安装es以及插件 ElasticSearch-2.3.1版本,系统为CentOS 7.0位. 对应的网上下载地址都有: elas ...

  9. [hdu3078]Network(LCA+排序)

    题意:维护树上两点之间的最短路径,其一,将点a的值变为b,其二,求路径上第k大的值. 解题关键:LCA+sort 复杂度:$O(qn\log n + n\log n)$ 数据弱不怪我 //#pragm ...

  10. 解决ubuntu下filezilla登录ftp看不到中文目录和文件的问题 (转载)

    转自:http://blog.csdn.net/duguteng/article/details/7716283 打开filezilla 文件-站点管理器-新站点--字符集--使用自定义的字符集 ,填 ...