算法小白求救大佬,只有10分(QWQ,一早已经求救两次了),板子学的是董晓老师的
// Problem: B3881 [信息与未来 2015] 拴奶牛
// Contest: Luogu
// URL: https://www.luogu.com.cn/problem/B3881
// Memory Limit: 128 MB
// Time Limit: 1000 ms
//
// Powered by CP Editor (https://cpeditor.org)
#include<bits/stdc++.h>
using namespace std;
const int N=1e6+10;
int n,k,p[N];
bool check(int x)
{
//假设x是两头奶牛间最小距离,那么假设所有奶牛距离都是x,求出最后一头奶牛的位置
int ip=p[1]+(n-1)*(x+1);
if(ip<=p[k])return true;
else return false;//最后一头奶牛栓的位置超过p[k],可以缩小x,r=mid
}
void solve()
{
cin>>n>>k>>p[1];
for(int i=2;i<=k;i++)
p[i]=p[i-1]+((p[i-1]*2357+137)%10)+1;
int l=0,r=100000;
while(l+1<r)
{
int mid=l+r>>1;
if(check(mid))l=mid;
else r=mid;
}
cout<<l<<endl;
}
int main()
{ ios::sync_with_stdio(false);cin.tie(0),cout.tie(0);
solve();
return 0;
}