心路历程
cnmcnmcnmcnmcnmcnmcnmcnmcnmcnmcnmcnm
我的代码被lzx和lkp大佬调,一个劲的出数据
然后把他们自己AC代码卡掉, 然后我自己10分代码还没被卡
我:#*()@&¥#@真nm有趣.
到最后还是读题的问题,我真的一脸懵逼
这个题一开始的时候,图是从00开始还是11开始就没说
真的就是抠字眼,建议做一下 磨 炼 心 态
思路
判断标识错误的时候,什么都不和你说
然后会给你出小数和不在范围内的数,这种数一律按照error处理
还有他给你的机器人走的步数会有0,所以如果你一开始不判断的话就会炸(我就是这里,纪念一下)
一开始的时候我把第一个if放到了最下边,然后我就没了,我真的无语,cao
int bu = 0;
while (1) {
if (bu == x) break;
s--, bu++;
if (s < 0) { flag = 1, s += bu; return 1; }
if (tu[s][t] != 0) { flag = 1, s += bu; return 1; }
}
总之,细节有亿点点, 注意细节就行了.不想多说话(又双叒叕浪费了一天,我去,吐了)
code
/*
time:2020.4.26
Auther:_Destiny
*/
#include <bits/stdc++.h>
#define ll long long
#define N 100010
#define M 210
using namespace std;
int T, n, m, s, t;
int tu[M][M], paochao, renchao, h;
int arong, dajing, xiaojing, k, flag, f1 = 1;
string opt; stack<int> a;//弹夹
int ma[M][M];//在i,j处的靶子的生命值
int read() {
int s = 0, f = 0; char ch = getchar();
while (!isdigit(ch)) f |= (ch == ‘-‘), ch = getchar();
while (isdigit(ch)) s = s * 10 + (ch ^ (48)), ch = getchar();
return f ? -s : s;
}
void init() {//初始化清理
flag = 0, f1 = 1, h = 0, s = 0, t = 0, arong = 0;
paochao = 0, renchao = 0, dajing = 0, xiaojing = 0;
while (!a.empty()) a.pop();
memset(tu, 0, sizeof tu);
memset(ma, 0, sizeof ma);
}
void clear(int x) {
std::string s; getchar();
for (int i = 1; i <= k - x; ++i)
getline(std::cin, s);
}
void paozhuan() {//炮台旋转
double ds; cin >> ds; int x1 = ds;
if (x1 != ds) { flag = 1; return; }
if (x1 < 0 || x1 > 1) { flag = 1; return; }
if (x1 == 1) {
paochao--;
if (paochao == -1) paochao = 3;
}//paochao机器人朝向
else if (x1 == 0) {
paochao++;
if (paochao == 4) paochao = 0;
}
}
void renzhuan() {//机器人转动
double ds; cin >> ds; int x1 = ds;
if (x1 != ds) { flag = 1; return; }
if (x1 < 0 || x1 > 1) { flag = 1; return; }
if (x1 == 0) {
renchao++;
if (renchao == 4) renchao = 0;
}//renchao机器人朝向
else if (x1 == 1) {
renchao--;
if (renchao == -1) renchao = 3;
}
}
void tiandan() {//装弹药
double ds;
cin >> ds;
int x = ds;
if (x != ds) { flag = 1; return; }
if (x < 0 || x > 1) { flag = 1; return; }
if ((int)(a.size() + 1) > arong) { flag = 1; return ; }
if (x == 1) {
if (dajing) { a.push(2); dajing--; }
} else if (x == 0) {
if (xiaojing) { a.push(1); xiaojing--; }
}
}
void fashe() {//发射子弹
if (a.empty()) return;
int shanghai = a.top(); a.pop();
if (paochao == 0) {
for (int i = s - 1; i >= 0; i--)
if (tu[i][t] == 1) break;
else if (tu[i][t] == 2) {
ma[i][t] -= shanghai;
if (ma[i][t] <= 0) tu[i][t] = 0, h++;
return;
}
} else if (paochao == 1) {
for (int i = t - 1; i >= 0; i--)
if (tu[s][i] == 1) break;
else if (tu[s][i] == 2) {
ma[s][i] -= shanghai;
if (ma[s][i] <= 0) tu[s][i] = 0, h++;
return;
}
} else if (paochao == 2) {
for (int i = s + 1; i < n; i++)
if (tu[i][t] == 1) break;
else if (tu[i][t] == 2) {
ma[i][t] -= shanghai;
if (ma[i][t] <= 0) tu[i][t] = 0, h++;
return;
}
} else if (paochao == 3) {
for (int i = t + 1; i < m; i++)
if (tu[s][i] == 1) break;
else if (tu[s][i] == 2) {
ma[s][i] -= shanghai;
if (ma[s][i] <= 0) tu[s][i] = 0, h++;
return;
}
}
}
bool renzou() { //机器人走
double ds; cin >> ds; int x = ds;
if (x != ds) { flag = 1; return 1; }
if (x < 0 || x >= max(n, m)) { flag = 1; return 1; }
if (renchao == 0) {
int bu = 0;
while (1) {
if (bu == x) break;
s--, bu++;
if (s < 0) { flag = 1, s += bu; return 1; }
if (tu[s][t] != 0) { flag = 1, s += bu; return 1; }
}
} else if (renchao == 1) {
int bu = 0;
while (1) {
if (bu == x) break;
t--, bu++;
if (t < 0) {flag = 1, t += bu; return 1; }
if (tu[s][t] != 0) { flag = 1, t += bu; return 1; }
}
} else if (renchao == 2) {
int bu = 0;
while (1) {
if (bu == x) break;
s++, bu++;
if (s >= n) {flag = 1, s -= bu; return 1; }
if (tu[s][t] != 0) {flag = 1, s -= bu; return 1; }
}
} else if (renchao == 3) {
int bu = 0;
while (1) {
if (bu == x) break;
t++, bu++;
if (t >= m) {flag = 1, t -= bu; return 1; }
if (tu[s][t] != 0) { flag = 1, t -= bu; return 1; }
}
}
return 0;
}
int main() {
scanf("%d", &T);
while (T--) {
init();
scanf("%d%d", &n, &m);
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++) {
scanf("%d", &tu[i][j]);
if (tu[i][j] == 2) ma[i][j] = 2;//给靶子生命值
}
scanf("%d%d%d%d%d%d", &s, &t, &arong, &dajing, &xiaojing, &k);
for (int i = 1; i <= k; i++) {
cin >> opt;
if (opt == "END") { f1 = 0; clear(i); break; }
else if (opt == "FT") paozhuan();
else if (opt == "FF") tiandan();
else if (opt == "FE") fashe();
else if (opt == "WT") renzhuan();
else if (opt == "WG") if (renzou()) flag = 1;
if (flag == 1) { clear(i); break;}
}
if (f1 == 1 || flag == 1) puts("ERROR");
else if (f1 == 0) puts("Complete");
printf("%d %d\n", s, t);
printf("%d\n", h);
printf("%d %d %d %d\n", paochao, renchao, dajing, xiaojing);
}
}