跳到正文

个人记录

CSP-J 2021 T1 题解

luqyou约 1 分钟
原文
文章信息与版本

文章信息

收录
2025年12月12日
更新
2026年6月25日
篇幅
约 1 分钟

版本

  1. v1当前

前言

不要for!不要for!!

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

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

思路

70pts70pts

用for枚举 LL 到 RR,然后边跑for边取 maxmax。

100pts100pts

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

code

C++
#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;
}
原文
存档评论1 条抓取于