analysis
random_shuffle是个好东西
就这样
如果random数组的话,记得要映射回来,否则凉透(所以还是用结构体吧)
表示不会打高精度
code
结构体版
#include<bits/stdc++.h>
using namespace std;
#define loop(i,start,end) for(register int i=start;i<=end;++i)
#define anti_loop(i,start,end) for(register int i=start;i>=end;--i)
#define max(a,b) ((a>b)?a:b)
#define min(a,b) ((a<b)?a:b)
#define ll long long
#define clean(arry,num) memset(arry,num,sizeof(arry))
const int maxn=1010;
int n;
struct node{
int left;int right;
}que[1010];
template<typename T>void read(T &x)
{
x=0;char r=getchar();T neg=1;
while(r>'9'||r<'0'){if(r=='-')neg=-1;r=getchar();}
while(r<='9'&&r>='0'){x=(x<<1)+(x<<3)+r-'0';r=getchar();}
x*=neg;
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("datain23.txt","r",stdin);
#endif
srand(time(0));
read(n);
read(que[0].left),read(que[0].right);
loop(i,1,n)read(que[i].left),read(que[i].right);
ll res=LONG_LONG_MAX,maxx,sum;
loop(times,1,10000){
random_shuffle(que+1,que+1+n);
maxx=-1;
sum=que[0].left;
loop(i,1,n){
maxx=max(maxx,sum/que[i].right);
if(maxx>=res)break;
sum*=que[i].left;
}
res=min(res,maxx);
}
printf("%lld",res);
return 0;
}
数组版
#include<bits/stdc++.h>
using namespace std;
#define loop(i,start,end) for(register int i=start;i<=end;++i)
#define anti_loop(i,start,end) for(register int i=start;i>=end;--i)
#define max(a,b) ((a>b)?a:b)
#define min(a,b) ((a<b)?a:b)
#define ll long long
#define clean(arry,num) memset(arry,num,sizeof(arry))
const int maxn=1010;
int que[maxn];
int a[maxn];
int b[maxn];
int n;
template<typename T>void read(T &x)
{
x=0;char r=getchar();T neg=1;
while(r>'9'||r<'0'){if(r=='-')neg=-1;r=getchar();}
while(r<='9'&&r>='0'){x=(x<<1)+(x<<3)+r-'0';r=getchar();}
x*=neg;
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("datain23.txt","r",stdin);
#endif
srand(time(0));
read(n);
loop(i,0,n){
read(a[i]),read(b[i]);
que[i]=i;
}
register int times=10000;
register ll minn_max=LONG_LONG_MAX;
while(times--){
random_shuffle(que+1,que+1+n);
ll res=a[que[0]];
int maxx=-1;
loop(i,1,n){
maxx=max(maxx,(res/b[que[i]]));
if(minn_max<=maxx)break;
res*=a[que[i]];
}
minn_max=min(minn_max,maxx);
}
printf("%lld",minn_max);
return 0;
}