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. python 列表之队列

    列表实现队列操作(FIFO),可以使用标准库里的 collections.deque,deque是double-ended quene的缩写,双端队列的意思,它可以实现从队列头部快速增加和取出对象. ...

  2. (Nginx + Gunicorn) 时 nginx 400 request line is too large (4360 4094)

    查看nginx下面两个参数 值是否满足 client_header_buffer_size 512k;large_client_header_buffers 4 512k; 满足依然出现 如果ngin ...

  3. bzoj2673

    限制这么多 肯定是网络流 考虑连边 首先我们计算出每行最多放的棋子数$sx[i]$,每列最多放的棋子数$sy[i]$ 首先由源点向第$i$行连流量为$sx[i]$费用为$0$的边,第$i$列向汇点连流 ...

  4. [CTSC 2012] Cheat

    [题目链接] https://www.lydsy.com/JudgeOnline/problem.php?id=2806 [算法] 首先建立广义后缀自动机 注意到问题具有单调性 , 不妨对于每组询问二 ...

  5. python爬虫知识点总结(七)PyQuery详解

    官方学习文档:http://pyquery.readthedocs.io/en/latest/api.html 一.什么是PyQuery? 答:强大有灵活的网页解析库,模仿jQuery实现.如果你觉得 ...

  6. Linux命令汇总(二)

    1.登录用户设置 新创建了一个用户,用useradd指令,但是发现通过终端无法登陆:  echo password | passwd --stdin username  或者  passwd --st ...

  7. PHP函数---$_Get()和$_Post()的用法

    一.$_Get()和$_Post()函数是用来传值的,即对应两种提交表单的方法,get和post. 二.$_Get方法 (1)获取通过URL的传值 Example 1 新建两个PHP文件,1.php, ...

  8. 人工智能实践:linux 和 python 基础简介

    linux下的目录 绝对路径:是以根目录(" / ")为起点的完整路径,以你所要到的目录为终点. 相对路径:是你当前的目录(" .")为起点的路径,以你所要到的 ...

  9. ReSIProcate源码目录下功能说明

    1.basicCall,basicMessage,basicRegister,resip_test测试用的 2.db_static Sleepy Cat开发的Berkeley DB 3.dum为Dia ...

  10. sql基础内容2

    -- day16课程内容 --CREATE DATABASE day16;USE day16; -- *************一.数据约束********************------ 1.1 ...