UVA-1346 Songs (greedy + sort)

Source: Internet
Author: User

Test instructions: The label, length, and frequency of each song are known, and the order of the play is obtained, which makes the minimum and output the label of the first song in the playing order.

Analysis:

1, the shorter the length, the greater the frequency of the song row in front, the smaller the style.

2, S (i) is the current playing order of the song is the first few plays.

#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) < 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 I NT 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;con    St 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&AMP;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;}

UVA-1346 Songs (greedy + sort)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.