对于n==100。1,1,2或者1,2,2大量重复的形状相同的数据,cmp函数最后一项如果表达式带等于,整个程序就会崩溃

还没有仔细分析std::sort的调用过程,所以这里不是很懂。。,mark以后研究

因为题目让你挑一到两个平行六面体,然后去每个平行六面体长宽高的最小值,然后去求最小值中的最大值

我们很容易想到暴力的做法,如果两个平行六面体能够合并的话,那我们直接计算合并之后的最小值,因为我们知道此时

合并之后再求最小值,它是只增不减的

那么我们就要找到能合并某一个面的所有平行六面体的集合,

这里有一个令人模糊的地方,那就是对于每一个平行六面体,我们选它的哪一个面呢,当然只有三个不同的面

我们发现了以下事实

1,2,3==3,2,1==2,3,1尺寸的平行六面体是同一个东西,但是这个给我们带来了很大的困扰。。

因为我们会把同一个东西当成不同的考虑3遍,而每一遍我们起初还会考虑三个面。。很乱。。

但是仔细一想,我们其实不用考虑1,2和1,3这两个面,因为你叠加这两个平行六面体,只增加次大值或者最大值

最小值没变。。而只有最小值对答案有贡献,所以说我们要让除了最小值的另外两个尺寸构成平面然后去考虑能不能和其他的

平行六面体叠加,增加最小值,从而达到增大对答案贡献的目的

所以我们需要把每个平行六面体的size从小到大排序,然后我们希望对平行六面体整体排序,然后次大值和最大值相等的尽量挨在一起

这样就好处理了,这个就是字典序了,看你侧重哪个元素的优先选取,仔细想想就能懂了

本次代码经验,记得切换目录到源文件根目录,否则会报错。。能用数组索引操作的变量(下标操作)我们就尽量不起别名,用for简单操作

代码:

