[CF733D]Kostya the Sculptor(贪心)
题目链接:http://codeforces.com/contest/733/problem/D
题意:给n个长方体,允许最多两个拼在一起,拼接的面必须长宽相等。问想获得最大的内切圆的长方体序号是多少。最多拼2个,可以不拼。
最大内切圆与最短的边有关系,在读入的时候做只取一个的情况,接下来按照边长从大到小排序,之后按照最大边依次排序,取相邻的两个拼接在一起看看是否更大。
#include <bits/stdc++.h>
using namespace std; typedef struct S {
int x, y, z, id;
S(){}
S(int xx, int yy, int zz) {
if(xx < yy) swap(xx, yy);
if(xx < zz) swap(xx, zz);
if(yy < zz) swap(yy, zz);
x = xx; y = yy; z = zz;
}
bool operator <(const S b) const {
if(x == b.x) {
if(y == b.y) return z > b.z;
return y > b.y;
}
return x > b.x;
}
bool operator ==(const S b) const {
return x == b.x && y == b.y && z == b.z;
}
S operator +(const S b) const {
return S(x,y,z+b.z);
}
}S;
typedef pair<int,int> pii;
const int maxn = ;
int n, ret, id1, id2;
S s[maxn]; int main() {
// freopen("in", "r", stdin);
int x, y, z;
while(~scanf("%d", &n)) {
ret = ; id2 = -;
for(int i = ; i <= n; i++) {
scanf("%d%d%d",&x,&y,&z);
s[i] = S(x, y, z);
s[i].id = i;
if(ret < s[i].z) {
ret = s[i].z;
id1 = i;
}
}
sort(s+, s+n+);
for(int i = ; i <= n - ; i++) {
if(s[i].x==s[i+].x&&s[i].y==s[i+].y) {
S t = s[i] + s[i+];
if(ret < t.z) {
ret = t.z;
id1 = s[i].id; id2 = s[i+].id;
if(id1 > id2) swap(id1, id2);
}
}
}
if(id2 == -) {
printf("%d\n%d\n", , id1);
}
else {
printf("%d\n%d %d\n", , id1, id2);
}
}
return ;
}
[CF733D]Kostya the Sculptor(贪心)的更多相关文章
- CF733D Kostya the Sculptor[贪心 排序]
D. Kostya the Sculptor time limit per test 3 seconds memory limit per test 256 megabytes input stand ...
- codeforces 733D Kostya the Sculptor(贪心)
Kostya is a genial sculptor, he has an idea: to carve a marble sculpture in the shape of a sphere. K ...
- Codeforces378 D Kostya the Sculptor(贪心)(逻辑)
Kostya the Sculptor time limit per test 3 seconds memory limit per test 256 megabytes input standard ...
- Kostya the Sculptor
Kostya the Sculptor 题目链接:http://codeforces.com/problemset/problem/733/D 贪心 以次小边为第一关键字,最大边为第二关键字,最小边为 ...
- 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. Kostya the Sculptor 分组 + 贪心
http://codeforces.com/contest/733/problem/D 给定n个长方体,然后每个长方体都能选择任何一个面,去和其他长方体接在一起,也可以自己一个,要求使得新的长方体的最 ...
- Kostya the Sculptor(贪心
这题本来 想二分.想了很久很久,解决不了排序和二分的冲突. 用贪心吧.. 题意: 给你n个长方形,让你找出2个或1个长方体,使得他们拼接成的长方体的内接球半径最大(这是要求最短边越大越好)( ...
- 【25.47%】【codeforces 733D】Kostya the Sculptor
time limit per test3 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
随机推荐
- hadoop 启动停止命令
1 批量启动与停止 1.1 Start-all.sh # Start all hadoop daemons. Run this on master node. bin=`dirname ...
- 记一个由MemCached引发的性能问题
最近有个项目用loadrunner做了压力测试,发现并发量还不到200服务器就支撑不住了.boss那边紧急开会,说此项目最近3个月内将有100家中大型公司用于校园招聘工作,如果这个问题不解决公司有可能 ...
- 【python cookbook】【数据结构与算法】14.对不原生支持比较操作的对象排序
问题:想在同一个类的实例之间做排序,但是它们并不原生支持比较操作. 解决方案:使用内建的sorted()函数可接受一个用来传递可调用对象的参数key,sorted利用该可调用对象返回的待排序对象中的某 ...
- 给文件加ip访问限制
获取IP: function getIP(){ return isset($_SERVER['HTTP_X_FORWARDED_FOR'])? $_SERVER['HTTP_X_FORWARDED_F ...
- __ATTRIBUTE__ 你知多少?【转】
转自:http://www.cnblogs.com/astwish/p/3460618.html GNU C 的一大特色就是__attribute__ 机制.__attribute__ 可以设置函数属 ...
- 理解Linux中断 (3)【转】
转自:http://blog.csdn.net/tommy_wxie/article/details/7425712 版权声明:本文为博主原创文章,未经博主允许不得转载. .下半部 在中断处理过程中, ...
- ServiceStack.Redis常用操作 - 事务、并发锁_转
一.事务 使用IRedisClient执行事务示例: using (IRedisClient RClient = prcm.GetClient()) { RClient.Add("key&q ...
- while DEMO
while DEMO #!/bin/bash #author:xiluhua #since: let v_count= " ] do ] then sleep echo $v_count l ...
- 编码-截取中文-去除HTML字符
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> < ...
- mysql使用索引扫描来做排序
mysql有两种方式可以生成有序的结果,通过排序操作或者按照索引顺序扫描,如果explain的type列的值为index,则说明mysql使用了索引扫描来做排序(不要和extra列的Using ind ...