首页 > 代码库 > 【UVA】1346 - Songs(贪心)

【UVA】1346 - Songs(贪心)

根据题意可以得到,长度小,并且频率低的排到前面,所以设 k = l  / q;

之后sort排序就可以

141286751346SongsAcceptedC++0.0292014-09-01 11:30:14


#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <string>
#include <cstring>
#include <cmath>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
using namespace std;
const double eps = 1e-10;
#define MAXD 100000 + 10
#define _PI acos(-1.0)
struct Pow{
    double k;
    int n;
    double L;
    double Hz;
    friend bool operator <(Pow p,Pow q){
        return p.k < q.k;
    }
}value[MAXD];
int main(){
    int n;
   while(scanf("%d",&n) != EOF){
        for(int i = 0 ; i < n ; i++){
            scanf("%d%lf%lf",&value[i].n,&value[i].L,&value[i].Hz);
            value[i].k = 1.0 * value[i].L / value[i].Hz;
        }
        sort(value,value + n);
        int t;
        scanf("%d",&t);
        printf("%d\n",value[t - 1].n);
   }
   return 0;
}

【UVA】1346 - Songs(贪心)