"The Valley P1080" King game

Source: Internet
Author: User

We sort in ascending order by the product of the right or left hand number to minimize the maximum number of coins.

Why is it?

We know:

1) If the next two people exchange positions, will only affect the value of these two people, will not affect others

2) Assume the adjacent two persons I, i + 1. Set A[i] b[i] <= a[i + 1] b[i + 1],i before everyone's left hand product is S.

ans1 = Max{s/b[i], S * A[i]/b[i + 1]}

Ans2 = max{s/b[i + 1], S * a[i + 1]/b[i]}

Because, A[i] b[i] <= a[i + 1] b[i + 1]

So, S a[i]/b[i + 1] <= s a[i + 1]/b[i]

And because, S/b[i + 1] <= S * A[i]/b[i + 1]

So, ans2 = S * a[i + 1]/b[i]

ans1 = Max{s/b[i], S * A[i]/b[i + 1] (<=s a[i + 1]/b[i])}

So, ans1 <= ans2

As for high precision,

Here is the 60-point code, and yy a bit on the good

1#include <cstdio>2#include <cstring>3#include <algorithm>4 #definell Long Long5 using namespacestd;6 Const intn=20010;7 ll S[n],tmp[n];8 structfx{9 ll L,r,x;Ten}d[1010]; One BOOLCMP (FX a,fx b) { A     returna.x<b.x; - } - intMain () { the     intN; -ll ans=0, P,q; -scanf"%d",&n); -      for(intI=0; i<=n;i++){ +scanf"%lld%lld",&d[i].l,&D[I].R); -d[i].x=d[i].l*D[I].R; +     } ASort (d+1, d+n+1, CMP); atp=1; -      for(intI=1; i<=n;i++){ -p*=d[i-1].L; -         if(ans<p/D[I].R) -ans=p/D[I].R; -     } inprintf"%lld", ans); -     return 0; to}
-

"The Valley P1080" King game

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.