Codeforces Round #378 (Div. 2) D 贪心

本文解析了CodeForces竞赛中的一道D级难度题目,通过优化算法实现高效的解题策略。介绍了如何对输入数据进行预处理并使用特定的数据结构来简化问题,最终通过比较不同组合找到最优解。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

题目传送门:http://codeforces.com/contest/733/problem/D


思路:其实这题挺简单的,当时是过于自信导致错了n发。


代码如下:

#include <iostream>
#include <algorithm>
#include <cstring>
#include <stdio.h>
#include <string>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <bitset>
#include <cstdlib>

using namespace std;
#define   lson          l,m,rt<<1
#define   rson          m+1,r,rt<<1|1
#define   ll            long long
#define   ull           unsigned long long
#define   mem(n,v)      memset(n,v,sizeof(n))
#define   MAX           100005
#define   MAXN          105
#define   PI            3.1415926
#define   E             2.718281828459
#define   opnin         freopen("input.txt","r",stdin)
#define   opnout        freopen("output.txt","w",stdout)
#define   clsin         fclose(stdin)
#define   clsout        fclose(stdout)
#define   haha1         cout << "haha1"<< endl
#define   haha2         cout << "haha2"<< endl
#define   haha3         cout << "haha3"<< endl

const int    INF    =   0x3f3f3f3f;
const ll     INFF   =   0x3f3f3f3f3f3f3f3f;
const double pi     =   3.141592653589793;
const double inf    =   1e18;
const double eps    =   1e-8;
const ll     mod    =   1e18;
const ull    mx     =   133333331;
/**************************************************************************/
struct arr
{
    int a[3];
    int num;
    friend bool operator < (struct arr a,struct arr b){
        if(a.a[0] == b.a[0]){
            if(a.a[1] == b.a[1])
                return a.a[2] > b.a[2];
            else return a.a[1] > b.a[1];
        }
        else return a.a[0] > b.a[0];
    }
}ar[MAX];
int main()
{
    int n;
    cin >> n;
    int a[3];
    for(int i=0;i<n;i++){
        scanf("%d%d%d",&a[0],&a[1],&a[2]);
        sort(a,a+3);
        ar[i].a[0] = a[2];
        ar[i].a[1] = a[1];
        ar[i].a[2] = a[0];
        ar[i].num = i+1;
    }
    sort(ar,ar+n);
    int Max = 0;
    int id_n = 1;
    int id_x = -1;
    int id_y = -1;
    for(int i=0;i<n;i++){
        if(ar[i].a[2] > Max){
            Max = ar[i].a[2];
            id_x = ar[i].num;
        }
    }
    for(int i=1;i<n;i++){
        if(ar[i].a[0] == ar[i-1].a[0] && ar[i].a[1] == ar[i-1].a[1]){
            if(min(ar[i].a[2] + ar[i-1].a[2],ar[i].a[1]) > Max){
                Max = min(ar[i].a[2] + ar[i-1].a[2],ar[i].a[1]);
                id_n = 2;
                id_x = ar[i-1].num;
                id_y = ar[i].num;
            }
        }
    }
    cout << id_n << endl;
    if(id_n == 1){
        cout << id_x << endl;
    }
    else cout << id_x << ' ' << id_y << endl;

    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值