Kostya the Sculptor(贪心
这题本来 想二分。想了很久很久,解决不了排序和二分的冲突。 用贪心吧。。
题意:
给你n个长方形,让你找出2个或1个长方体,使得他们拼接成的长方体的内接球半径最大(这是要求最短边越大越好)(两个矩形拼接的条件是
他们有一个面完全相同)
输入n,输入第 i个长方体的 三条边长度。最多2个长方体拼接。
输出 不要拼接的"1"和最大能切成内切球的 i ;或者输出要拼接的“2”和这两个长方体的序号 i 。
如果 两个长方体的边长分别是 3 2 4,3 2 4 。可以拼接成 6 2 4,3 2 8,3 4 4;
显然 3 4 4这种拼法 内切球是最大的。(这里是 想到用贪心的起点)
给所有的长方体记录原来的位置序号,再按边长排序,(下面代码里的cmp)。这样可以保证每个长方体的第三条边都是最小的,
这样两个长方体的第三条边相加起来, 能使两个长方体的最短边得到加强。(类似木桶的短板原理)
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<string>
#include<cmath>
#include<set>
#include<vector>
#include<stack>
#include<queue>
#include<map>
using namespace std;
#define ll long long
#define se second
#define fi first
const int INF= 0x3f3f3f3f;
const int N=1e5+; int a[],b[];
int n,maxn=; struct note
{
int x,y,z;
int loc;
}q[N]; bool cmp(note r,note t)
{
return (r.x>t.x||
r.x==t.x&&r.y>t.y||
r.x==t.x&&r.y==t.y&&r.z>t.z);
} int main() //(3 2 4 ;3 2 4)3*2*8,6*2*4,3*4*4选的是3*4*4。
{
cin>>n;
int loc=,loc1=,loc2=; //这是要输出的长方体位置
for(int i=;i<=n;i++){
scanf("%d%d%d",&a[],&a[],&a[]);
sort(a,a+);
q[i].z =a[];
q[i].y =a[];
q[i].x =a[];
q[i].loc =i; //记录原来的下标
if(maxn<a[])
{
maxn=a[];
loc=i;
}
}
sort(q+,q++n,cmp);
int sign=; for(int i=;i<n;i++)
{
if(q[i].x==q[i+].x && q[i].y==q[i+].y)
{
b[]=q[i].x; b[]=q[i].y; b[]=q[i].z+q[i+].z;
sort(b,b+);
if(maxn<b[])
{
maxn=b[];
loc1=q[i].loc;
loc2=q[i+].loc;
sign=;
}
}
}
if(sign){
cout<<<<endl;
cout<<loc1<<' '<<loc2;
}
else
cout<<<<endl<<loc;
}
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个长方体,然后每个长方体都能选择任何一个面,去和其他长方体接在一起,也可以自己一个,要求使得新的长方体的最 ...
- [CF733D]Kostya the Sculptor(贪心)
题目链接:http://codeforces.com/contest/733/problem/D 题意:给n个长方体,允许最多两个拼在一起,拼接的面必须长宽相等.问想获得最大的内切圆的长方体序号是多少 ...
- 【25.47%】【codeforces 733D】Kostya the Sculptor
time limit per test3 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
随机推荐
- EXCEL中,在其中列 前面or后面加一个“元”字的技巧
EXCEL小技巧,我们平常需要用到一些,记录下,供有需要的人参考! 案例: EXCEL其中的一列,每个后面加一个“元”字,如果要1个1个去加,相当麻烦,其实很简单,只需要一个公式即可! 解决方法: ( ...
- 分布式消息通信之RabbitMQ_Note
目录 1. RabbitMQ 安装 2. RabbitMQ 应用场景,特性 3. 官网入门指引 4. RabbitMQ 工作模型 5. RabbitMQ 主要的几种交换机类型 6. Java API的 ...
- java 画图 Graphics 文字自动换行
/** * 文字超出限定长度自动换行 * * @param g 画布 * @param font 字体样式 * @param text 文字 * @param widthLength 最大长度 (多少 ...
- F2812 DSP程序运行在片内RAM和FLASH的区别
F2812 DSP程序运行在片内RAM和片内FLASH的区别 声明:引用请注明出处http://blog.csdn.net/lg1259156776/ 说明:F2812是带有内部Flash的DSP,与 ...
- Python 图形库
1. 总体介绍 http://www.cnblogs.com/Vito2008/p/5264291.html 2.pygal http://rfyiamcool.blog.51cto.com/1030 ...
- .NET细节知识总结,不断更新
1.catch (Exception)和catch (Exception e) Exception 类包含许多子类 程序执行的时候要将每一个类都搜索一遍 以找到符合的异常类 这样是蛮消耗资源的 影响效 ...
- 【转】spring基础:@ResponseBody,PrintWriter用法
理解:很多情况我们需要在controller接收请求然后返回一些message. 1.在springmvc中当返回值是String时,如果不加@ResponseBody的话,返回的字符串就会找这个St ...
- idea2019开发第一个java程序HelloWorld
用idea2019开发第一个java程序: (idea破解不在本讲义范围之内) 新手建议忽略此部分,先把eclipse用熟.技术是一样的.idea缺省配置是黑色的,很晃眼,可以(Files/setti ...
- ACMComputerFactory(POJ-3436)【最大流】
题目链接:https://vjudge.net/problem/POJ-3436 题意:要用N台机器来组装电脑,每台电脑由P个零部件构成,每一台机器的输入电脑和输出电脑的每部分都有各自的属性,机器本身 ...
- 利用Python进行数据分析_Pandas_基本功能
申明:本系列文章是自己在学习<利用Python进行数据分析>这本书的过程中,为了方便后期自己巩固知识而整理. 第一 重新索引 Series的reindex方法 In [15]: obj = ...