Describe
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.
Format input Format
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 format
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.
Input:
3
1 1
2 3
7 4
4 6
Output:
2
Idea: the minister according to the whole number of left-and-left order from small to large, in order to solve the overflow problem, using C + + large numbers.
#include <iostream>#include<iomanip>#include<string.h>#include<algorithm>using namespacestd;Const intmaxn=10005;Const intBase=10000;Const intlen=4;structbigint{intE[maxn],len; BigInt () {memset (E,0,sizeof(e)); Len=0; } void Set(intx) {memset (E,0,sizeof(e)); Len=0; while(x>0) {E[len++]=x%BASE; X/=BASE; } } BOOL operator> (ConstBigInt &b) {if(len>B.len) {return true; } Else if(len==B.len) { for(inti=len-1; i>=0; i--) { if(E[i]>b.e[i])return true; Else if(E[i]<b.e[i])return false; Else ; } return false; } Else { return false; }} BigIntoperator*(ConstBigInt &b) {BigInt res; for(intI=0; i<len;i++) { intup=0; for(intj=0; j<b.len;j++) { intz=e[i]*b.e[j]+up+res.e[i+J]; Res.e[i+j]=z%BASE; up=z/BASE; } if(up!=0) res.e[i+b.len]=Up ; } Res.len=len+B.len; while(res.len>1&&res.e[res.len-1]==0) res.len--; returnRes; } BigIntoperator/(Const int&b) {BigInt res=* This; intcarry=0; for(inti=len-1; i>=0; i--) {Res.e[i]+=carry*BASE; Carry=res.e[i]%b; Res.e[i]/=b; } while(res.len>1&&res.e[res.len-1]==0) res.len--; returnRes; } Friend Ostream&operator<< (Ostream & out,ConstBigInt &b) { out<<b.e[b.len-1]; for(inti=b.len-2; i>=0; i--) { out<<SETW (LEN) <<setfill ('0') <<B.e[i]; } out<<Endl; return out; }};structnode{intx, y;} MON[MAXN];BOOLCompConstNode &a,ConstNode &b) { returnA.x*a.y < b.x*b.y;}intN,kl,kr;intMain () {CIN>>N; CIN>>kl>>KR; for(intI=0; i<n;i++) {cin>>mon[i].x>>mon[i].y; } sort (Mon,mon+N,comp); BigInt Res; Res.Set(0); BigInt Mul; Mul.Set(KL); for(intI=0; i<n;i++) {BigInt tmp; TMP=mul/mon[i].y; if(tmp>res) res=tmp; BigInt b; B.Set(mon[i].x); Mul=mul*b; } cout<<res<<Endl; return 0;}
vijos1779 King Game