跳到正文

剪贴板

剪贴板 in27lut2

原文
剪贴板信息

剪贴板信息

收录
更新
C++
#include<bits/stdc++.h>
using namespace std;
const int LIMIT_SIZE=24;
struct State
{
	char map[LIMIT_SIZE][LIMIT_SIZE];
};
#define ACTION_PUT  0
#define ACTION_STAR  1
#define ACTION_BOMBER 2
#define ACTION_REJECT 3
struct PlayAction
{
	int action;
	int x, y;
};
class Replay
{
	public:
		int len;
		vector<PlayAction> list;
		void LoadReplay();
};
int n,m,star,bomber,nop;
vector<int> oplist;
vector<State> his;
State  init_map;
Replay  gameplay;
long long spj_a[12];
void ReportScore(long long score)
{
	long long ans=0;
	for(int i=1; i<=10; i++)
		if(score>=spj_a[i])ans=i;
	printf("Correct! Your score is %lld and get %lld points",score,ans);
}
void LoadGame()
{
	scanf("%d%d%d%d",&n,&m,&star,&bomber);
	for(int i=1; i<=n; i++)
	{
		string tmp;
		cin>>tmp;
		for(int j=0; j<m; j++)
			init_map.map[i][j+1]=tmp[j];
	}
	scanf("%d",&nop);
	for (int i=0; i<nop; i++)
	{
		int x;
		scanf("%d",&x);
		oplist.push_back(x);
	}
}
const int SCORE[]= {0,4,20,100,500,1500,5000,20000,100000,500000};
long long total_score=0;
State curt;
int qx[LIMIT_SIZE*LIMIT_SIZE];
int qy[LIMIT_SIZE*LIMIT_SIZE];
int head,tail;
bool mark[LIMIT_SIZE][LIMIT_SIZE];
int dx[]= {0, 0, 1, -1};
int dy[]= {1, -1, 0, 0};
bool valid(int x, int y)
{
	return 1<=x&&x<=n&&1<=y&&y<=m;
}
bool CheckUpgrade(int x,int y)
{
	int L=curt.map[x][y];
	if(L=='9')return 0;
	memset(mark,0,sizeof(mark));
	mark[x][y]=1;
	qx[0]=x;
	qy[0]=y;
	head=0;
	tail=1;
	while(head<tail)
	{
		x=qx[head];
		y=qy[head];
		head++;
		for(int d=0; d<4; d++)
			if(valid(x+dx[d],y+dy[d])&&curt.map[x+dx[d]][y+dy[d]]==L&&!mark[x+dx[d]][y+dy[d]])
			{
				mark[x+dx[d]][y+dy[d]]=1;
				qx[tail]=x+dx[d];
				qy[tail]=y+dy[d];
				tail++;
			}
	}
	return tail>=3;
}
void DoUpgrade()
{
	for(int i=1; i<tail; i++)
		curt.map[qx[i]][qy[i]]='.';
	curt.map[qx[0]][qy[0]]++;
	total_score+=SCORE[curt.map[qx[0]][qy[0]]-'0'];
}
void BuildOnPos(int x, int y)
{
	total_score+=SCORE[curt.map[x][y]-'0'];
	while(CheckUpgrade(x,y))
		DoUpgrade();
}
void print()
{
	for(int i=1;i<=50;++i)
		cout<<endl;
}
void Replay::LoadReplay()
{
	len=0;
	list.clear();
	char buf[256];
	char cmd[256];
	int x,y;
	PlayAction act;
	int line=0;
	int opnow=0;
	total_score=0;
	curt=init_map;
	for (int i = 0; i < 114514; ++i)
		his.push_back(init_map);
	int cccnt = 0;
	while(1)
	{
		cout << cccnt++ << '\n';
		cout<<"Bomber:"<<bomber<<endl;
		cout<<"Star:"<<star<<endl;
		cout<<"Total_score:"<<total_score<<endl;
		cout<<"Queue:"<<endl;
		for(int i=opnow;i<min(opnow+20,(int)oplist.size());++i)
		 	cout<<oplist[i]<<" ";
		cout<<endl;
		cout<<"Map:"<<endl;
		for(int i=1;i<=n;++i)
		{
			for(int j=1;j<=m;++j)
				cout<<char(curt.map[i][j]);
			printf("\n");
		}
		scanf("%s",cmd);
		if(!strcmp(cmd,"END"))
			break;
		if(!strcmp(cmd,"PUT"))
			act.action = ACTION_PUT;
		else if(!strcmp(cmd,"STAR"))
			act.action = ACTION_STAR;
		else if(!strcmp(cmd,"BOMBER"))
			act.action = ACTION_BOMBER;
		else if(!strcmp(cmd,"REJECT"))
			act.action = ACTION_REJECT;
		else
		{
			printf("Output Invalid!");
			continue;
		}
		if (act.action!=ACTION_REJECT)
			scanf("%d%d",&x,&y);
		if(x<=0||x>n||y<=0||y>m)
		{
			printf("Output Invalid!");
			continue;
		}
		act.x=x;
		act.y=y;
		list.push_back(act);
		len++;
		int x=act.x;
		int y=act.y;
		if(act.action==ACTION_BOMBER)
		{
			his.push_back(curt);
			if(bomber<=0)
				printf("Output Invalid! [Line %d] No bombers left.",len+1);
			if (curt.map[x][y]=='.')
				printf("Output Invalid! [Line %d] Can't place bomber on (%d, %d). It's empty.",len+1,x,y);
			total_score-=SCORE[curt.map[x][y]-'0']/2;
			curt.map[x][y]='.';
			bomber--;
		}
		else if(act.action==ACTION_PUT)
		{
			if(opnow>=nop)
			{
				printf("Output Invalid! [Line %d] Too many PUT operations.",len+1);
				continue;
			}
			if(curt.map[x][y]!='.')
			{
				printf("Output Invalid! [Line %d] Can't place L on (%d, %d). It's not empty.",len+1,x,y);
				continue;
			}
			his.push_back(curt);
			curt.map[x][y]=oplist[opnow++]+'0';
			BuildOnPos(x, y);
		}
		else if(act.action==ACTION_STAR)
		{
			his.push_back(curt);
			if(star<=0)
				printf("Output Invalid! [Line %d] No stars left",len+1);
			if (curt.map[x][y]!='.')
				printf("Output Invalid! [Line %d] Can't place STAR on (%d, %d). It's not empty.",len+1,x,y);
			for(char c='9'; c>='1'; c--)
			{
				curt.map[x][y] = c;
				if(CheckUpgrade(x, y))
					break;
			}
			BuildOnPos(x, y);
			star--;
		}
		else if(act.action==ACTION_REJECT) {
			// assert(0);
			curt = his[his.size()-1];
			--opnow;
			his.pop_back();
		}
	}
}
int main()
{
	//freopen("a2.out","w",stdout);
	// for(int i=10; i>=2; i--)
	// 	cin>>spj_a[i];
	// spj_a[1]=1;
	LoadGame();
	print();
	gameplay.LoadReplay();
	return 0;
}
/*
4352
3572
2932
2407
1976
1622
1332
1000
500
3 3
0 0
.1.
.11
...
30
2 4 1 4 2 1 3 1 1 1 1 2 1 1 2 1 1 2 2 1 1 1 2 1 1 1 2 1 1 4
PUT 1 1
PUT 3 3
PUT 1 3
PUT 2 3
PUT 1 2
PUT 1 1
PUT 1 3
PUT 2 1
*/