解题思路:在前面都选择花费总时间最少的 最后的答案一定是花费时间最少的
注意事项:记得开 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语言训练-大、小写问题 (C语言代码)浏览:614 |
WU-格式化数据输出 (C++代码)浏览:1212 |
wu-淘淘的名单 (C++代码)浏览:1339 |
C语言程序设计教程(第三版)课后习题8.6 (C语言代码)浏览:567 |
C语言程序设计教程(第三版)课后习题8.8 (C语言代码)浏览:1433 |
C语言程序设计教程(第三版)课后习题1.6 (C语言代码)浏览:476 |
图形输出 (C语言代码)浏览:945 |
C语言程序设计教程(第三版)课后习题5.7 (C语言代码)浏览:578 |
三角形 (C语言代码)浏览:659 |
C语言程序设计教程(第三版)课后习题5.4 (C语言代码)浏览:531 |