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 思路: ...
随机推荐
- umount 卸载 无响应的 NFS 文件系统
当NFS Client 无法访问 NFS Server的适合,在Client上df操作等就会挂起. 这个适合需要将挂载的NFS卸载掉.在不知道挂载点的情况下,可以使用nfsstat -m 命令来查看. ...
- ACM学习历程—HDU1584 蜘蛛牌(动态规划 && 状态压缩 || 区间DP)
Description 蜘蛛牌是windows xp操作系统自带的一款纸牌游戏,游戏规则是这样的:只能将牌拖到比她大一的牌上面(A最小,K最大),如果拖动的牌上有按顺序排好的牌时,那么这些牌也跟着一起 ...
- ESFramework Demo -- P2P通信Demo(附源码)
现在我们将在ESFramework Demo -- 文件传送Demo 的基础上,使用ESPlus提供的第四个武器,为其增加P2P通信的功能.在阅读本文之前,请务必先掌握ESFramework 开发手册 ...
- 51 nod 1522 上下序列——序列dp
题目:http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1522 很好的思想.考虑从小到大一对一对填数,这样也能对它的大小限制 ...
- bzoj 4319 Suffix reconstruction —— 贪心构造
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=4319 思维还是不行...这样的构造都没思路... 首先,我们可以按 rank 的顺序从小到大 ...
- poj1966Cable TV Network——无向图最小割(最大流)
题目:http://poj.org/problem?id=1966 把一个点拆成入点和出点,之间连一条边权为1的边,跑最大流即最小割: 原始的边权赋成inf防割: 枚举源点和汇点,直接相邻的两个点不必 ...
- Codeplus2017 11月赛T3——基因
题目:https://www.luogu.org/problemnew/show/P4059 DP,状态应分为空格或字母,可用0和1表示,据此转移,详见代码. 另:注意初始化,因为有负值所以要先把f数 ...
- Html 5 版 电子时钟
效果图: html 5 canvas元素 Html 5的canvas元素可以用于在网页上绘制图形[即canvas的作用]. canvas画布使用JavaScript在网页上绘制图形 其拥有绘制各种路 ...
- HDU4391(线段树+剪枝)
Paint The Wall Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- .NETFramework:Random
ylbtech-.NETFramework:Random 1.程序集 mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c ...