关于拼图和逆序数的关系可以看看这个

http://www.guokr.com/question/579400/

然后求逆序数在判断就行了

 按题意生成原始排列,观察发现,每一轮数后方比该数小的数的数量(即对逆序对数的贡献)呈等差数列形式,公差p-1,项数为(num-1)/p+1,(首项为0)照此简化计算,不需要正真求出排列。

#include <bits/stdc++.h>
using namespace std;

int main()
{
    int t,n,m,p;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d%d%d",&n,&m,&p);
        int num=n*m-1;
        int res=0;
        while(num-1>=p)
        {
            int s=(num-1)/p;
            res+=s*(s+1)*(p-1)/2;
            num-=s+1;
        }
        puts(res%2? "NO":"YES");
    }
    return 0;
}

 

相关文章:

  • 2021-06-22
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-09
  • 2022-12-23
  • 2021-06-22
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-08-14
  • 2021-12-20
  • 2021-05-16
  • 2021-12-25
  • 2021-08-21
相关资源
相似解决方案