CodeForces 733D Kostya the Sculptor

排序。把每一个长方体拆成$6$个做,然后排序做即可。

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<ctime>
#include<iostream>
using namespace std;
typedef long long LL;
const double pi=acos(-1.0);
void File()
{
    freopen("D:\\in.txt","r",stdin);
    freopen("D:\\out.txt","w",stdout);
}
template <class T>
inline void read(T &x)
{
    char c = getchar();
    x = 0;
    while(!isdigit(c)) c = getchar();
    while(isdigit(c))
    {
        x = x * 10 + c - ‘0‘;
        c = getchar();
    }
}

struct X
{
    int a,b,c,id;
}s[600010],t[600000];
int n,sz;

void add(int A,int B,int C,int ID)
{
    s[sz].a=A;
    s[sz].b=B;
    s[sz].c=C;
    s[sz].id=ID;
    sz++;
}

bool F(int x,int y)
{
    if(s[x].a!=s[y].a) return 0;
    if(s[x].b!=s[y].b) return 0;
    if(s[x].c!=s[y].c) return 0;
    if(s[x].id!=s[y].id) return 0;
    return 1;
}

bool cmp(X a,X b)
{
    if(a.a!=b.a) return a.a<b.a;
    if(a.b!=b.b) return a.b<b.b;
    if(a.c!=b.c) return a.c<b.c;
    return a.id<b.id;
}

int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        int a,b,c; cin>>a>>b>>c;
        add(a,b,c,i); add(b,a,c,i);
        add(a,c,b,i); add(c,a,b,i);
        add(b,c,a,i); add(c,b,a,i);
    }

    sort(s,s+sz,cmp);

    sz=0; t[sz++]=s[0];
    for(int i=1;i<6*n;i++)
    {
        if(F(i,i-1)==1) continue;
        t[sz++]=s[i];
    }
/*
    for(int i=0;i<sz;i++)
    {
        printf("%d %d %d %d\n",t[i].a,t[i].b,t[i].c,t[i].id);
    }
    */

    int mx=0,ans1,ans2,ans3;

    for(int i=0;i<sz;i++)
    {
        if(min(t[i].a,min(t[i].b,t[i].c))>mx)
        {
            mx=min(t[i].a,min(t[i].b,t[i].c));
            ans1=1; ans2=t[i].id;
        }

        if(i>=1&&t[i].a==t[i-1].a&&t[i].b==t[i-1].b)
        {
            if(min(t[i].a,min(t[i].b,t[i].c+t[i-1].c))>mx)
            {
                mx=min(t[i].a,min(t[i].b,t[i].c+t[i-1].c));
                ans1=2; ans2=t[i].id; ans3=t[i-1].id;
            }
        }
    }

    if(ans1==1) printf("1\n%d\n",ans2);
    else printf("2\n%d %d\n",ans2,ans3);

    return 0;
}
时间: 2024-10-11 09:15:25

CodeForces 733D Kostya the Sculptor的相关文章

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 w

Kostya the Sculptor

Kostya the Sculptor 题目链接:http://codeforces.com/problemset/problem/733/D 贪心 以次小边为第一关键字,最大边为第二关键字,最小边为第三关键字排序,每次只需要找次小边和最大边均相同,最小边最大的两项即可. 因为用Python遇到很多问题,切片操作a[i:j]是左闭右开区间[i,j) 代码如下: 1 n = int(input()) 2 a = [] 3 ans,u,v = 0,-1,-1 4 for i in range(n):

CF733D Kostya the Sculptor[贪心 排序]

D. Kostya the Sculptor time limit per test 3 seconds memory limit per test 256 megabytes input standard input output standard output Kostya is a genial sculptor, he has an idea: to carve a marble sculpture in the shape of a sphere. Kostya has a frien

codeforces 733D

明白了自己这么菜的原因多半是赛后不肯去补那些需要多花点时间思考的题目以及效率不高,但愿现在还不算晚... #include<bits/stdc++.h> #include<iostream> #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> #include<string.h> #define maxint 999999999 #d

codeforces733D. Kostya the Sculptor 偏序cmp排序,数据结构hash,代码简化

对于n==100.1,1,2或者1,2,2大量重复的形状相同的数据,cmp函数最后一项如果表达式带等于,整个程序就会崩溃 还没有仔细分析std::sort的调用过程,所以这里不是很懂..,mark以后研究 因为题目让你挑一到两个平行六面体,然后去每个平行六面体长宽高的最小值,然后去求最小值中的最大值 我们很容易想到暴力的做法,如果两个平行六面体能够合并的话,那我们直接计算合并之后的最小值,因为我们知道此时 合并之后再求最小值,它是只增不减的 那么我们就要找到能合并某一个面的所有平行六面体的集合,

CF 378(2) C D 模拟

CF 378(2)   好坑,有时间再做一遍 CodeForces 733C 题意:n只怪物,每只重ai,一开始有给定序列a[].问最后是否能变到x只特定序列b[],变化只能是相邻的大吃小. 题解:坑死人的题,,但不要怕去写这种题,在草稿纸上写好思路,一定要动手写.  思路:先把a[]根据b[]进行分段,再对每一段进行分析.细节太多,不自己动手写一遍根本体会不到.. #include<bits/stdc++.h> using namespace std; #pragma comment(lin

Codeforces Round #397 by Kaspersky Lab and Barcelona Bootcamp (Div. 1 + Div. 2 combined) A B C D 水 模拟 构造

A. Neverending competitions time limit per test 2 seconds memory limit per test 512 megabytes input standard input output standard output There are literally dozens of snooker competitions held each year, and team Jinotega tries to attend them all (f

Codeforces Round #397 by Kaspersky Lab and Barcelona Bootcamp (Div. 1 + Div. 2 combined) B

Description Kostya likes Codeforces contests very much. However, he is very disappointed that his solutions are frequently hacked. That's why he decided to obfuscate (intentionally make less readable) his code before upcoming contest. To obfuscate th

【codeforces 718E】E. Matvey&#39;s Birthday

题目大意&链接: http://codeforces.com/problemset/problem/718/E 给一个长为n(n<=100 000)的只包含‘a’~‘h’8个字符的字符串s.两个位置i,j(i!=j)存在一条边,当且仅当|i-j|==1或s[i]==s[j].求这个无向图的直径,以及直径数量. 题解:  命题1:任意位置之间距离不会大于15. 证明:对于任意两个位置i,j之间,其所经过每种字符不会超过2个(因为相同字符会连边),所以i,j经过节点至多为16,也就意味着边数至多