Cow Tipping

原题目梗概:
n*n的01网格;
操作改变x,y;
矩形{(0,0),(x,y)}内数字会被全部反转;
经过至少ans次操作使网格全变成0;
求ans;

输入: 
n
网格

输出:
ans;


游戏过程:
输入x,y使网格全变成0;
根据操作次数与ans的差值计算得分
  • CT_beta:
#include<bits/stdc++.h>
#include<windows.h>
using namespace std;
string name,amt="";
bool f[10],___=false;
bool cm[15][15]{
	{0,0,0,0,0,0,1,0,0},
	{0,1,1,0,0,0,1,1,0},
	{0,0,1,1,0,1,1,0,0},
	{0,0,0,0,0,0,0,0,0},
	{0,0,1,1,0,0,1,1,0},
	{0,0,1,1,0,1,0,0,1},
	{0,0,1,1,0,1,0,0,1},
	{0,0,1,1,0,0,1,1,0},
	{0,0,0,0,0,0,0,0,0},
	{0,0,0,0,0,0,0,0,0}
};
int CT_Formans;
void print(string s,int spd){
	for(int i=0;i<s.size();++i){
		cout<<s[i];
		Sleep(spd);
	}return;
}
//3-CT(3,4)--------------------------------------------- 
void CT_brt(){
	for(int i=0;i<10;++i)
		for(int j=0;j<10;++j)
			cm[i][j]=(rand()&1);
}
void CT_printForm(){
	cout<<"  Y";
	for(int j=0;j<10;++j)cout<<j;
	cout<<"\nX\n";
	for(int i=0;i<10;++i){
		cout<<i<<"  ";
		for(int j=0;j<10;++j)
			cout<<cm[i][j];	
		cout<<'\n';
	}cout<<'\n';
	
}
void CT_changeForm(int x,int y){
	for(int i=0;i<=x;++i)
		for(int j=0;j<=y;++j)
			cm[i][j]=!cm[i][j];
}
bool CT_checkForm(){
	for(int i=0;i<10;++i)
		for(int j=0;j<10;++j)
			if(cm[i][j])return false;
	return true;
}
void CT_dscrp(){
	system("cls");
//	print("敬请期待...\n",20);
	print("这是一个10*10的表格\n",100);
	CT_printForm();
	system("pause");
	print("你需要输入一个坐标(X,Y)\n",100);
	Sleep(1000);
	print("例如,输入 2 5\n",100);
	Sleep(1000);
	print("矩形{(0,0) (2,5)}中的所有数字都会反转\n",100);
	Sleep(1000);
	CT_changeForm(2,5);
	CT_printForm();
	Sleep(1000);
	print("就像这样\n",100);
	Sleep(1000);
	print("最后,你需要把表格恢复成全是0的样子\n",100);
	Sleep(1000);
	print("这就是全部了\n",100);
	system("pause");
}

void CT_ansn(){
	bool t[15][15];
	for(int i=9;i>=0;--i)
		for(int j=9;j>=0;--j)
			t[i][j]=cm[i][j];
	CT_Formans=0;
	for(int i=9;i>=0;--i)
		for(int j=9;j>=0;--j)
			if(cm[i][j]){
				CT_changeForm(i,j);
				++CT_Formans;
				if(___){
					cout<<CT_Formans<<'\n'<<i<<' '<<j<<'\n';
					CT_printForm();
					system("pause");
				}
			}
	for(int i=9;i>=0;--i)
		for(int j=9;j>=0;--j)
			cm[i][j]=t[i][j];
}
void CT_start(){
	system("cls");
	CT_brt();
	CT_printForm();
	CT_ansn();
	int x,y,cnt=CT_Formans;
	while(!CT_checkForm()){
		printf("剩余%d步\n",cnt);
		printf("请输入(X,Y):");
		cin>>x>>y;
		CT_changeForm(x,y);
		--cnt;
		system("cls");
	CT_printForm();
	}
	
	int sor=10;
	sor+=cnt/ceil(CT_Formans/5);
	printf("得分:%d/10\n",sor);
	system("pause");
	if(!f[3]&&sor==10){
		f[3]==true;
		system("cls");
		print("You got a perfect score!\n",50);
		print("You got:",50);
		Sleep(1000);
		print("牧牛犬\n",500);
		amt+="_牧牛犬";
		print("Hellow "+name+amt+'\n',50);
		system("pause");
	}
	else if(!f[4]&&sor<0){
		f[4]==true;
		system("cls");
		print("You got a ugly score!\n",300);
		print("You got:",50);
		Sleep(1000);
		print("恐牛症\n",500);
		amt+="_恐牛症";
		print("Hellow "+name+amt+'\n',50);
		system("pause");
	} 
	
}
void CT(){//Cow Tipping
	system("cls");
	print("Cow Tipping!\n",20);
	print("0.EXIT\n",20);
	print("1.Direction\n",20);
	print("2.Start game\n",20);
	int answer;
	cin>>answer;
	if(answer==0)return; 
	else if(answer==1)CT_dscrp();
	else if(answer==2)CT_start();
	else if(answer==20260725)___=true;
	CT();
}

int main(){	

	srand((unsigned)time(NULL));

	system("pause");
	CT();
	system("pause");

 return 0;
}