思路讲解
?即是有多少个数不参与这个移动

当然这个公式只有在特定条件下才能用
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| if(K==0){ if(First>=N){ std::cout<< N<<"\n"; }else if(First>=N-2){ std::cout<< N-1<<"\n"; }else{ std::cout<<-1<<"\n"; } }else{ if(First>=N){ std::cout<< N<<"\n"; }else{ ll res=(N-First-1)/K+1; std::cout<< N-res<<"\n"; } }
|
AC代码
https://codeforces.com/contest/2028/submission/300282002
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
| #include <iostream> #include <cstring> #include <algorithm> #include <deque> #include <queue> #include <vector> #include <set> #include <map> #include <cmath> #include <bitset> #include <iterator> #include <random> #include <iomanip> #include <cctype> #include <array>
typedef long long ll; typedef std::pair<ll,ll> pll; const ll MAXN=static_cast<ll>(2e5)+10; ll N,T,K,First;
void solve(){ std::cin>>N>>K>>First; if(K==0){ if(First>=N){ std::cout<< N<<"\n"; }else if(First>=N-2){ std::cout<< N-1<<"\n"; }else{ std::cout<<-1<<"\n"; } }else{ if(First>=N){ std::cout<< N<<"\n"; }else{ ll res=(N-First-1)/K+1; std::cout<< N-res<<"\n"; } } return; }
int main() { std::ios::sync_with_stdio(false); std::cin.tie(0);std::cout.tie(0); std::cin>>T; while (T--) { solve(); } return 0; }
|
心路历程(WA,TLE,MLE……)