Kostya the Sculptor

这次cf打的又是心累啊,果然我太菜,真的该认真学习,不要随便的浪费时间啦

【题目链接】Kostya the Sculptor

&题意:

给你n个长方体,你要使长方体的内切球有体积最大,有两种选择方案

①只选1个长方体。

②选2个长方体,黏到一起,但这2个长方体黏的那一面必须完全相等。也就是长宽相等。

&题解:

1个长方体遍历一遍取最小就好了。

2个的时候要第2短的和第3短的相等,才能合到一起,最小的有可能是2个最小的相加,或者是第2短的那个。

这题比赛的时候,总是在想如果相等的在最后怎么办,还要特殊处理,好像并没有处理好,所以总是wa。

现在想来根本不用,只要在最后加一个绝对不可能相等的数据就好了,这就减少了特殊处理最后一组的麻烦。应记住。

这也是用过好多次的方法了,不知道为什么当时就想不起来了 = =

还有输出的格式问题,为什么我注释的那块就不对呢?我还真的不知道,如果有大神看见,希望能评论回答一下!

【时间复杂度】O(\(n\))

&代码:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = 0x3f3f3f3f;
#define cle(a,val) memset(a,(val),sizeof(a))
#define SI(N) scanf("%d",&(N))
#define SII(N,M) scanf("%d %d",&(N),&(M))
#define SIII(N,M,K) scanf("%d %d %d",&(N),&(M),&(K))
#define rep(i,b) for(int i=0;i<(b);i++)
#define rez(i,a,b) for(int i=(a);i<=(b);i++)
#define red(i,a,b) for(int i=(a);i>=(b);i--)
const ll LINF = 0x3f3f3f3f3f3f3f3f;
#define PU(x) puts(#x);
#define PI(A) cout<<(A)<<endl;
#define DG(x) cout<<#x<<"="<<(x)<<endl;
#define DGG(x,y) cout<<#x<<"="<<(x)<<" "<<#y<<"="<<(y)<<endl;
#define DGGG(x,y,z) cout<<#x<<"="<<(x)<<" "<<#y<<"="<<(y)<<" "<<#z<<"="<<(z)<<endl;
#define PIar(a,n) rep(i,n)cout<<a[i]<<" ";cout<<endl;
#define PIarr(a,n,m) rep(aa,n){rep(bb, m)cout<<a[aa][bb]<<" ";cout<<endl;}
const double EPS = 1e-9 ;
/* //////////////////////// C o d i n g S p a c e //////////////////////// */
const int MAXN = 100000 + 9 ;
struct Node
{
ll x,y,z;
int id;
}no[MAXN];
bool cmp(const Node& A,const Node& B){
if (A.y==B.y) return A.z==B.z?A.x<B.x:A.z<B.z;
else return A.y<B.y;
}
int n;
void Solve()
{
while(~SI(n)){
rep(i,n){
int t[5];
rep(j,3) SI(t[j]);
sort(t,t+3);
no[i].x=t[0],no[i].y=t[1],no[i].z=t[2],no[i].id=i+1;
}
ll re1=0,re2=1;
rep(i,n){
if (re1<no[i].x){
re1=no[i].x,re2=no[i].id;
}
}
sort(no,no+n,cmp);
ll re3=0,re4=1,re5=1;
Node t;
t.x=-1,t.y=-1,t.id=-9;
no[n++]=t;
rep(i,n-1){
if (no[i].z==no[i+1].z&&no[i].y==no[i+1].y){
while(no[i].z==no[i+1].z&&no[i].y==no[i+1].y) i++;
if (re3<min(no[i].x+no[i-1].x,no[i].y)){
re3=min(no[i].x+no[i-1].x,no[i].y);
re4=no[i].id,re5=no[i-1].id;
}
}
}
if (re3>re1){ printf("2\n%d",re4);
printf(" %d\n",re5);
//上面的是对的,但下面的就是错的,一样的东西啊,不知道为什么
// printf("2\n%d %d\n",re4,re5);
}
else{
printf("1\n%d\n",re2);
}
}
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("1.in", "r", stdin);
freopen("1.out","w",stdout);
#endif
//iostream::sync_with_stdio(false);
//cin.tie(0), cout.tie(0);
// int T;cin>>T;while(T--)
Solve();
return 0;
}

