A. 扑克牌
直接去重后拿52减去数量即可
#include <bits/stdc++.h>
using namespace std;
int n;
vector<string> s;
int main() {
cin >> n;
for (int i = 1; i <= n; i++) {
string t;
cin >> t;
s.push_back(t);
}
sort(s.begin(), s.end());
cout << 52 - (unique(s.begin(), s.end()) - s.begin());
return 0;
}
B. 地图探险
简单模拟,对着题目写就行
#include <bits/stdc++.h>
using namespace std;
int t, w[4][2] = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}};
int n, m, k, x, y, d;
bool vis[1010][1010];
char g[1010][1010];
int main() {
cin >> t;
while (t--)
{
cin >> n >> m >> k;
cin >> x >> y >> d;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++) {
vis[i][j] = 0;
cin >> g[i][j];
}
int ans = 1;
vis[x][y] = true;
for (int i = 1; i <= k; i++)
{
int tx = x + w[d][0], ty = y + w[d][1];
if (tx >= 1 && tx <= n && ty >= 1 && ty <= m && g[tx][ty] == '.') {
x = tx, y = ty;
if (!vis[x][y])
vis[x][y] = true, ans++;
}
else
d = (d + 1) % 4;
}
cout << ans << '\n';
}
return 0;
}
C. 小木棍
一开始想贪心,想了想先打个表,结果一打表直接就很明显能看出规律了
#include <bits/stdc++.h>
using namespace std;
string solve(int n)
{
if (n <= 1)
return "-1";
if (n == 2)
return "1";
if (n == 3)
return "7";
if (n == 4)
return "4";
if (n == 5)
return "2";
if (n == 6)
return "6";
if (n == 7)
return "8";
if (n == 8)
return "10";
if (n == 9)
return "18";
if (n == 10)
return "22";
int t = n % 7;
if (t == 0)
return string(n / 7, '8');
if (t == 1)
return "10" + string(n / 7 - 1, '8');
if (t == 2)
return "1" + string(n / 7, '8');
if (t == 3)
return "200" + string(n / 7 - 2, '8');
if (t == 4)
return "20" + string(n / 7 - 1, '8');
if (t == 5)
return "2" + string(n / 7, '8');
if (t == 6)
return "6" + string(n / 7, '8');
return "-1";
}
int main() {
int t;
cin >> t;
while (t--)
{
int n;
cin >> n;
cout << solve(n) << '\n';
}
return 0;
}
D. 接龙
还没做,占坑