https://vjudge.net/contest/229603#problem/B

绿书题

大模拟,绿书上用了个比较麻烦的输入,其实只要getchar()!='0'就行

坑:

rep(i,0,s.length()-1)会wa

len=s.length()-1后不会。。。

#define _CRT_SECURE_NO_WARNINGS
#include<cstring>
#include<cctype>
#include<cstdlib>
#include<iomanip>
#include<cmath>
#include<cstdio>
#include<string>
#include<cassert>
#include<stack>
#include<ctime>
#include<list>
#include<set>
#include<map>
#include<queue>
#include<vector>
#include<sstream>
#include<fstream>
#include<iostream>
#include<functional>
#include<algorithm>
#include<memory.h>
//#define INF 0x3f3f3f3f
#define eps 1e-6
#define pi acos(-1.0)
#define e exp(1.0)
#define rep(i,t,n) for(int i =(t);i<=(n);++i)
#define per(i,n,t) for(int i =(n);i>=(t);--i)
#define mp make_pair
#define pb push_back
#define mmm(a,b) memset(a,b,sizeof(a))
//std::ios::sync_with_stdio(false);
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
void smain();
#define ONLINE_JUDGE
int main() {
//ios::sync_with_stdio(false);
#ifndef ONLINE_JUDGE
FILE *myfile;
myfile =freopen("C:\\Users\\SuuTT\\Desktop\\test\\in.txt", "r", stdin);
if (myfile == NULL)
fprintf(stdout, "error on input freopen\n");
/*FILE *outfile;
outfile= freopen("C:\\Users\\SuuTT\\Desktop\\test\\out.txt", "w", stdout);
if (outfile == NULL)
fprintf(stdout, "error on output freopen\n");*/
long _begin_time = clock();
#endif
smain();
#ifndef ONLINE_JUDGE
long _end_time = clock();
printf("time = %ld ms.", _end_time - _begin_time);
#endif
return ;
}
int dir[][] = { ,,,,-,,,- };
const int maxn = 3e3 + ;
struct point {
int x, y;
point(int x = , int y = ) :x(x), y(y) {} };
typedef point Vector;
Vector operator+ (const Vector& A, const Vector& B) { return Vector(A.x + B.x, A.y + B.y); }
Vector operator- (const point& A, const point& B) { return Vector(A.x - B.x, A.y - B.y); }
Vector operator* (const Vector& A, int p) { return Vector(A.x*p, A.y*p); }
Vector operator/ (const Vector& A, int p) { return Vector(A.x / p, A.y / p); }
bool operator== (const point& a, const point &b) { return a.x == b.x && a.y == b.y; }
bool operator< (const point& p1, const point& p2) { return p1.x < p2.x || (p1.x == p2.x && p1.y < p2.y); }
const int Gsize = ;
vector<string> grid;
point ePos;
map<char, Vector> Dirs;
bool valid(const point& p) {
return p.x >= && p.x < Gsize&&p.y >= && p.y < Gsize;
}
void printGrid() {
for (int i = ; i < Gsize; i++) {
rep(j, , Gsize - ) {
if (j)cout << ' ';
cout << grid[i][j];
}
cout << endl;
}
}
bool tryMove(char cmd) {
if (!Dirs.count(cmd))return false;
assert(Dirs.count(cmd));
point p = ePos + Dirs[cmd];
if (!valid(p))return false;
swap(grid[p.x][p.y], grid[ePos.x][ePos.y]);
ePos = p;
return true;
}
int n; int ans; void Run(){ } void smain() {
int t=;
string line;
Dirs['A'] = Vector(-, ); Dirs['B'] = Vector(, ); Dirs['L'] = Vector(, -); Dirs['R'] = Vector(, );
while () {
grid.clear();
ePos.x = -, ePos.y = -;
rep(i, , Gsize - ) {
getline(cin, line);
if (line == "Z")return;
assert(line.size() == Gsize);
rep(j, , Gsize - ){
if (line[j] != ' ')continue;
assert(ePos.x == - && ePos.y == -);
ePos.x = i;
ePos.y = j;
}
grid.push_back(line);
}
//char move;
string moves;
while () {
getline(cin, line); assert(!line.empty());
bool end = *(line.rbegin()) == '';
if (!end) moves.append(line);
else moves.append(line, , line.size() - );
if (end)break;
}
bool legal = ;
//int len =;
//rep(i, , moves.size() - )if (!tryMove(moves[i])) { legal = false; break; }
for (const auto& m : moves) if (!tryMove(m)) { legal = false; break; }
if (t > )cout << endl;
cout << "Puzzle #" << t++ << ":" << endl;//Puzzle #2:
if (legal) printGrid();
else cout << "This puzzle has no final configuration." << endl;
} }
/* TRGSJ
XDOKI
M VLN
WPABE
UQHCF
ARRBBL0
ABCDE
FGHIJ
KLMNO
PQRS
TUVWX
AAA
LLLL0
ABCDE
FGHIJ
KLMNO
PQRS
TUVWX
AAAAABBRRRLL0
Z*/
04-23 19:41