萌新刚学OI1ms,A+B求助
  • 板块灌水区
  • 楼主封禁用户
  • 当前回复6
  • 已保存回复8
  • 发布时间2024/10/13 16:29
  • 上次更新2024/10/13 16:51:26
查看原帖
萌新刚学OI1ms,A+B求助
973480
封禁用户楼主2024/10/13 16:29

this

#include<bits/stdc++.h>
using namespace std;
int x[4]={0,0,1,1};
int y[4]={0,1,0,1};
int fx[4]={-1,0,1,0};
int fy[4]={0,1,0,-1};
int maxx=0,minx=2147483647,maxy=0,miny=2147483647,d=0;
bool check(){
	for(int i=0;i<3;i++){
		for(int j=i+1;j<4;j++){
			if(x[i]==x[j]&&y[i]==y[j]) return false;
		}
	}
	return true;
}
void ret(int f){
	maxx=max(maxx,x[f]);
	minx=min(minx,x[f]);
	maxy=max(maxy,x[f]);
	miny=min(miny,x[f]);
	return;
}
void move(int f,int u){
	x[f]+=fx[(d+u)%4];
	y[f]+=fy[(d+u)%4];
	ret(f);
	return;
}
void xz(int f){
	d=(d+1)%4;
	for(int i=0;i<4;i++){
		if(i==f) continue;
		int dx=x[f]-x[i],dy=x[i]-x[f];
		swap(dx,dy);
		x[i]=x[f]+dx,y[i]=y[f]+dy;
		ret(i);
	}
	return;
}
int main(){
	int q;
	cin >> q;
	while(q--){
		char s[4];
		cin >> s[1] >> s[2] >> s[3];
		int f;
		if(s[1]=='F'&&s[2]=='L') f=0; 
		if(s[1]=='F'&&s[2]=='R') f=1;
		if(s[1]=='R'&&s[2]=='L') f=2;
		if(s[1]=='R'&&s[2]=='R') f=3;
		switch(s[3]) { 
			case 'F': move(f, 0);break;
			case 'B': move(f, 2);break;
			case 'R': move(f, 1);break;
			case 'L': move(f, 3);break;
			default: xz(f);break;
		}
		if(check()==false){
			cout << -1;
			return 0;
		}
	}
	cout << (maxx-minx+1)*(maxy-miny+1);
	return 0;
}
2024/10/13 16:29
加载中...