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. Kostya has a friend Zahar who works at a career. Zahar knows about Kostya's idea and wants to present him a rectangular parallelepiped of marble from which he can carve the sphere.
Zahar has n stones which are rectangular parallelepipeds. The edges sizes of the i-th of them are ai, bi and ci. He can take no more than two stones and present them to Kostya.
If Zahar takes two stones, he should glue them together on one of the faces in order to get a new piece of rectangular parallelepiped of marble. Thus, it is possible to glue a pair of stones together if and only if two faces on which they are glued together match as rectangles. In such gluing it is allowed to rotate and flip the stones in any way.
Help Zahar choose such a present so that Kostya can carve a sphere of the maximum possible volume and present it to Zahar.
The first line contains the integer n (1 ≤ n ≤ 105).
n lines follow, in the i-th of which there are three integers ai, bi and ci (1 ≤ ai, bi, ci ≤ 109) — the lengths of edges of the i-th stone. Note, that two stones may have exactly the same sizes, but they still will be considered two different stones.
In the first line print k (1 ≤ k ≤ 2) the number of stones which Zahar has chosen. In the second line print k distinct integers from 1 to n — the numbers of stones which Zahar needs to choose. Consider that stones are numbered from 1 to n in the order as they are given in the input data.
You can print the stones in arbitrary order. If there are several answers print any of them.
题意:给你n个矩形,当它们任意一个面积相同时可以合并,最多合并两个,问你组成最大内切求需要哪几个矩形组合,如果一个矩形就能组成
最大那么就输出1然后它的下表,如果需要两个(最多两个)输出2然后它们的下标。
这题作为d题是挺简单的,思路简单构成的矩形内切圆大小取决于它的最小边,所以如果拿最小边那个面去合成的话最多也不会超过最小边,
所以要拿最大边和次大边组合才有可能得到大的。于是处理一下3个边从大到小排序一下,在将这些点从大到小排序一下。先记录一个矩形时
最大结果的下标是多少, 再考虑两个的时候大边于次大边这个面组合,最大内切圆半径为min(sum , s[i].y) (sum表示两最小边之和,s[i].y
表示次小边)。大致就是这样的思路。
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
const int M = 1e5 + 10;
typedef long long ll;
struct ss {
ll x , y , z , num;
}s[M];
bool cmp(ss a , ss b) {
if(a.x == b.x)
return a.y > b.y;
return a.x > b.x;
}
int main()
{
int n;
cin >> n;
ll MAX = 0;
int temp = 0;
for(int i = 0 ; i < n ; i++) {
ll a , b , c;
cin >> a >> b >> c;
ll sum = a + b + c;
s[i].x = max(a , max(b , c));
s[i].z = min(a , min(b , c));
s[i].y = (sum - s[i].x - s[i].z);
s[i].num = i;
if(MAX < s[i].z) {
temp = i;
MAX = s[i].z;
}
}
sort(s , s + n , cmp);
ll sum2 = 0;
int l = 0;
int r = l;
int l2 = l;
for(int i = 0 ; i < n - 1 ; i++) {
if(s[i].x == s[i + 1].x && s[i].y == s[i + 1].y) {
l = i;
sum2 = s[i].z + s[i + 1].z;
if(MAX < min(sum2 , s[i].y)) {
MAX = min(sum2 , s[i].y);
r = i + 1;
l2 = l;
}
}
}
if(r - l2 >= 1) {
cout << r - l2 + 1 << endl;
for(int i = l2 ; i <= r ; i++) {
cout << s[i]. num + 1 << ' ';
}
}
else {
cout << 1 << endl;
cout << temp + 1 << endl;
}
return 0;
}
codeforces 733D Kostya the Sculptor(贪心)的更多相关文章
- CodeForces 733D Kostya the Sculptor
排序.把每一个长方体拆成$6$个做,然后排序做即可. #pragma comment(linker, "/STACK:1024000000,1024000000") #includ ...
- CF733D Kostya the Sculptor[贪心 排序]
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
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 ...
- 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 Gym 100338E Numbers (贪心,实现)
题目:http://codeforces.com/gym/100338/attachments 贪心,每次枚举10的i次幂,除k后取余数r在用k-r补在10的幂上作为候选答案. #include< ...
- [Codeforces 1214A]Optimal Currency Exchange(贪心)
[Codeforces 1214A]Optimal Currency Exchange(贪心) 题面 题面较长,略 分析 这个A题稍微有点思维难度,比赛的时候被孙了一下 贪心的思路是,我们换面值越小的 ...
- Codeforces Round #378 (Div. 2) D. Kostya the Sculptor 分组 + 贪心
http://codeforces.com/contest/733/problem/D 给定n个长方体,然后每个长方体都能选择任何一个面,去和其他长方体接在一起,也可以自己一个,要求使得新的长方体的最 ...
随机推荐
- [ PyQt入门教程 ] PyQt5信号与槽
信号和槽是PyQt编程对象之间进行通信的机制.每个继承自QWideget的控件都支持信号与槽机制.信号发射时(发送请求),连接的槽函数就会自动执行(针对请求进行处理).本文主要讲述信号和槽最基本.最经 ...
- Spring Boot简单环境搭建
#### 一.创建一个简单的Maven项目 使用`Maven`,通过导入`Spring Boot`的`starter`模块,可以将许多程序依赖的包自动导入到工程中.使用`Maven`的`parent ...
- CSS: hack 方式一览
本文引自:http://blog.csdn.net/freshlover/article/details/12132801 什么是CSS hack 由于不同厂商的流览器或某浏览器的不同版本(如IE6- ...
- 算法与数据结构基础 - 折半查找(Binary Search)
Binary Search基础 应用于已排序的数据查找其中特定值,是折半查找最常的应用场景.相比线性查找(Linear Search),其时间复杂度减少到O(lgn).算法基本框架如下: //704. ...
- 多线程 共享资源 同步锁 java
Java多线程编程:Lock synchronized是java中的一个关键字,也就是说是Java语言内置的特性.那么为什么会出现Lock呢? 如果一个代码块被synchronized修饰了,当一 ...
- 如何在GitHub上删除自己的项目?
话不多说,直奔主题~ 1.打开GitHub,在主页左边有自己写的库. 2.拿删除第二个库wlh-hub/vue-zsgc为例,点击它,进入下面页面. 3.在导航栏一栏中,找到settings,并点击. ...
- 洛谷 P4401 [IOI2007]Miners 矿工配餐
题意简述 有两个矿洞,已知食物的种类(≤3)和顺序,将他们送往任一矿洞, 若一个矿洞3次食物相同,贡献1:若有2种不同食物,贡献2:若有3种不同食物,贡献3 求最大贡献 题解思路 food[i] 为当 ...
- 解决php - Laravel rules preg_match(): No ending delimiter '/' found 问题
### 说明解决php - Laravel preg_match(): No ending delimiter '/' found 一.遇到问题的原因本正常添加如下 public function r ...
- C#中的扩展方法(向已有类添加方法,但无需创建新的派生类型)
C#中的扩展方法 扩展方法使你能够向现有类型"添加"方法,而无需创建新的派生类型.重新编译或以其他方式修改原始类型. 扩展方法是一种特殊的静态方法,但可以像扩展类型上的实例方法一样 ...
- 一文了解:Redis主从复制
Redis主从复制 主从复制 主从复制,将一台Redis服务器的数据,复制到其他Redis服务器.前者称为主(master)节点,后者称为从(slave)节点 . 在默认的情况下,Redis都是主节点 ...