"Greedy + sort" King game

Source: Internet
Author: User
Tags mul

"Greedy + sort" King game

Time limit:1000ms
Memory limit:131072kb

Description
Coincides with the national Day of H, the King invited the N ministers to play a prize-winning game. First, he had each minister write an integer on the left and right, and the king himself wrote an integer on the left and right. Then, let the N-ministers in a row, the king standing in front of the team. When the team is lined up, all the ministers receive several gold coins for the king's reward, and each minister obtains the number of gold coins: the product of the number of the left hand of everyone in front of the minister divided by the number of his own right hand, and then rounded down to get the result.
The king does not want a particular minister to receive a special reward, so he wants you to help him rearrange the order of the ranks so that the most rewarding ministers receive as little reward as possible. Note that the king's position is always at the front of the team.




Input
The first line contains an integer n, representing the number of ministers.
The second line contains two integers a and b, separated by a space, representing the whole number of the king's left and right hand.
Next n rows, each line contains two integers a and b, separated by a space, representing the integers on the left and right of each minister, respectively.




Output
The output has only one row and contains an integer that represents the number of gold coins received by the most awarded ministers in the rearranged ranks.




Sample Input
3
1 1
2 3
7 4
4 6




Sample Output
2




Hint
"Input and Output Sample description" Press 1, ministers of the 2 and 3rd rank in such a way that the ministers who received the most prizes received 2 gold coins, 1, 3 and 2 in order to receive the highest number of gold coins (2), and 2, 1 and 3 in order to receive the highest number of gold coins by the ministers who received the most prizes: 2, 2 and 1 Such ranks, the most rewarding ministers receive 9 gold coins, 3, 1, 2 such ranks, the most rewarding ministers receive gold coins of 2, according to 3, 2, 1 such a team, the most awarded by the Minister of the number of gold coins is 9.
As a result, the most rewarding minister receives at least 2 gold coins, and the answer output is 2.

"Data Range"
For 20% of the data, there are 1≤n≤10,0 < A, b < 8; for 40% data, there are 1≤n≤20,0 < A, b < 8;
For 60% of the data, there are 1≤n≤100;
For 60% of the data, the answer is not more than 109;
For 100% of data, there are 1≤n≤1,000,0 < A, b < 10000.



Source
noip2012

The data is very water.

20 minutes of mob search.

I didn't expect the key to be sorted by the results of either hand.

So weak, so sad.

I'm using my left hand for the keyword sort of error greedy plus 30 points for the mob search

Positive solution:

Let's first consider the situation of only two people.

First person: L/r1 l*l1/r2; obviously l*l1/r2>l/r1;

A second person: L/R2 l*l2/r1; It's obvious l*l2/r1>l/r2;.

Compare Max (L1/R2,L2/R1) = (L1*R1,L2*R2);

So you can use greed in the order of the product of the right hand and then enumerate


TOT, I'm a high-precision, TM-ugly.

Three points out of time.

But the data is very water.

Just enumerate the last person with the first person

It's still not understood.

To prove that enumerating the last person with the first person is the right amount

So the leader was right about Noip's data is very water.

So I'm going to practice high-precision first.

# include<stdio.h># include<cstring># include<iostream># include<vector># include<algorithm>using namespacestd;Const intmaxn=10000; typedefLong LongLL;CharTB[MAXN];structnode{LL l; LL R;} edge[ ++Ten]; LL Gl,gr,n,min=-0x7fffffff, min=0x7fffffff; LL VIS[MAXN],A[MAXN],C[MAXN],STR[MAXN]; LL CMP (ConstNode &a,ConstNode &B) {    returna.l*a.r<b.l*B.R;}voidCheck () {if(a[0]<str[0])return; Else if(a[0]>str[0]) {str[0]=a[0]; for(intI=1; i<=a[0];i++) str[i]=c[i];} Else if(a[0]==str[0])     for(inti=a[0];i>=1; i--)    if(c[i]>Str[i]) {     for(intI=1; i<=a[0];i++) str[i]=C[i];  Break; }}voidMul (ll x) {ll i,m=0;  for(i=1; i<=a[0];i++) {m=m+a[i]*x; A[i]=m%Ten; M=m/Ten; }   while(m!=0) {a[0]++; a[a[0]]=m%Ten; M=m/Ten; }}voidBinintb) {LL x=0;  for(LL i=a[0];i>=1; i--) {C[i]= (x*Ten+a[i])/b; X= (x*Ten+a[i])%b; }     while(c[a[0]]==0&&a[0]!=1) a[0]--;}voidinit () {cin>>N; CIN>>gl>>GR;  for(LL i=1; i<=n;i++) scanf ("%i64d%i64d",&edge[i].l,&EDGE[I].R);}voidyy () {LL x1=-0x7fffffff, x2=-0x7fffffff; Sort (Edge+1, edge+n+1, CMP);  for(LL i=n;i<=n;i++) {memset (A,0,sizeof(a)); Memset (c,0,sizeof(c)); LL cur=0; LL T=GL;  while(t!=0) {a[++cur]=t%Ten; t=t/Ten;} a[0]=cur;  for(LL j=1; j<i;j++) Mul (EDGE[J].L);        Di (EDGE[I].R);    Check (); }         for(LL i=1; i<=1; i++) {memset (A,0,sizeof(a)); Memset (c,0,sizeof(c)); LL cur=0; LL T=GL;  while(t!=0) {a[++cur]=t%Ten; t=t/Ten;} a[0]=cur;  for(LL j=1; j<i;j++) Mul (EDGE[J].L);        Di (EDGE[I].R);    Check (); }     for(inti=str[0];i>=1; i--) cout<<str[i];}voidDFS (LL cur,ll much) {if(cur==N)        {LL k;  for(LL i=1; i<=n;i++)        if(!vis[i]) {k=i; Break;} MIN=min (min,much/EDGE[K].R); return; }     for(LL i=1; i<=n;i++)    if(!Vis[i]) {Vis[i]=1; DFS (cur+1, much*EDGE[I].L); Vis[i]=0; }}voidEasy () {DFS (1, GL); cout<<MIN;}intMain () {init (); //Easy ();yy (); return 0;}

"Greedy + sort" 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.