CSP-J 2021 T1 题解

· · 个人记录

前言

不要for!不要for!!

本人 O(N) 复杂度交上去 70pts 亏死了!

不过成绩出来本题 100pts 大惊,CCF数据水的一批……

思路

70pts

用for枚举 LR,然后边跑for边取 max

100pts

因为余数最大 n-1,所以我们只要看余数为 n-1 的数是否在 LR 之间存在就行了,不存在输出 R\bmod n

code

#include<bits/stdc++.h>
using namespace std;
int main(){
// freopen("candy.in","r",stdin);
// freopen("candy.out","w",stdout);
   int n,l,r,ans1,ans2;
   cin>>n>>l>>r;
   ans1=r%n;
   if(r/n*n>l) ans2=n-1;
   else ans2=-1;
   cout<<max(ans1,ans2);
   return 0;
}