题目:https://codeforces.com/contest/1223/problem/C
注意:二分的写法,容易搞错
#include<bits/stdc++.h>
#define LL long long
#define INF 0x3f3f3f3f3f3f3f3f
using namespace std;
const int maxn=200005;
const int mod=1e9+7;
LL p[maxn];
LL x,a,y,b,k;
LL sum[maxn];
LL gcd(LL a,LL b)
{
if(b==0) return a;
return gcd(b,a%b);
}
bool cmp(LL a,LL b)
{
return a>b;
}
int main()
{
ios::sync_with_stdio(false);
int q;
cin>>q;
while(q--)
{
int n;
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>p[i];
}
sort(p+1,p+n+1,cmp);
sum[0]=0;
for(int i=1;i<=n;i++)
{
sum[i]=sum[i-1]+p[i];
}
cin>>x>>a>>y>>b>>k;
if(x<y)
swap(x,y),swap(a,b);
LL l,r;
l=1;r=n;
LL ans;
LL lcm=a*b/gcd(a,b);
while(l<=r)
{
LL mid=(l+r)/2;
LL both=mid/lcm;
LL aval=mid/a-both;
LL bval=mid/b-both;
LL zsum=0;
zsum+=sum[both]/100*(x+y);
zsum+=(sum[both+aval]-sum[both])/100*x;
zsum+=(sum[both+aval+bval]-sum[both+aval])/100*y;
if(zsum>=k)
{
//ans=mid;
r=mid-1;
}
else
{
l=mid+1;
}
}
if(l>n)
cout << -1 << endl;
else
cout << l << endl;
}
return 0;
}
本文详细解析了Codeforces竞赛中的一道题目,采用C++实现,重点介绍了如何使用二分查找算法来解决复杂的问题,包括数据预处理、排序、前缀和及数学运算等关键步骤。
&spm=1001.2101.3001.5002&articleId=102740598&d=1&t=3&u=aeacaf797ce04e9b90e22218e1970e81)
359

被折叠的 条评论
为什么被折叠?



