解题思路:在前面都选择花费总时间最少的 最后的答案一定是花费时间最少的
注意事项:记得开 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 人评分
C语言程序设计教程(第三版)课后习题8.3 (C语言代码)浏览:638 |
P1001 (C语言代码)浏览:801 |
DNA (C语言描述,数据结构)浏览:861 |
字符逆序 (C语言代码)浏览:646 |
C语言程序设计教程(第三版)课后习题5.6 (C语言代码)浏览:902 |
C语言程序设计教程(第三版)课后习题9.10 (C语言代码)浏览:835 |
第三届阿里中间件性能挑战赛-总决赛亚军比赛攻略浏览:1145 |
C语言程序设计教程(第三版)课后习题7.3 (C语言代码)浏览:534 |
C语言程序设计教程(第三版)课后习题3.7 (C语言代码)浏览:607 |
C语言程序设计教程(第三版)课后习题10.7 (C++代码)浏览:654 |