第一章-問題求解策略-LA3303-Songs

分類:貪心
題目鏈接:LA3303-Songs
對於某兩首歌曲song[i]+song[i+1],差別只有l[i]*f[i+1]或l[i+1]*f[i]按這個排序即可

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e6+10;
struct node
{
    ll id,le;
    double fr;
    bool operator < (const node &rhs) const
    {
        return fr*rhs.le<rhs.fr*le;
    }
}a[maxn];
int n,t;
int main()
{
    while(scanf("%d",&n)!=EOF)
    {
        for(int i=1;i<=n;i++)
        {
            scanf("%lld %lld %lf",&a[i].id,&a[i].le,&a[i].fr);
        }
        sort(a+1,a+1+n);
        scanf("%d",&t);
        printf("%d\n",a[t].id);
    }
    return 0;
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章