#include <cstdio>
#include <algorithm>
using namespace std;
int n;
const int maxn=1e5+;
struct node{
int a[];
int index;
};
bool cmp(node a,node b){
if(a.a[]!=b.a[]){
return a.a[]<b.a[];
}
if(a.a[]!=b.a[]){
return a.a[]<b.a[];
}
// if(a.a[2]!=b.a[2]){
// return a.a[2]<b.a[2];
// }
return a.a[]<b.a[];
//全部相等的时候因该返回什么
//目前我是这么理解的
//如果cmp为真则sort不交换,如果sort为假那我们就交换
//当完全相等的时候,我认为没有什么必要交换
//我们应该按照2,1,0的顺序来排列?
//事实证明有等于号好像不行呢。。 } node A[maxn];
bool check(int pre,int next){
node a=A[pre],b=A[next];
if(a.a[]==b.a[]&&a.a[]==b.a[]) return true;
return false;
}
int main(){
scanf("%d",&n);
register int i;
//int temp[3];
// printf("there1\n");
for(i=;i<n;++i){
scanf("%d%d%d",&A[i].a[],&A[i].a[],&A[i].a[]);
sort(A[i].a,A[i].a+);
A[i].index=i+;
}
// printf("there2\n");
sort(A,A+n,cmp);
//debug
// for(i=0;i<n;++i){
// printf("p:%d %d %d\n",A[i].a[0],A[i].a[1],A[i].a[2]);
// }
// printf("there3\n");
int ans,first=;
int ans1=-,ans2=-;
for(i=;i<n;++i){
// printf("there4 i:%d\n",i);
int mi=A[i].a[];
if(first){
first=;
ans=mi;
ans1=A[i].index;
ans2=-;//第一次初始化的时候更新不全
}
else{
if(mi>ans){
ans=mi;
ans1=A[i].index;
ans2=-;
}
}
if(i+<n&&check(i,i+)){
int now=A[i].a[]+A[i+].a[];
mi=min(A[i].a[],min(A[i].a[],now));
if(mi>ans){
ans=mi;
ans1=A[i].index;
ans2=A[i+].index;
}
}
}
if(ans2==-){
printf("1\n%d\n",ans1);
}
else{
printf("2\n%d %d\n",ans1,ans2);
}
return ;
}

codeforces733D. Kostya the Sculptor 偏序cmp排序,数据结构hash,代码简化的更多相关文章

  1. CF733D Kostya the Sculptor[贪心 排序]

    D. Kostya the Sculptor time limit per test 3 seconds memory limit per test 256 megabytes input stand ...

  2. Codeforces378 D Kostya the Sculptor(贪心)(逻辑)

    Kostya the Sculptor time limit per test 3 seconds memory limit per test 256 megabytes input standard ...

  3. Codeforces Round #378 (Div. 2) D - Kostya the Sculptor

    Kostya the Sculptor 这次cf打的又是心累啊,果然我太菜,真的该认真学习,不要随便的浪费时间啦 [题目链接]Kostya the Sculptor &题意: 给你n个长方体, ...

  4. Kostya the Sculptor

    Kostya the Sculptor 题目链接:http://codeforces.com/problemset/problem/733/D 贪心 以次小边为第一关键字,最大边为第二关键字,最小边为 ...

  5. 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 ...

  6. cmp排序hdoj 1106排序

    上班之余抽点时间出来写写博文,希望对新接触的朋友有帮助.今天在这里和大家一起学习一下cmp排序 /*标题还是比拟的水吧,但是花的时间还是比拟的多,心不够静*/ #include <iostrea ...

  7. Python实现各种排序算法的代码示例总结

    Python实现各种排序算法的代码示例总结 作者:Donald Knuth 字体:[增加 减小] 类型:转载 时间:2015-12-11我要评论 这篇文章主要介绍了Python实现各种排序算法的代码示 ...

  8. 专题 查找与排序的Java代码实现(一)

    专题 查找与排序的Java代码实现(一) 查找(Searching) 线性查找(linear search) 属于无序查找算法,适合于存储结构为顺序存储或链接存储的线性表. 基本思想:从数据结构线形表 ...

  9. php四种排序算法实现代码

    分享php排序的四种算法与代码. 冒泡:function bubble_sort($arr){ $num = count($arr); for($i=0;$i<$num;$i++){ for($ ...

随机推荐

  1. ios 使用autolayout 后button 的frame 无法设置问题!

    问题见这里,只能通过bounds和center进行设置!http://www.cocoachina.com/bbs/read.php?tid-236862.html 待研究!!!!~~~

  2. solr单机环境配置并包含外部单机zookeeper

    首先和之前一样下载solr-5.3.1.tgz,然后执行下面命令释放文件并放置在/usr/目录下: $ .tgz $ /usr/ $ cd /usr/solr- 这个时候先不用启动solr,因为单机模 ...

  3. glib-2.49.4 static build step in windows XP

    export LIBFFI_CFLAGS=" -I/usr/local/lib/libffi-3.2.1/include " \ export LIBFFI_LIBS=" ...

  4. FFMpeg ver 20160219-git-98a0053 滤镜中英文对照 2016.02.21 by 1CM

    FFMpeg ver 20160219-git-98a0053 滤镜中英文对照 2016.02.21 by 1CM T.. = Timeline support 支持时间轴 .S. = Slice t ...

  5. Spring配置数据源

    Spring在第三方依赖包中包含了两个数据源的实现类包,其一是Apache的DBCP,其二是 C3P0.可以在Spring配置文件中利用这两者中任何一个配置数据源. DBCP数据源 DBCP类包位于 ...

  6. Javascript调用C#后台方法及JSon解析

    Javascript调用C#后台方法及JSon解析   如何使用Ajax 调用C# 后台方法. 本文目录 如何使用Ajax 调用C# 后台方法. 1.后台(.cs)测试方法 2.前台调用(javasc ...

  7. 【leetcode】Binary Tree Right Side View(middle)

    Given a binary tree, imagine yourself standing on the right side of it, return the values of the nod ...

  8. 【leetcode】Surrounded Regions(middle)☆

    Given a 2D board containing 'X' and 'O', capture all regions surrounded by 'X'. A region is captured ...

  9. 20145213《Java程序设计》实验三敏捷开发与XP实践

    20145213<Java程序设计>实验三敏捷开发与XP实践 实验要求 1.XP基础 2.XP核心实践 3.相关工具 实验内容 1.敏捷开发与XP 软件工程是把系统的.有序的.可量化的方法 ...

  10. selinux

    root@lujie ~]# vim /etc/sysconfig/selinux # This file controls the state of SELinux on the system. # ...