解题思路:在前面都选择花费总时间最少的 最后的答案一定是花费时间最少的
注意事项:记得开 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语言代码)浏览:1395 |
P1001 (C++代码)浏览:774 |
汽水瓶 (C语言代码)怎么答案错误?????浏览:794 |
求圆的面积 (C语言代码)浏览:1269 |
2003年秋浙江省计算机等级考试二级C 编程题(1) (C语言代码)浏览:603 |
C语言程序设计教程(第三版)课后习题3.7 (C语言代码)浏览:840 |
【绝对值排序】 (C语言代码)浏览:820 |
【计算直线的交点数】 (C语言代码)浏览:1443 |
字符逆序 (C语言代码)浏览:609 |
C语言程序设计教程(第三版)课后习题5.8 (C语言代码)浏览:1153 |