#include<cstdio>#include<iostream>#include<utility>#include<vector>#include<cstring>#include<cmath>#include<cstdlib>#include<algorithm>#include<queue>#include<set>#include<map>#include<set>#include<array>#include<random>#include<bitset>#include<ctime>#include<limits.h>#include<assert.h>#include<unordered_set>#include<unordered_map>#define int long long#define RI register int#define CI const int&#define mp make_pair#define fi first#define se second#define Tp template <typename T>usingnamespace std;
typedeflonglong LL;
typedeflongdouble LDB;
typedefunsignedlonglong u64;
typedef pair <int,int> pi;
typedef vector <int> VI;
typedef array <int,3> tri;
constint N=500005;
int t,n,k,a[N];
signedmain(){
//freopen("CODE.in","r",stdin); freopen("CODE.out","w",stdout);for (scanf("%lld",&t);t;--t)
{
RI i; for (scanf("%lld%lld",&n,&k),i=1;i<=n;++i) scanf("%lld",&a[i]);
auto check=[&](CI lim)
{
int cur=0; for (RI i=1;i<=n;++i) cur+=max(0LL,lim-a[i]); return cur<=k;
};
int l=1,r=2e12,ret=0,mid; while (l<=r)
if (check(mid=l+r>>1)) ret=mid,l=mid+1; else r=mid-1;
if (ret==0) { puts("0"); continue; }
for (i=1;i<=n;++i) if (a[i]<ret) k-=(ret-a[i]),a[i]=ret;
sort(a+1,a+n+1,greater <int>());
for (i=1;i<=n;++i) if (a[i]==a[n]&&k>0) --k,++a[i];
int ans=n*a[n]-(n-1);
for (i=1;i<=n;++i) if (a[i]!=a[n]) ++ans;
printf("%lld\n",ans);
}
return0;
}
3|0B1. Reverse Card (Easy Version)
手玩一下式子会发现a必须是b的倍数,不妨设a=kb,此时gcd(a,b)=b
化一下式子会发现此时的限制就是b∣(k+1),直接枚举b的值计算即可
#include<cstdio>#include<iostream>#include<utility>#include<vector>#include<cstring>#include<cmath>#include<cstdlib>#include<algorithm>#include<queue>#include<set>#include<map>#include<set>#include<array>#include<random>#include<bitset>#include<ctime>#include<limits.h>#include<assert.h>#include<unordered_set>#include<unordered_map>#define RI register int#define CI const int&#define mp make_pair#define fi first#define se second#define Tp template <typename T>usingnamespace std;
typedeflonglong LL;
typedeflongdouble LDB;
typedefunsignedlonglong u64;
typedef pair <int,int> pi;
typedef vector <int> VI;
typedef array <int,3> tri;
int t,n,m;
intmain(){
//freopen("CODE.in","r",stdin); freopen("CODE.out","w",stdout);for (scanf("%d",&t);t;--t)
{
LL ans=0; scanf("%d%d",&n,&m);
for (RI b=1;b<=m&&1LL*b*(b-1)<=n;++b)
if (ans+=1LL*(n+b)/(1LL*b*b),b==1) --ans;
printf("%lld\n",ans);
}
return0;
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 地球OL攻略 —— 某应届生求职总结
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 提示词工程——AI应用必不可少的技术
· .NET周刊【3月第1期 2025-03-02】
2019-05-08 Luogu P5349 幂
2019-05-08 Luogu P5351 Ruri Loves Maschera
2018-05-08 CODE[VS] 1159 最大全0子矩阵
2018-05-08 关于树链剖分的一些算法
2018-05-08 Luogu P3373 【模板】线段树 2
2018-05-08 EZ 2018 05 06 NOIP2018 慈溪中学集训队互测(五)