首页 > 其他分享 >Test

Test

时间:2023-06-15 15:07:55浏览次数:19  
标签:return SampleSolve Test lastcol lastrow col row


/ / 
//  Construction/Destruction 
/ / 

/*  功能描述:
 * Queen有3中动作模式:
 * (1) 单步模式
 * (2) 自动演示模式
 * (3) 自动求解最终答案模式
 * 接口:
 * MoveNext()    尝试往下移动,更新StepSaver内容,同时更新lastrow、lastcol,为下一步作准备
 * Solve()        求解主函数
 * MoreSolve()    更多解的求解调用入口
  */ 


Queen::Queen( int  n, int  delay)
{
     if (n < 1   ||  n  > 32 )
    {
        AfxMessageBox(_T( " 请选择2~32之间的数,当前n被强制设为32 " ));
        n  =   32 ;
    }
    N  =  n;
    lastcol = ( 0 ),lastrow = ( 0 ),PlayDelay = (delay);
    SampleSolve  =   new  StepSaver(N);    
}

Queen:: ~ Queen()
{
    delete SampleSolve;
    
     // necessary? 
    SampleSolve  =   0 ;
    lastrow  =  lastcol  =   0 ;
}

int  Queen::Solve()
{
     int  ret;
     int  count = 0 ;

     do {
        ret = NextStep();
         if (ret  ==  FIND_ONE_SOLUTION)
            count ++ ;
    } while (ret != END_OF_SEARCH);

     return  count;
}

int  Queen::MoreSolve()
{
    
     if ( ! SampleSolve)  return   false ;

    SampleSolve -> UnSet(lastrow,lastcol);


     if (lastcol  >=  N - 1   &&  lastrow  >=  N - 1  )
         return   false ;
    lastcol  =  lastcol  + 1 ;
     if (lastcol  >=  N)
        lastrow  +=   1 ;

     return  Solve();
}



//  单步演示,如论成功与否,每一步都要走 
int  Queen::NextStep()
{

     int  row  =  lastrow;      //  行 
     int  col  =  lastcol;    //  列
    
     //  先做出失败的假设,在return false之前置好初值 
    lastrow  =  lastcol  =  N;

     if (row  >=  N  ||  col  >=  N)
         return  END_OF_SEARCH;     //  没有更多解了

     //  演示 
    Place(row,col);


     //  计算下一个待演示的位置
     //  当前是一个局部可用解,需要跳到下一行安排新的皇后,形成大一些的局部解
     //  若不是可用解,继续尝试在当前行安排当前皇后,或者退回到上一行接着上次的地方尝试。
     //                                                  如果发现没有退路了,返回false 
     if (SampleSolve -> IsCompatiable(row,col))    
    {
         // 标记当前可放位置 
        SampleSolve -> Set(row,col);    

         // 寻找下一个位置 
        row ++ ;     //  next line 

         / //
         ///  BUG ! Fix me!
         / /
         /// if(row >= N)
         ///         return false;
         /// col=0
         // //
         ///  Fixed: 
         if (row >= N)     //  已经找到一个解。并且,需要寻找下一个解的初始出发点。 
        {
//             row--; 
            col ++ ;
             while ( row >= N  ||  (row  >=   1    &&   col >= N ) ){     // 需要退格 
                    row -- ;
                    col  =  SampleSolve -> GetCol(row);
                    SampleSolve -> UnSet(row,col);     //  先取消此行的摆放标记 
                    col ++ ;     //  得到待尝试格的col 
            }
            
             //  更新lastrow, lastcol 
            lastrow  =  row;
            lastcol  =  col;

             if ( row  <=   0   &&  col  >= N )      //  已经退到了顶部之外,失败 
                 return  END_OF_SEARCH | FIND_ONE_SOLUTION;

             return  FIND_ONE_SOLUTION;     //

        } else {
            col  =   0 ;
        }
    } else {
        ASSERT(row >= 0 );
        
        col ++ ;     //  “一般情况”下的下一个位置 

         while ( row  >=   1    &&   col >= N ){     // 需要退格 
                row -- ;
                col  =  SampleSolve -> GetCol(row);
                SampleSolve -> UnSet(row,col);     //  先取消此行的摆放标记 
                col ++ ;     //  得到待尝试格的col 
        }
        
         if ( row  <=   0   &&  col  >= N )      //  已经退到了顶部之外,失败 
             return  END_OF_SEARCH;
    }

     //  更新lastrow, lastcol 
    lastrow  =  row;
    lastcol  =  col;

     return  HAVE_NEXT_STEP;
}






BOOL Queen::Place( int  x,  int  y)
{
     if (PlayDelay != 0 ){
        SampleSolve -> TempSet(x,y);
        ((CQueenDlg * )((CQueenDlg * )AfxGetApp() -> m_pMainWnd)) -> UpdateCanvas();
         // Sleep(PlayDelay); 
        SampleSolve -> TempUnSet(x,y);
    }
     if ( ! SampleSolve -> IsCompatiable(x,y))
         return   false ;
     return   true ;    
}

标签:return,SampleSolve,Test,lastcol,lastrow,col,row
From: https://blog.51cto.com/u_16162111/6492450

相关文章

  • Google Test(GTest)和Google Mock(GMock)入门简介
    GoogleTest1.自定义错误输出:ASSERT_EQ(x.size(),y.size())<<"Vectorsxandyareofunequallength";for(inti=0;i<x.size();++i){EXPECT_EQ(x[i],y[i])<<"Vectorsxandydifferatindex"<<i;}2.ASSERT_......
  • GTest测试框架中的friend(友元)使用注意点
    为了测试MyClass,写了一个测试caseTEST_F(MyClassTest,method){}GoogleTest框架中使用这样的测试单元时,会自动生成一个叫做MyClass_method_Test的类,在MyClass中声明友元的正确方法是:private:friendclassMyClass_method_Test;othervar...goeshere而不是:private:......
  • pyautogui.screenshot('test.png') 报错:PyAutoGUI was unable to import pyscreeze (T
    根据提示需要importpyscreeze还需要Pillow.通过pip3list可以查看到已经安装PyScreeze==0.1.29但是不是我手动安装的,应该是Pillow或者pyautogui下载的时候依赖了pyscreeze并且安装了最新版本0.1.29。通过依赖树可以看到是pyautogui依赖了sudopip3installpipdeptree安装查......
  • AtCoder Beginner Contest 249 G Xor Cards
    洛谷传送门AtCoder传送门好题。套路地,考虑枚举最优解的\(a\)异或和二进制下与\(k\)的\(\text{LCP}\),设在第\(i\)位不同。这样的好处是\(i\)之后的位可以随便选。之后按位贪心确定最优解\(b\)的异或和。考虑之前的答案是\(res\),当前在确定第\(j\)位,如何判断\(r......
  • 为什么AirtestIDE的selenium Window突然无法检索控件了?
    1.前言最近有很多朋友跟我们反馈,为什么1.2.15版本的IDE没办法做网页元素检索了,是不是我们不支持selenium了之类的。测试后发现,目前版本确实存在这个问题,原因是Chrome113.0.5672.127(最新)版本过高,AirtestIDE1.2.15暂未兼容。2.问题表现1)无法检索控件我们尝试使用Airtest1.2......
  • [-002-]-Python3+Unittest+Uiautomation Windows桌面App UI自动化之鼠标操作
    1、单击鼠标左键Click(x:int,y:int,waitTime:float=OPERATION_WAIT_TIME)模拟鼠标在点x,y的点击。OPERATION_WAIT_TIME默认为0.5即等待时间默认为0.5秒2、单击鼠标中键MiddleClick(x:int,y:int,waitTime:float=OPERATION_WAIT_TIME)模拟鼠标在点x,y......
  • AtCoder Beginner Contest 305 题解 A - F
    A-WaterStation题目大意找到离给定的数最近的一个\(5\)的倍数输出即可。解题思路我们取这个数对\(5\)的上下界,也就是整数除以\(5\)再乘以\(5\),以及这个数再加上一个\(5\),比较这两数和给定数的距离即可。ACCode#include<iostream>#include<algorithm>#includ......
  • pytest接口自动化(一)
    这里说下pytest接口自动化的工程项目的基本结构(个人的工程结构),项目工程主要使用pytest、pymysql、requests、pyyaml、allure-pytest、pytest-rerunfailures、pytest-xdist、filelock等插件。首先工程结构api_test[工程名称]api 存放接口的封装方法,方法中一般存着......
  • AtCoder Beginner Contest 219 H Candles
    洛谷传送门AtCoder传送门套路化了。比较显然的关路灯型区间dp。考虑你\(t\)时刻熄灭一个初始长度为\(a\)的蜡烛,得分是\(\max(a-t,0)\),所以尝试把时间塞进状态。设\(f_{i,j,k,0/1}\)表示,熄灭完区间\([i,j]\)的蜡烛,当前时间是\(t\),在左端点还是右端点的最大得......
  • pytest 执行脚本时,报(no name '/Users/**/PycharmProjects/interface_auto/test_case/
    触发场景:pytest执行脚本时,命名全部正确,但是直接报找不到执行函数解决方式:取掉init方法原因:测试框架在运行测试时会自动实例化测试类的对象,并且不会传递任何参数。如果您定义了__init__方法,测试框架将无法实例化您的测试类,从而导致测试无法运行。因此,为了确保测试类能够正......