UVA - 1346 Songs (贪心+排序)
题意:已知每首歌的标号,长度和播放频率,求一种播放顺序,使得 最小,并且输出该播放顺序下第t首歌的标号。
最小,并且输出该播放顺序下第t首歌的标号。
分析:
1、长度越短,播放频率越大的歌排在前面,上式越小。
2、s(i)表示的是当前播放顺序下这首歌是第几个播放。
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<iostream>
#include<sstream>
#include<iterator>
#include<algorithm>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<deque>
#include<queue>
#include<list>
#define lowbit(x) (x & (-x))
const double eps = 1e-8;
inline int dcmp(double a, double b){
    if(fabs(a - b) < eps) return 0;
    return a > b ? 1 : -1;
}
typedef long long LL;
typedef unsigned long long ULL;
const int INT_INF = 0x3f3f3f3f;
const int INT_M_INF = 0x7f7f7f7f;
const LL LL_INF = 0x3f3f3f3f3f3f3f3f;
const LL LL_M_INF = 0x7f7f7f7f7f7f7f7f;
const int dr[] = {0, 0, -1, 1, -1, -1, 1, 1};
const int dc[] = {-1, 1, 0, 0, -1, 1, -1, 1};
const int MOD = 1e9 + 7;
const double pi = acos(-1.0);
const int MAXN = 70000 + 10;
const int MAXT = 10000 + 10;
using namespace std;
struct Node{
    int id, len;
    double f;
    double k;
    void read(){
        scanf("%d%d%lf", &id, &len, &f);
        k = len / f;
    }
    bool operator < (const Node&rhs)const{
        return k < rhs.k;
    }
}num[MAXN];
int main(){
    int n;
    while(scanf("%d", &n) == 1){
        for(int i = 1; i <= n; ++i){
            num[i].read();
        }
        sort(num + 1, num + 1 + n);
        int t;
        scanf("%d", &t);
        printf("%d\n", num[t].id);
    }
    return 0;
}

 
                
            
         浙公网安备 33010602011771号
浙公网安备 33010602011771号