0%

CF 986-B. Alice's Adventures in Permuting

思路讲解

?即是有多少个数不参与这个移动

image

当然这个公式只有在特定条件下才能用

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){
// 不用移动N次,因为N有一个数可以作为不动数
std::cout<< N-1<<"\n";
}else{
std::cout<<-1<<"\n";
}
}else{
if(First>=N){
std::cout<< N<<"\n";
}else{
// res即是上图的?
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){
// 不用移动N次,因为N有一个数可以作为不动数
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;
}
/*
AC https://codeforces.com/contest/2028/submission/300282002
1
10 10 10

9

1
1 0 0

1
1 1 2

*/

心路历程(WA,TLE,MLE……)