【NOIP2012 提高组 day1】国王游戏
题解这道题是一道贪心题,大家只需要找到贪心策略是左手与右手的乘积,然后从小到大sort一下就OK了;(不过大家有一点需要小小注意一下,需要打一个高精度,要不然就只有60了)
#include<bits/stdc++.h>
#define MAXN 10005
using namespace std;
int a[10005],n,len,x,y;
struct each{
long long a,b;
}use[10005];
bool cmp(const each x,const each y){
return x.a*x.b < y.a*y.b;
}
void m(int x){
for(int i=1; i<=len; i++){
a[i]*=x;
}
for(int i=1; i<=len; i++){
if(a[i]>=10)
{
a[i+1]+=a[i]/10;
a[i]%=10;
}
if(i==len&&a[i+1]!=0)len++;
}
}
void d(int mod){
int rest=a[len];
int i;
for(i=len-1; i>0; i--){
if(rest>=mod)break;
rest=rest*10+a[i];
}
if(rest<mod){
printf("1");
return;
}
while(i>0){
printf("%d",rest/mod);
rest%=mod;
rest=rest*10+a[i--];
}
printf("%d",rest/mod);
}
int main(){
cin>>n>>x>>y;
for(long long i=1; i<=n; i++){
scanf("%d%d",&use[i].a,&use[i].b);
}
sort(use+1,use+n+1,cmp);
a[1]=x;
len=1;
for(int i=1; i<n; i++){
m(use[i].a);
}
d(use[n].b);
return 0;
}