牛吃fafa

Protecting the Flowers

https://ac.nowcoder.com/acm/problem/25043

//牛吃fafa 
//贪心,按照t/d排序 
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
struct cow
{
    ll ti,d;
    ll  flo,sum_t;//flo是数到每头牛破坏花的总和,sum_t是从第一头到当前牛所耗的全部时间 
}t[100005];
bool cmp(cow a,cow b)
{
    return a.ti*b.d<b.ti*a.d;//排序 
}
int main()
{
    int i,n;
    cin>>n;
    for(i=1;i<=n;i++)    cin>>t[i].ti>>t[i].d;
    sort(t+1,t+n+1,cmp);
    t[1].flo=0;//注意雷区,第一头牛没破坏花 
    t[1].sum_t=2*t[1].ti; 
    for(i=2;i<=n;i++)
    {
        t[i].sum_t=t[i-1].sum_t+2*t[i].ti;//更新所用时间 
        t[i].flo=t[i-1].flo+t[i].d*t[i-1].sum_t;//更新当前牛破坏花的和 
    }
    cout<<t[n].flo<<endl;//输出 
}
全部评论

相关推荐

程序员花海:实习和校招简历正确格式应该是教育背景+实习+项目经历+个人评价 其中项目经历注意要体现业务 实习经历里面的业务更是要自圆其说 简历模板尽可能保持干净整洁 不要太花哨的
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务