CF 1823B B. Sort with Step

CF 1823B B. Sort with Step

Problem - B - Codeforces

题意:

给n长的数组,里边只有1-n的数字,问你能不能在k步长的交换内换成升序的1-n

AC代码:

首先给你1-n的数字还要排成增序;

对于3 4 1 2

3在第1个数, abs(3 - 1) % 2 == 0;

所以3可以在步长为2的交换中换回位置3

对于步长为2 , 如果你在1的位置,所有你能换的就是1 3 5 7 …

所以对于a[i],要想能够换到i的位置,就看abs(a[i] - i) % k == 0是否成立

先跑一遍看看有几个位置是换不到的,如果这些位置的数量超过2,那肯定是不可能提前交换一次能处理的了,直接输出-1;

如果刚好有两个位置,那就判断交换之后他们能不能让自己跑回原来的位置:

行的话输出1,不行就-1,

如果只有一个位置换不了,那寄,输出-1;

不存在需要交换的位置,赢,输出0;

#include<bits/stdc++.h>
#define IO std::ios::sync_with_stdio(false); \
std::cin.tie(0);                             \
std::cout.tie(0)

#define all(v) v.begin(),v.end()

#define int long long
#define PII pair<ll,int>
#define ld long double
#define x first
#define y second
#define endl '\n'
#define inf 0x3f3f3f3f
using namespace std;
const int N = 2e5+10;
void solve()
{
    int n,k;
    cin>>n>>k;
    vector<int> a(n+1),p(n+1),s;
    bool ok = 1;

    for(int i = 1;i<=n;i++){
        cin>>a[i];
        p[a[i]] = i;
        if(abs(i -  a[i]) % k != 0){
            ok = 0;
            s.push_back(a[i]);
        }
    }
    if(ok)cout<<"0"<<endl;
    else{
        if(s.size() > 2){
            cout<<"-1"<<endl;
        } else{
            if(s.size() == 2){
                auto x = s[0],y = s[1];
                if(abs(p[y] - x) % k == 0 && abs(p[x] - y) % k == 0)cout<<"1"<<endl;
                else cout<<"-1"<<endl;
            } else{
                cout<<"-1"<<endl;
            }
        }
    }
}
signed main(){
    int t;
    cin>>t;
    while(t--)
    {
    solve();
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
Form Circle is the circle which defines the deepest points of involute form control of the tooth profile. This circle along with the tooth tip circle (or start of chamfer circle) determines the limits of tooth profile requiring control. It is located near the major circle on the internal spline and near the minor circle on the external spline. Form Clearance (cF) is the radial depth of involute profile beyond the depth of engagement with the mating part. It allows for looseness between mating splines and for eccentricities between the minor circle (internal), the major circle (external), and their respective pitch circles. Form Diameter (DFe, DFi) the diameter of the form circle. Internal Spline is a spline formed on the inner surface of a cylinder. Involute Spline is one having teeth with involute profiles. Lead Variation is the variation of the direction of the spline tooth from its intended direction parallel to the reference axis, also including parallelism and alignment variations (see Fig. 1a). Note: Straight (nonhelical) splines have an infinite lead. Length of Engagement (Lq) is the axial length of contact between mating splines. Machining Tolerance (m) is the permissible variation in actual space width or actual tooth thickness. Major Circle is the circle formed by the outermost surface of the spline. It is the outside circle (tooth tip circle) of the external spline or the root circle of the internal spline. Major Diameter (Do, Dri) is the diameter of the major circle. Minor Circle is the circle formed by the innermost surface of the spline. It is the root circle of the external spline or the inside circle (tooth tip circle) of the internal spline. Minor Diameter (Dre, Di) is the diameter of the minor circle. Nominal Clearance is the actual space width of an internal spline minus the actual tooth thickness of the mating external spline. It does not define the fit between mating members, because of the effect of variations. Out of Roundness is the variation of the spline from a true circular configuration. Parallelism Variation is the variation of parallelism of a single spline tooth with respect to any other single spline tooth (see Fig. 1b). Pitch (P/Ps) is a combination number of a one-to-two ratio indicating the spline proportions; the upper or first number is the diametral pitch, the lower or second number is the stub pitch and denotes, as that fractional part of an inch, the basic radial length of engagement, both above and below the pitch circle. Pitch Circle is the reference circle from which all transverse spline tooth dimensions are constructed. Pitch Diameter (D) is the diameter of the pitch circle. Pitch Point is the intersection of the spline tooth profile with the pitch circle. Pressure Angle (φ) is the angle between a line tangent to an involute and a radial line through the point of tangency. Unless otherwise specified, it is the standard pressure angle. Profile Variation is any variation from the specified tooth profile normal to the flank. Spline is a machine element consisting of integral keys (spline teeth) or keyways (spaces) equally spaced around a circle or portion thereof. Standard (Main) Pressure Angle (φD) is the pressure angle at the specified pitch diameter. Stub Pitch (Ps) is a number used to denote the radial distance from the pitch circle to the major circle of the external spline and from the pitch circle to the minor circleof the internal spline. The stub pitch for splines in this standard is twice the diametral pitch. Total Index Variation is the greatest difference in any two teeth (adjacent or otherwise) between the actual and the perfect spacing of the tooth profiles. Total Tolerance (m + λ) is the machining tolerance plus the variation allowance. Variation Allowance (λ) is the permissible effective variation

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值