#include<bits/stdc++.h>
#include<windows.h>
#include"highprecisionclock.h"
using namespace std;
#define random(a,b) (rand()%(b-a)+a)
void Load(int ***a){
//cout<<"initializing load sequence"<<endl;
for(int i=8;i<15;++i){
for(int j=1;j<21;++j){
char d[20];
sprintf(d,"%d%s%d%s",i,"-",j,"random.txt");
//cout<<"loading "<<d<<endl;
ifstream load(d);
//cout<<"loading number :"<<(i-8)*20+j-1<<endl;
for(int k=0;k<i;++k){
for(int l=0;l<4;++l){
load>>a[(i-8)*20+j-1][k][l];
}
}
load.close();
}
}
//cout<<"load sequence complete"<<endl;
}
bool Cut(double ave3,int step,int score){
if(step==2){
if(score<ave3)
return true;
else
return false;
}
else
return false;
}
void Display(int **a,int m,int n){
cout<<endl;
for(int i=m-1;i>-1;--i){
for(int j=0;j<n;++j){
cout<<a[i][j]<<" ";
}
cout<<endl;
}
cout<<endl;
}
void DisplayOps(int **ops,int *step){
for(int i=0;i<*step;++i){
cout<<ops[i][0]<<" "<<ops[i][1]<<" "<<ops[i][2]<<endl;
}
cout<<endl;
}
void Generate(int **a,int m,int n,int k){
srand((int)time(0));
for(int i=0;i<m;++i){
for(int j=0;j<n;++j){
a[i][j]=random(1,k);
}
}
}
void Check(int **a,int m,int n,int *flag){
int **tmp;
*flag=0;
tmp=new int *[m];
for(int i=0;i<m;++i){
tmp[i]=new int [n];
}
for(int i=0;i<m;i++){
for(int j=0;j<n;j++)
tmp[i][j]=0;
}
stack<int>te;
//cout<<"检查横向中"<<endl;
for(int i=0;i<m;++i){
int ct=0;
for(int j=0;j<n;++j){
if(a[i][j]!=0){
if(te.empty()||te.top()==a[i][j]){
++ct;
}
else if(te.top()!=a[i][j]){
if(ct<3){
while(!te.empty()){
te.pop();
}
}
else{
int tee=j;
while(!te.empty()){
tmp[i][--tee]=1;
te.pop();
}
}
ct=1;
}
te.push(a[i][j]);
}
else{
while(!te.empty()){
te.pop();
}
ct=0;
}
}
if(!te.empty()&&ct<3){
while(!te.empty()){
te.pop();
}
ct=0;
}
else if(!te.empty()){
int tee=n;
while(!te.empty()){
tmp[i][--tee]=1;
te.pop();
}
ct=0;
}
}
//cout<<"检查纵向中"<<endl;
for(int j=0;j<n;++j){
int ct=0;
for(int i=0;i<m;++i){
if(a[i][j]!=0){
if(te.empty()||te.top()==a[i][j]){
++ct;
}
else if(te.top()!=a[i][j]){
if(ct<3){
while(!te.empty()){
te.pop();
}
}
else{
int tee=i;
while(!te.empty()){
tmp[--tee][j]=1;
te.pop();
}
}
ct=1;
}
te.push(a[i][j]);
}
else{
while(!te.empty()){
te.pop();
}
ct=0;
}
}
if(!te.empty()&&ct<3){
while(!te.empty()){
te.pop();
}
ct=0;
}
else if(!te.empty()){
int tee=m;
while(!te.empty()){
tmp[--tee][j]=1;
te.pop();
}
ct=0;
}
}
//Display(tmp,m,n);
for(int i=0;i<m;++i){
for(int j=0;j<n;++j){
if(tmp[i][j]==1){
a[i][j]=0;
tmp[i][j]=0;
*flag=1;
}
}
}
//Display(a,m,n);
for(int i=0;i<m;++i)
delete []tmp[i];
delete[] tmp;
}
void Fall(int **a,int m,int n){
for(int i=0;i<m-1;++i){
for(int j=0;j<n;++j){
if(a[i][j]==0){
//cout<<"处理"<<i+1<<"行"<<j+1<<"列中..."<<a[i][j]<<endl;
int te=-1,temp;
for(int k=i;k<m;++k){
if(a[k][j]!=0){
te=k;
break;
}
}
//cout<<"正在交换a["<<te+1<<"]["<<j+1<<"]:"<<a[te][j]<<"和a["<<i+1<<"]["<<j+1<<"]:"<<a[i][j]<<endl;
if(te!=-1){
temp=a[i][j];
a[i][j]=a[te][j];
a[te][j]=temp;
}
//cout<<a[te][j]<<"和"<<a[i][j]<<"交换了!"<<endl<<endl;
//Display(a,m,n);
}
}
}
}
void AutoCheck(int **a,int m,int n){
int *flag;
flag=new int;
Check(a,m,n,flag);
Fall(a,m,n);
while(*flag==1){
Check(a,m,n,flag);
Fall(a,m,n);
}
}
void Fill(int **a,int m,int n,int k,int *flag){
srand((int)time(0));
*flag=0;
for(int i=0;i<m;++i){
for(int j=0;j<n;++j){
if(a[i][j]==0){
a[i][j]=random(1,k);
*flag=1;
}
}
}
AutoCheck(a,m,n);
}
void AutoFill(int **a,int m,int n,int k){
int *flag;
flag=new int;
*flag=0;
srand((int)time(0));
AutoCheck(a,m,n);
Fill(a,m,n,k,flag);
while(*flag==1)
Fill(a,m,n,k,flag);
}
int CheckScore(int **a,int m,int n){
int **tmp;
tmp=new int *[m];
for(int i=0;i<m;++i){
tmp[i]=new int [n];
}
for(int i=0;i<m;i++){
for(int j=0;j<n;j++)
tmp[i][j]=0;
}
stack<int>te;
//cout<<"检查横向中"<<endl;
for(int i=0;i<m;++i){
int ct=0;
for(int j=0;j<n;++j){
if(a[i][j]!=0){
if(te.empty()||te.top()==a[i][j]){
++ct;
}
else if(te.top()!=a[i][j]){
if(ct<3){
while(!te.empty()){
te.pop();
}
}
else{
int tee=j;
while(!te.empty()){
tmp[i][--tee]=1;
te.pop();
}
}
ct=1;
}
te.push(a[i][j]);
}
else{
while(!te.empty()){
te.pop();
}
ct=0;
}
}
if(!te.empty()&&ct<3){
while(!te.empty()){
te.pop();
}
ct=0;
}
else if(!te.empty()){
int tee=n;
while(!te.empty()){
tmp[i][--tee]=1;
te.pop();
}
ct=0;
}
}
//cout<<"检查纵向中"<<endl;
for(int j=0;j<n;++j){
int ct=0;
for(int i=0;i<m;++i){
if(a[i][j]!=0){
if(te.empty()||te.top()==a[i][j]){
++ct;
}
else if(te.top()!=a[i][j]){
if(ct<3){
while(!te.empty()){
te.pop();
}
}
else{
int tee=i;
while(!te.empty()){
tmp[--tee][j]=1;
te.pop();
}
}
ct=1;
}
te.push(a[i][j]);
}
else{
while(!te.empty()){
te.pop();
}
ct=0;
}
}
if(!te.empty()&&ct<3){
while(!te.empty()){
te.pop();
}
ct=0;
}
else if(!te.empty()){
int tee=m;
while(!te.empty()){
tmp[--tee][j]=1;
te.pop();
}
ct=0;
}
}
//Display(tmp,m,n);
int score=0;
for(int i=0;i<m;++i){
for(int j=0;j<n;++j){
if(tmp[i][j]==1){
a[i][j]=0;
score++;
tmp[i][j]=0;
}
}
}
//cout<<"After CheckScore"<<endl;
//Display(a,m,n);
for(int i=0;i<m;++i)
delete []tmp[i];
delete[] tmp;
return score;
}
int AutoCheckScore(int **a,int m,int n){
int scplus=0,*flag,k;
flag=new int;
k=CheckScore(a,m,n);
scplus+=k;
while(CheckScore(a,m,n)!=0){
Check(a,m,n,flag);
Fall(a,m,n);
scplus+=CheckScore(a,m,n);
}
delete flag;
return scplus;
}
int BestSingleSolve(int **a,int m,int n){
int **tmp;
tmp=new int *[m];
for(int i=0;i<m;++i){
tmp[i]=new int [n];
}
for(int i=0;i<m;++i){
for(int j=0;j<n;++j){
tmp[i][j]=a[i][j];
}
}
int max,eleh,elel,op=0;
max=0;
for(int i=0;i<m-1;++i){
for(int j=0;j<n-1;++j){
int temp,sc;
temp=tmp[i][j];
tmp[i][j]=tmp[i][j+1];
tmp[i][j+1]=temp;
sc=CheckScore(tmp,m,n);
if(sc>max){
max=sc;
eleh=i;
elel=j;
op=1;
}
temp=tmp[i][j];
tmp[i][j]=tmp[i][j+1];
tmp[i][j+1]=temp;
temp=tmp[i][j];
tmp[i][j]=tmp[i+1][j];
tmp[i+1][j]=temp;
sc=CheckScore(tmp,m,n);
if(sc>max){
max=sc;
eleh=i;
elel=j;
op=2;
}
temp=tmp[i][j];
tmp[i][j]=tmp[i+1][j];
tmp[i+1][j]=temp;
}
}
cout<<op<<" "<<max<<" "<<eleh<<" "<<elel<<endl;
int temp;
if(op==1){
int *flag;
flag=new int;
temp=a[eleh][elel];
a[eleh][elel]=a[eleh][elel+1];
a[eleh][elel+1]=temp;
Check(a,m,n,flag);
Fall(a,m,n);
delete flag;
}
else if(op==2){
int *flag;
flag=new int;
temp=a[eleh][elel];
a[eleh][elel]=a[eleh+1][elel];
a[eleh+1][elel]=temp;
Check(a,m,n,flag);
Fall(a,m,n);
delete flag;
}
for(int i=0;i<m;++i)
delete []tmp[i];
delete[] tmp;
return max+AutoCheckScore(a,m,n);
}
int SingleSolve(int **a,int m,int n,int **op,int *step,int sth,int stl,int *st
消消乐_消消乐_源码
版权申诉
127 浏览量
2021-10-02
02:15:42
上传
评论 1
收藏 4KB ZIP 举报
耿云鹏
- 粉丝: 61
- 资源: 4761
最新资源
- Image_1713714819368.png
- 数据可视化 matplotlib 实例.docx
- Python 使用 Matplotlib 绘制甘特图的实践.docx
- matplotlib 中的 cmap 参数介绍.docx
- 基于matlab的毕业设计基于Matlab使用LQR实现车辆轨迹跟踪源码.zip
- 基于Matplotlib 的高互动性可视化系统设计与实现
- matplotlib 数据可视化报告.docx
- 传统网页UI设计在移动应用开发中的应用研究.pdf
- 基于pytorch实现BERT+BiLSTM+CRF实现中文命名实体识别源码.zip
- 校园帮项目,毕业设计/课程设计/javaWeb/SSM
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
评论0