Codeforces Round #516 (Div. 1, by Moscow Team Olympiad) D
Posted rrsb
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Codeforces Round #516 (Div. 1, by Moscow Team Olympiad) D相关的知识,希望对你有一定的参考价值。
题链
Description
解一个线性规划(大雾)
Sol
单纯形我们发现我们可以暴力枚举转的圈数,而这个东西可以数论分块优化。
Code
#include <bits/stdc++.h> #define LL long long using namespace std; LL n,x,k,lb,ub,l,r,ans=-1; int main() { scanf("%lld%lld%lld%lld",&n,&l,&r,&k); x=(r>=l?r-l+1:r+n-l+1)%n; for(LL i=k,j,r;i;i=j){ j=k/(k/i+1);r=k/i; ub=min(2*n,i); lb=max(n,j+1); ub=min(ub,min((2*n+k-2*x+1)/(r+1),(k-x)/r)); lb=max(lb,(k-2*x+r-1)/r); if(ub>=lb)ans=max(ans,ub); } if(x<=k&&k<=x*2)ans=max(ans,n+min(k-x,x-1)+n-x+1); if(!x&&k==n)ans=max(ans,n+1); printf("%lld ",~ans?ans-n:ans); }
以上是关于Codeforces Round #516 (Div. 1, by Moscow Team Olympiad) D的主要内容,如果未能解决你的问题,请参考以下文章
Codeforces Round #516 (Div. 2&&Div.1)
Codeforces Round #516 (Div. 2, by Moscow Team Olympiad)
Codeforces Round #516 (Div. 1) 题解
[Codeforces Round #516][Codeforces 1063B/1064D. Labyrinth]