柑橘味砖头


私信TA

用户名:uq_73696371690

访问量:481

签 名:

等  级
排  名 9025
经  验 1125
参赛次数 0
文章发表 17
年  龄 0
在职情况 学生
学  校
专  业

  自我简介:

解题思路:在前面都选择花费总时间最少的 最后的答案一定是花费时间最少的

注意事项:记得开 long long

参考代码:

#include<bits/stdc++.h>

#define int long long

using namespace std;

struct st{

    int s,a,e,sum;

}st[1010];

int n,ans;

bool cmp(const struct st& p1,const struct st& p2){//从小到大

    return p1.sum<p2.sum;

}

signed main()

{   

    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

    cin>>n;

    for(int i=0;i<n;i++){

        cin>>st[i].s>>st[i].a>>st[i].e;

        st[i].sum=st[i].s+st[i].a+st[i].e;

    }

    sort(st,st+n,cmp);

    int temp=0;

    for(int i=0;i<n;i++){

        temp+=(st[i].s+st[i].a);

        ans+=temp;

        temp+=st[i].e;

        //cout<<temp<<" ";

    }

    cout<<ans<<endl;

    return 0;

}


 

0.0分

0 人评分

看不懂代码?想转换其他语言的代码? 或者想问其他问题? 试试问问AI编程助手,随时响应你的问题:

编程语言转换万能编程问答  

代码解释器

代码纠错

SQL生成与解释

  评论区