Codeforces Round #378 (Div. 2) D - Kostya the Sculptor的更多相关文章

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

  2. Codeforces Round #378 (Div. 2) D. Kostya the Sculptor 分组 + 贪心

    http://codeforces.com/contest/733/problem/D 给定n个长方体,然后每个长方体都能选择任何一个面,去和其他长方体接在一起,也可以自己一个,要求使得新的长方体的最 ...

  3. Codeforces Round #378 (Div. 2) D题(data structure)解题报告

    题目地址 先简单的总结一下这次CF,前两道题非常的水,可是第一题又是因为自己想的不够周到而被Hack了一次(或许也应该感谢这个hack我的人,使我没有最后在赛后测试中WA).做到C题时看到题目情况非常 ...

  4. Codeforces Round #378 (Div. 2) A B C D 施工中

    A. Grasshopper And the String time limit per test 1 second memory limit per test 256 megabytes input ...

  5. Codeforces Round #378 (Div. 2)F - Drivers Dissatisfaction GNU

    http://codeforces.com/contest/733/problem/F 题意:给你一些城市和一些路,每条路有不满意程度和每减少一点不满意程度的花费,给出最大花费,要求找出花费小于s的最 ...

  6. Codeforces Round #378 (Div. 2)

    A: 思路: 水题,没啥意思; B: 思路: 暴力,也没啥意思; C: 思路: 思维,可以发现从前往后和为b[i]的分成一块,然后这一块里面如果都相同就没法开始吃,然后再暴力找到那个最大的且能一开始就 ...

  7. Codeforces Round #378 (Div. 2) C D

    在实验室通宵 一边做水题一边准备随时躲起来以免被门卫大爷巡查发现..结果居然没来.. 本来以为可以加几分变个颜色..结果挂了CD...状态有点差...思维不太活跃 沉迷暴力不能自拔 D 给出n个长方体 ...

  8. Codeforces Round #378 (Div. 2) C. Epidemic in Monstropolis 模拟

    C. Epidemic in Monstropolis time limit per test 1 second memory limit per test 256 megabytes input s ...

  9. 暴力+树状数组维护 Codeforces Round #378 (Div. 2) C

    题目大意:给你一个长度为n的数组a,然后数值大的可以合并数值小的,且合并了以后该数组的长度-1.给你一个长度为k目标数组b,问,是否可以从a数组变到b数组,是就yes并且输出步骤.否就输出no 思路: ...

随机推荐

  1. H5页面左图右边文字如何布局

    <!DOCTYPE html><html lang="en"><head>    <meta charset="UTF-8&qu ...

  2. div仿textarea

    CSS代码: .test_box { width: 400px; min-height: 120px; max-height: 300px; _height: 120px; margin-left: ...

  3. Java:多线程<三>死锁、线程间通讯

    死锁: 同步嵌套同步,而且使用的锁不是同一把锁时就可能出现死锁 class Test implements Runnable { private boolean flag; Test(boolean ...

  4. 使用urllib编写python爬虫

    新版python中,urllib和urllib2合并了,统一为urllib (1)简单爬取网页 import urllib content = urllib.request.urlopen(req). ...

  5. Unix Shell 程序设计 —— 正则表达式

    参考:http://www.cnblogs.com/erichhuang/archive/2012/03/13/2394119.html 简介: 简单的说,正则表达式是一种可以用于模式匹配和替换的强有 ...

  6. VaildForm 自定义提示消息

    ValidForm插件提供了7种提示效果,其中有四种自定义效果,具体访问地址:http://validform.rjboy.cn/demo.html 个人偏爱其中两种,即 l 提示效果四:[自定义提示 ...

  7. redis入门指南-安装redis

    纸上得来终觉浅 绝知此事要躬行 Redis官方不支持window.微软发布了可在redis的分支.不建议使用 但我确实用了. win7 redis2.8.4  php5.6  apache2.4 ht ...

  8. python 程序构架

    http://blog.csdn.net/heyabo/article/details/8806176

  9. java 内存机制简介

    java内存回收机制 不论哪种语言的内存分配方式,都需要返回所分配内存的真实地址,也就是返回一个指针到内存块的首地址.java中对象是采用new或者反射的方法创 建的,这些对象的创建都是在堆中分配,所 ...

  10. candence 知识积累2

    1 Allegro Symbol的类型以及作用: (1)Package Symbol : PCB里的封装符号,元器件的footprint,用来做元器件的封装,后缀(.psm),主要在电器层Etch ( ...