P1080 King Game

Source: Internet
Author: User

Violence does not write, direct copy of the series ...

This problem is a greedy word. But the point is how to prove that greed is right.

Need to give a certain arrangement to get the most money of the minister to take the least, is actually a sort.

We discuss the relationship between the two ministers, how to make the answer to the smallest.

Set two ministers a a\, a called \ ( b\), the product of the left hand of the people in front of them (including The king) is collectively known as \ (tot\).

When \ (a\) in front of \ (b\) , then \ (a\) get the money is \ (\frac{tot}{r_a}\),\ (b\) get the money is \ (\ Frac{tot \times l_a}{r_b}\).

And when \ (b\) in front of \ (a\) , then \ (b\) get the money is \ (\frac{tot}{r_b}\),\ (a\) get the money is \ (\ Frac{tot \times l_b}{r_a}\).

Obviously, the first situation \ (b\) get more money than the second situation \ (a\) take more money, and the second case \ (b\) get more money than the first case \ (a\) get more money.

So we don't need to compare these two pairs of sizes ...

Now the second situation is better.

Then there must be \ (\frac{tot \times l_b}{r_a} < \frac{tot \times l_a}{r_b}\), can be about (tot\), and multiplied by \ (r_ ar_b\), you can get

\[l_b \times r_b < l_a \times R_a\]

So in between, the left hand in the right hand of the product smaller, the answer will be smaller.

Such proofs can be set up in the bubble sort, and what about the other sort?

Also set up! Does the bubble set up, the Quick Platoon is not set up?!

So this is the solution to this problem: according to the left hand multiplied by the right hand of the product from small to large sort, everyone counted his own money, take Max.

Then the killer came: This problem requires high precision!

But also simple high-precision. Because this problem only needs to deal with the high-precision multiplication of the low-precision and high-precision divided by the two operations, overloaded operators can be done.

Because I have not mastered these high-precision and low-precision mutual computing things, so also copied someone else's puzzle ...

Code:

#include <cstdio> #include <cstring> #include <algorithm>const int maxn = 1005;struct nodes{int L, R;    BOOL operator < (const Nodes &AMP;RHS) Const {return L * R < RHS.L * RHS.R;    }} s[maxn];int n;int L, r;struct int{int a[10005], Len;        INT () {memset (A, 0, sizeof a);    len = 0;        } void init (int x) {if (x = = 0) len = 1;                else {while (x) {a[len++] = x 10;            x/= 10;        }}} BOOL operator < (const INT &AMP;RHS) Const {if (len! = Rhs.len) return len < Rhs.len;            for (int i = len-1; I >= 0; i--) {if (A[i] < Rhs.a[i]) return true;        else if (A[i] > Rhs.a[i]) return false;    } return false;        } int operator * (const int &AMP;RHS) const {INT ret;        for (int i = 0; i < len; i++) ret.a[i] = a[i] * RHS;        int Llen; for (int i = 0; I < Len | | Ret.a[i];                i++) {if (Ret.a[i]/ten) {Ret.a[i + 1] + = Ret.a[i]/10;            Ret.a[i]%= 10;        } Llen = i;        } if (Ret.a[llen] = = 0) Ret.len = Llen;        else Ret.len = Llen + 1;    return ret;        } int operator/(const int &x) const {INT ret;        Ret.len = Len;        int rest = 0;            for (int i = len-1; I >= 0; i--) {rest = rest * + a[i];            Ret.a[i] = rest/x;        Rest%= x;        } while (Ret.len > 1 && ret.a[ret.len-1] = = 0) ret.len--;    return ret;        } void Print () {for (int i = len-1; I >= 0; i--) printf ("%d", a[i]);    printf ("\ n");        }};int Main () {/* while (233) {int x, y; scanf ("%d%d", &x, &y); INT xx;        Xx.init (x); INT yy;        Yy.init (y);        INT res1 = xx * y, res2 = xx/y;        Res1.print ();        Res2.print (); Printf("%d\n", xx < yy);    } return 0;    */scanf ("%d%d%d", &n, &l, &r);    for (int i = 1; I <= n; i++) scanf ("%d%d", &AMP;S[I].L, &AMP;S[I].R);    Std::sort (S + 1, s + n + 1); INT temp;    Temp.init (L);    INT ans;        for (int i = 1; I <= n; i++) {ans = Std::max (ans, TEMP/S[I].R);    temp = temp * S[I].L;    } ans.print ();    return 0; }

P1080 Kings Games

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.