当前位置: 代码迷 >> 综合 >> Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined) B. Batch Sort
  详细解决方案

Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined) B. Batch Sort

热度:123   发布时间:2023-09-23 06:01:39.0

题目地址:http://codeforces.com/contest/724/problem/B

暴力

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
#define swap(x,y) (x^=y,y^=x,x^=y)
int G[23][23],n,m;
bool check(){for(int i=1;i<=n;++i){int cnt=0;for(int j=1;j<=m;++j)cnt+=G[i][j]!=j;if(cnt>2) return false;}return true;
}
int main(int argc, char const *argv[])
{cin>>n>>m;for(int i=1;i<=n;++i)for(int j=1;j<=m;++j)scanf("%d",&G[i][j]);if(check()) {cout<<"YES"<<endl;return 0;}for(int i=1;i<=m;++i)for(int j=i+1;j<=m;++j){for(int k=1;k<=n;++k) swap(G[k][i],G[k][j]);if(check()) {cout<<"YES"<<endl;return 0;}for(int k=1;k<=n;++k) swap(G[k][i],G[k][j]);}cout<<"NO"<<endl;return 0;
}


  相关解决方案