总结
T1
真的入门,一点思考量都没有,照着题意写就行了。
#include <bits/stdc++.h>
using namespace std;
int n, cnt = 0;
bool p[4][13];
int main () {
memset (p, 0, sizeof (p));
scanf ("%d", &n);
for (int i = 1;i <= n;++ i) {
char a, b;
int c, d;
cin >> a >> b;
if (a == 'D') {
c = 0;
} else if (a == 'C') {
c = 1;
} else if (a == 'H') {
c = 2;
} else if (a == 'S') {
c = 3;
}
if (b == 'A') {
d = 0;
} else if (b == 'T') {
d = 9;
} else if (b == 'J') {
d = 10;
} else if (b == 'Q') {
d = 11;
} else if (b == 'K') {
d = 12;
} else {
d = b - '0' - 1;
}
if (!p[c][d]) {
p[c][d] = true;
++ cnt;
}
}
cout << 52 - cnt << endl;
return 0;
} // DCHST2
也是照着题意模拟就行。
#include <bits/stdc++.h>
using namespace std;
int t;
int n, m, k;
int x, y, d; //不要y0!!!啊!!!
bool mp[1010][1010];
bool vis[1010][1010];
constexpr int dx[4] = {0, 1, 0, -1};
constexpr int dy[4] = {1, 0, -1, 0};
int main() {
scanf ("%d", &t);
while (t --) {
int cnt = 1;
memset (mp, 0, sizeof (mp));
memset (vis, 0, sizeof (vis));
scanf ("%d%d%d%d%d%d", &n, &m, &k, &x, &y, &d);
for (int i = 1; i <= n; ++ i) {
for (int j = 1; j <= m; ++ j) {
char c;
scanf (" %c", &c);
if (c == 'x') {
mp[i][j] = true;
} else {
mp[i][j] = false;
}
}
}
vis[x][y] = true;
for (int i = 1; i <= k; ++ i) {
int xx = x + dx[d];
int yy = y + dy[d];
if (0 < xx && xx <= n && 0 < yy && yy <= m && !mp[xx][yy]) {
if (!vis[xx][yy]) {
vis[xx][yy] = true;
++cnt;
}
x = xx;
y = yy;
} else {
d = (d + 1) % 4;
}
}
printf ("%d\n", cnt);
}
return 0;
}