- wsh 的博客
8月week2Day 1总结
- @ 2024-8-12 20:30:18
作者附:第四题还是没做出来....... 只能写第一题的题解了
T1糖果
思路
我们对于一个n可以写出一个答案数组(假设n==5):
0,1,2,3,4,0,1,2,3,4,0,1,2,3,4,0
--------l-------r------------
那么答案其实就是在l~r这个区间取值
如果最大值n-1在此区间内(r/n*n>=l) 答案就是n-1
否则这一定是个单调递增区间 取最大值即可
附Ac代码
#include<bits/stdc++.h>
using namespace std;
int n,l,r;
void fropn(string a){
string t1=a+".in",t2=a+".out";
freopen(t1.c_str(),"r",stdin);
freopen(t2.c_str(),"w",stdout);
}
int main()
{
fropn("candy");
cin>>n>>l>>r;
if(r/n*n-1>=l) cout<<n-1;
else cout<<r%n;
return 0;
}