⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 1034.cpp

📁 我的URAL的1000 ~ 1050 的全部代码 包含WA 最后AC的程序 有2~3个比较难的是MAIGO的程序
💻 CPP
字号:
//排列组合问题 
#include <iostream>
#include <math.h>
using namespace std;

const int maxN = 50;
bool  row[maxN + 1], col[maxN + 1], lDiag[ 2 * maxN + 3 ], rDiag[ 2 * maxN + 3 ];
struct Point{int x, y; };
Point p[maxN + 1];
int n, ans;
int c1, c2, c3;

void disSet(Point a)
{
     row[a.x] = false;
     col[a.y] = false;
     lDiag[ a.y - a.x + n ] = false ;
     rDiag[ a.y + a.x - 1 ] = false ;
}
void set(Point a)
{
     row[a.x] = true;
     col[a.y] = true;
     lDiag[ a.y - a.x + n ] = true ;
     rDiag[ a.y + a.x - 1 ] = true ;
}
void readIn()
{
     memset(col, false, sizeof(col));
     memset(row, false, sizeof(row));
     memset(lDiag,false,sizeof(lDiag));
     memset(rDiag,false,sizeof(rDiag));
     int i;
     cin >> n;
     for( i = 1; i <= n; i++ )
     {
          cin >>p[i].x >> p[i].y; 
          set(p[i]);
     }
}

bool  canplace( Point p )
{
      if( row[a.x] || col[a.y] || lDiag[ a.y - a.x + n ] || rDiag[ a.y + a.x - 1 ] )
          return false;
      return true;
}
void check()
{
     int i , j , k;
     Point t1, t2, t3;
     for( i = 1; i <= n; i++ )
     {
          t1.x = i;
          t1.y = c1.y;
          if( canplace(t1) && t1.x != c1.x )
          {
              set(t1);
              for( j = 1; j <= n; j++ )
              {
                   t2.x = j;
                   t2.y = c2.y;
                   if( canplace(t2) && t2.x != c2.x )
                   {
                       set(t2);
                       for( k = 1; k <= n; k )
                   }
              }
              
          }
     }     
}
void work()
{
     for( c1 = 1; c1 <= n - 2; c1++ )
          for( c2 = c1 + 1; c2 <= n - 1; c2++ )
               for( c3 = c2 + 1; c3 <= n; c3++ )
               {
                    disSet( p[c1] );
                    disSet( p[c2] );
                    disSet( p[c3] );
                    
                    check();
                    
                    set( p[c1] );
                    set( p[c2] );
                    set( p[c3] );
               }
}
int main()
{
    readIn();
    work();
    return 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -