#include#include <>#include <>#include <>#include <iostream> using namespace std;#include <ctime>int mai() // 倒计时{for (int i=3; i>=0; i--){ long t = time(NULL);for(;;){long n = time(NULL);if(n != t) break; } system("cls"); cout<<""<<endl;cout<<""<<endl;cout<<" 离史上最卡哇依的游戏开始还有** " << i 哦!!!"<<e ndl;}return 0;}void init1();void print1();int exit1();void init2();void print2();int exit2();void init3();void print3();int exit3();void near1(int a,int b,int a1,int b1);char chessman[10][10];void main() //主函数{ time_t start,end,time; start=clock();mai(); int d;cout<<""<<endl;cout<<"<><< " ** 秒"<<endl;cout<<""<<endl;cout<<"**************************************************************** "<<endl;cout<<"**************************************************************** "<<endl;cout<<" ** 亲,请选择适合您智商的级别:[1] 低级[2] 中级[3] 登峰造极**"<<endl;cout<<"**************************************************************** "<<endl;cout<<"**************************************************************** "<<endl;cout<<""<<endl;cout<<""<<endl;cout<<" 研发小组:Q Y Q"<<endl;cout<<" 请选择:***- "cin>>d;*** cout<<""<<endl;system("pause");switch(d){case 1:init1();break;case 2:init2();break;case 3:init3();break;default :cout<<" 你个逗比"}int op;int row,line;int row2,line2;do{ if(d==1)print1();else if(d==2)print2();else if(d==3) print3();printf("options:\n");printf("\\n");printf("\\n");printf("\\n");scanf("%d",&op);if(op==1){printf(" 不造亲第一个相中了谁呢:");scanf("%d %d",&line,&row);printf(" 再给他找个伴儿吧,亲:");scanf("%d %d",&line2,&row2);if(chessman[line][row]!=chessman[line2][row2]) {printf(" 有缘无分呐!\n");system("pause");}else if(line==line2&&row==row2){printf(" 有搞错哦,亲!!!\n"); system("pause");}else if(line<=line2){near1(line,row,line2,row2);}else{near1(line2,row2,line,row);}}if(op==2){}if(op==3){ main();}}while(exit1(),exit2(),exit3());system("pause");printf("\n\n\n\t\t 哇呀!你好厉害!\n");end=clock();time=end-start; // 这里的时间是计算机内部时间cout << endl << "time:" << time << endl;system("pause");cout<<" 本次得分:98 分! 继续保持哦!"<<endl;system("pause");}void init1() //4 乘4 矩阵{int i,j;int a[4]={0};srand(time(NULL)); for(i=1;i<4;i++) for(j=1;j<5;j++) {chessman[i][j]=rand()%4+65;if(chessman[i][j]==65) a[0]++;if(chessman[i][j]==66) a[1]++;if(chessman[i][j]==67) a[2]++;if(chessman[i][j]==68) a[3]++;} for(i=0;i<4;i++) {if(a[i]%2!=0)chessman[4][i+1]=i+65;elsechessman[4][i+1]=69;}}void print1(){int i,j;system("cls");printf("\t 1 2 3 4\n"); for(i=0;i<5;i++){printf("\t\n\t"); for(j=0;j<5;j++) { printf("%4c",chessman[i][j]);if(j==4&&i!=0&&i!=5) printf("\t%d",i);}} printf("\n\n\n\n");}int exit1(){int i,j;for(i=0;i<6;i++){for(j=0;j<6;j++)if(chessman[i][j]!=0)return 1;} return 0;}void init2() //6 乘6 矩阵{int i,j;int a[6]={0};srand(time(NULL)); for(i=1;i<6;i++) for(j=1;j<7;j++) {chessman[i][j]=rand()%6+65;if(chessman[i][j]==65) a[0]++;if(chessman[i][j]==66) a[1]++;if(chessman[i][j]==67) a[2]++;if(chessman[i][j]==68) a[3]++;if(chessman[i][j]==69) a[4]++;if(chessman[i][j]==70) a[5]++;} for(i=0;i<6;i++) {if(a[i]%2!=0) chessman[6][i+1]=i+65;elsechessman[6][i+1]=71;}}void print2(){int i,j;system("cls");printf("\t 1 2 3 4 5 6\n"); for(i=0;i<8;i++){printf("\t\n\t"); for(j=0;j<8;j++) {printf("%4c",chessman[i][j]); if(j==6&&i!=0&&i!=7) printf("\t%d",i);}}printf("\n\n\n\n");}int exit2(){int i,j;for(i=0;i<8;i++){for(j=0;j<8;j++)if(chessman[i][j]!=0)return 1;}return 0;}void init3() //8 乘8 矩阵{int i,j;int a[8]={0};srand(time(NULL)); for(i=1;i<8;i++) for(j=1;j<9;j++) {chessman[i][j]=rand()%8+65;if(chessman[i][j]==65) a[0]++;if(chessman[i][j]==66) a[1]++;if(chessman[i][j]==67) a[2]++;if(chessman[i][j]==68) a[3]++;if(chessman[i][j]==69) a[4]++;if(chessman[i][j]==70) a[5]++;if(chessman[i][j]==71) a[6]++;if(chessman[i][j]==72) a[7]++;}for(i=0;i<8;i++){if(a[i]%2!=0)chessman[8][i+1]=i+65;elsechessman[8][i+1]=73;}}void print3()int i,j;system("cls");printf("\t 1 2 3 4 5 6 7 8 \n"); for(i=0;i<10;i++)// 棋盘内容为A 到H // 记录A 的个数{{{printf("\t\n\t"); for(j=0;j<10;j++) {printf("%4c",chessman[i][j]); if(j==9&&i!=0&&i!=9)printf("\t%d",i);}}printf("\n\n\n\n");}int exit3(){int i,j;for(i=0;i<10;i++){for(j=0;j<10;j++) if(chessman[i][j]!=0) return 1;}return 0;}void near1(int a,int b,int a1,int b1) // 三种路径{int arow[2];int aline[2];int brow[2];int bline[2]; intstart=0,end=0; //临时两个点int i,j,n; //用于循环for(i=0;i<2;i++){arow[i]=a;brow[i]=a1;aline[i]=b;bline[i]=b1;//初始化数组}/////////////////////////////////////////(a, b)a 列中有哪些列for(i=a+1;i<10;i++)if(chessman[i][b]==0)arow[1]=i; // arow【1】 A 点a 行向下向量elsebreak;} for(i=a-1;i>=0;i--){ if(chessman[i][b]==0) // arow【0】 A 点a 行向上向量arow[0]=i; elsebreak;} ////////////////////////////////////////////(a1,b1)a 行中有哪些列for(i=a1+1;i<10;i++){ if(chessman[i][b1]==0) // brow[1]B 点a1 行向下向量brow[1]=i; elsebreak;} for(i=a1-1;i>=0;i--){ if(chessman[i][b1]==0) // brow[1]B 点a1 行向上向量brow[0]=i; else break;} //////////////////////////////////////(a,b)b 行有哪些列for(i=b+1;i<10;i++){if(chessman[a][i]==0) //aline[1]A 点b 列向右向量aline[1]=i;elsebreak;} for(i=b-1;i>=0;i--){if(chessman[a][i]==0) //aline[0]A 点b 列向左向量aline[0]=i;elsebreak;}/////////////////////////////(a1,b1) 中b1 列中有哪些行for(i=b1+1;i<10;i++) {if(chessman[a1][i]==0)bline[1]=i;else//bline[1]B 点b1 列向左向量break;} for(i=b1-1;i>=0;i--){ if(chessman[a1][i]==0) //bline[1]B 点b1 列向右向量bline[0]=i;elsebreak;}/////////////////////////////////////// 关键算法/////////////////////////////////// /**********************情况一(a,b) (a1,b1)*********************************情况二()(a1,b1)***********************************/考虑上下向量if(brow[0]>=arow[0]) 量start=brow[0];elsestart=arow[0];if(brow[1]<=arow[1])end=brow[1];elseend=arow[1];for(;start<=end;start++) {// bl要大于b,否则就交换如果不交换将使下面的循环出错、//if(b<b1){j=b; //小的赋值到i=b1; //大的赋值到} else {j=b1;i=b;}///这里节约一个变量//向上方向向量有共同的列向//取大的//向下的方向向量有共同的列向量取小的//列向量上共同sart 到endifor(n=0;j<i;j++) // 同一行上,从列j 到i{ if(chessman[start][j]==0) // 同一行上,所有列都是0n++;elsebreak;}if((n==b-b1)&&(n>0)) //因为b 和b1 大小不能确定,所以有两个ifchessman[a][b]=chessman[a1][b1]=0;if((n==b1-b)&&(n>0)) chessman[a][b]=chessman[a1][b1]=0;} //考虑左右向量//if(aline[0]>=bline[0]) //向左的向量有共同的列向量start=aline[0]; //取大的elsestart=bline[0];if(aline[1]<bline[1])end=aline[1];elseend=bline[1];for(i=start;i<=end;i++){for(j=a,n=0;j<a1;j++){if(chessman[j][i]==0) //同一列上所有行都是0n++;else break;}if(n==a1-a&&n>0){ chessman[a][b]=chessman[a1][b1]=0; break;}}//************************************************************************** 同行或者同列( a,b)或者( a,b) (a1,b1) (a1,b1)***************************************************************************}//同行if((aline[1]>=b1)||(aline[0]<=b1)) chessman[a][b]=chessman[a1][b1]=0;//同列if(arow[1]>=a1)chessman[a][b]=chessman[a1][b1]=0; if(a==a1){ } if(b==b1) {。