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 ...
随机推荐
- blender-编译源码
1. 获得源码,目前是以 2.8 版本为例子 https://www.blender.org/download/ 上,可以直接下面源码 2. 解压,在blender-2.80 目录下,运行 mak ...
- 最新 珍岛java校招面经 (含整理过的面试题大全)
从6月到10月,经过4个月努力和坚持,自己有幸拿到了网易雷火.京东.去哪儿.珍岛等10家互联网公司的校招Offer,因为某些自身原因最终选择了珍岛.6.7月主要是做系统复习.项目复盘.LeetCode ...
- coverage代码覆盖率的使用~~
我们看下代码覆盖率的统计~,这个不必太揪心,觉得可以帮助你优化代码,可以看看,也不要带在意~ 1.先在cmd命令窗口在线安装coverage pip install coverage 2.安装完毕后我 ...
- windows和linux环境下使用google的glog日志库
一.概述 glog是google推出的一款轻量级c++开源日志框架,源码在github上,目前最新release版本是v0.3.5. githut地址:https://github.com/googl ...
- FZU2018级算法第二次作业 2.10 逆序数(权值线段树)
题目: Nk 最近喜欢上了研究逆序数,给出一个由 1…n 组成的数列 a1,a2,a3…an, a1的逆序数就是在 a2…an 中,比 a1 小的数的数量,而 a2 的逆序数就是 a3….an 中比 ...
- python标准库之collections介绍
collections----容器数据类型 collections模块包含了除list.dict.和tuple之外的容器数据类型,如counter.defaultdict.deque.namedtup ...
- DMA存储器到存储器传输代码讲解
M to M:Flash to Sram,把内部flash的数据传输到内部SRAM(DRAM主要存放的是变量, flash 主要存放代码) M to P: SRAM to 串口,同时LED闪烁,演示D ...
- @Adaptive注解
关于@Adaptive注解 引用dubbo官方文档的一段话: Adaptive 可注解在类或方法上.当 Adaptive 注解在类上时,Dubbo 不会为该类生成代理类.注解在方法(接口方法)上时 ...
- const函数返回自身的引用也是常量引用
const函数返回自身的引用也是const 解决:根据对象是否为consr重载
- Spring (4)框架
Spring第四天讲义 今日内容 Spring的事务管理 Spring和MyBatis框架的集成 1. Spring的事务管理 1.1. 事务是什么? 在操作数据库时(增删改),如果同时操作多次数据, ...