Codeforces Round #378 (Div. 2) D. Kostya the Sculptor 分组 + 贪心
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 分组 + 贪心的更多相关文章
- Codeforces Round #378 (Div. 2) D - Kostya the Sculptor
Kostya the Sculptor 这次cf打的又是心累啊,果然我太菜,真的该认真学习,不要随便的浪费时间啦 [题目链接]Kostya the Sculptor &题意: 给你n个长方体, ...
- 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 ...
- Codeforces Round #378 (Div. 2) D题(data structure)解题报告
题目地址 先简单的总结一下这次CF,前两道题非常的水,可是第一题又是因为自己想的不够周到而被Hack了一次(或许也应该感谢这个hack我的人,使我没有最后在赛后测试中WA).做到C题时看到题目情况非常 ...
- 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 ...
- Codeforces Round #378 (Div. 2)F - Drivers Dissatisfaction GNU
http://codeforces.com/contest/733/problem/F 题意:给你一些城市和一些路,每条路有不满意程度和每减少一点不满意程度的花费,给出最大花费,要求找出花费小于s的最 ...
- Codeforces Round #378 (Div. 2)
A: 思路: 水题,没啥意思; B: 思路: 暴力,也没啥意思; C: 思路: 思维,可以发现从前往后和为b[i]的分成一块,然后这一块里面如果都相同就没法开始吃,然后再暴力找到那个最大的且能一开始就 ...
- Codeforces Round #378 (Div. 2) C D
在实验室通宵 一边做水题一边准备随时躲起来以免被门卫大爷巡查发现..结果居然没来.. 本来以为可以加几分变个颜色..结果挂了CD...状态有点差...思维不太活跃 沉迷暴力不能自拔 D 给出n个长方体 ...
- 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 ...
- 暴力+树状数组维护 Codeforces Round #378 (Div. 2) C
题目大意:给你一个长度为n的数组a,然后数值大的可以合并数值小的,且合并了以后该数组的长度-1.给你一个长度为k目标数组b,问,是否可以从a数组变到b数组,是就yes并且输出步骤.否就输出no 思路: ...
随机推荐
- certbot申请SSL证书及中间证书问题
首先是到https://certbot.eff.org/上申请证书,由于我们使用的web服务器是基于erlang的cowboy的,在主页上没有选项可以支持,因此在Software下拉项中选择" ...
- [acm]HDOJ 2059 龟兔赛跑
题目地址: http://acm.hdu.edu.cn/showproblem.php?pid=2059 起点和终点,共n+2个点,n+2个状态,简单DP即可. //11512698 2014-08- ...
- ubuntu强制卸载软件
以卸载cups为例子 一:列出软件列表,找到需要卸载的软件的名字命令:dpkg --list
- 闪回之 Flashback Data Archive
背景:Oracle 11g 中 Flashback Data Archive 特性.将变化数据另外存储到创建的闪回归档区(Flashback Archive)中,以和 undo 区别开来,这样就可以为 ...
- 【转】Android Menu
Menu由两种形式,Option menu和Context menu.前者是按下设备的Menu硬按钮弹出,后者是长按widget弹出. Option Menu 当我们按下Menu的硬件按钮时,Opti ...
- .NETFramework-Web.Services:WebMethodAttribute
ylbtech-.NETFramework-Web.Services:WebMethodAttribute 1.程序集 System.Web.Services, Version=4.0.0.0, Cu ...
- Modbus通讯协议学习 - 认识篇
转自:http://www.cnblogs.com/luomingui/archive/2013/06/14/Modbus.html 什么是Modbus? Modbus 协议是应用于电子控制器上的一种 ...
- CF-811A
A. Vladik and Courtesy time limit per test 2 seconds memory limit per test 256 megabytes input stand ...
- 第3章 编写ROS程序-3
1.订阅者程序 我们继续使用 turtlesim 作为测试平台,订阅 turtlesim_node发布的/turtle1/pose 话题. 这一话题的消息描述了海龟的位姿 (位置和朝向) .尽管目前你 ...
- Swoole 协程与 Go 协程的区别
Swoole 协程与 Go 协程的区别 进程.线程.协程的概念 进程是什么? 进程就是应用程序的启动实例. 例如:打开一个软件,就是开启了一个进程. 进程拥有代码和打开的文件资源,数据资源,独立的内存 ...