先给出比赛链接:
https://ac.nowcoder.com/acm/contest/92036
A 小红打怪
Show Code A
class Point { // 点类
public:
int x, y;
Point () {}
Point (int x, int y) : x(x), y(y) {}
Point operator+(const Point &P) const { return Point(x + P.x, y + P.y); }
};
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
map<char, point=""> mp{{'W', {-1,0}}, {'S', {1,0}}, {'A', {0,-1}}, {'D', {0,1}}};
int n, m;
cin >> n >> m;
Point be;
vector<vector> g(n + 1, vector(m + 1));
for (int i = 1; i <= n; ++ i) {
for (int j = 1; j <= m; ++ j) {
cin >> g[i][j];
if (g[i][j] != '.' && g[i][j] != '*') be = {i, j};
}
}
auto check = [&](Point p) {
if (1 <= p.x && p.x <= n && 1 <= p.y && p.y <= m) {
return 1;
} else {
return 0;
}
}; // 用于判断点是否在范围内
int ans = 0;
Point d = mp[g[be.x][be.y]];
Point cur = be + d;
while (check(cur)) {
if (g[cur.x][cur.y] == '*') {
ans ++;
}
cur = cur + d;
}
cout << ans << "\n";
}
B 马走日
Show Code B
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int tt;
cin >> tt;
while (tt--) {
ll n, m;
cin >> n >> m;
if (n == 1 || m == 1) {
cout << 1 << "\n";
} else if (n == 1 && m == 2) {
cout << 1 << "\n";
} else if (n == 2 && m == 1) {
cout << 1 << "\n";
} else if (n == 2 && m == 2) {
cout << 1 << "\n";
} else if (n == 2 && m == 3) {
cout << 2 << "\n";
} else if (n == 3 && m == 2) {
cout << 2 << "\n";
} else if (n == 3 && m == 3) {
cout << 8 << "\n";
} else {
ll ans;
if (n == 2) {
ans = (m + 1) / 2;
} else if (m == 2) {
ans = (n + 1) / 2;
} else {
ans = n * m;
}
cout << ans << "\n";
}
}
}
C 捡石头
Show Code C
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
ll n, m;
cin >> n >> m;
if (n % (m + 1) == 0) {
cout << "second\n";
} else {
cout << "first\n";
}
}
D 小红进地下城
Show Code D
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
string s1 , s2 ;
cin >> s1 >> s2 ;
if (s1 == s2) {
cout << "Yes\n";
} else {
cout << "No\n";
}
}
F 小红的字符串生成
Show Code F
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
string s1, s2;
cin >> s1 >> s2;
if (s1 == s2) {
cout << 2 << "\n";
cout << s1 << "\n";
cout << s1 + s2 << "\n";
} else {
cout << 4 << "\n";
cout << s1 << "\n";
cout << s2 + s1 << "\n";
cout << s1 + s2 << "\n";
cout << s2 << "\n";
}
}
G 小红的字符串中值
Show Code G
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int n;
char chr;
cin >> n >> chr;
string s;
cin >> s;
ll ans = 0;
for (int i = 0; i < n; ++ i) {
if (s[i] == chr) {
ll left = i + 1;
ll right = n - i;
ans += min(left, right);
}
}
cout << ans << "\n";
}
H [NOIP2015]扫雷游戏
Show Code H
class Point { // 点类
public:
int x, y;
Point () {}
Point (int x, int y) : x(x), y(y) {}
Point operator+(const Point &P) const { return Point(x + P.x, y + P.y); }
};
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int n, m;
cin >> n >> m;
vector<vector> g(n + 1, vector(m + 1));
vector<vector> dp(n + 1, vector(m + 1)); // dp[i][j] 表示(i, j)周围有几个雷
for (int i = 1; i <= n; ++ i) {
for (int j = 1; j <= m; ++ j) {
cin >> g[i][j];
}
}
auto check = [&](Point p) {
if (1 <= p.x && p.x <= n && 1 <= p.y && p.y <= m) {
return 1;
} else {
return 0;
}
}; // 用于判断点是否在范围内
for (int i = 1; i <= n; ++ i) {
for (int j = 1; j <= m; ++ j) {
if (g[i][j] == '*') {
dp[i][j] = -1;
for (int k1 = i - 1; k1 <= i + 1; ++ k1) {
for (int k2 = j - 1; k2 <= j + 1; ++ k2) {
if (check({k1, k2}) && (k1 != i || k2 != j) && g[k1][k2] != '*') {
dp[k1][k2]++;
}
}
}
}
}
}
for (int i = 1; i <= n; ++ i) {
for (int j = 1; j <= m; ++ j) {
if (dp[i][j] == -1) {
cout << '*';
} else {
cout << dp[i][j];
}
}
cout << "\n";
}
}
I 可编程拖拉机比赛
Show Code I
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int n;
cin >> n;
int ans = 0;
for (int i = 1; i <= 3; i ++) {
ans += (n * i + 9) / 10 - n * i / 10;
cout << ans << " ";
}
}
J 数圈圈
Show Code A
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
map<char, ll=""> mp{{'0', 1}, {'4', 1}, {'6', 1}, {'8', 2}, {'9', 1}};
int N = 1e6;
vector a(N + 1); // a[i] i这个数有几个圈
vector sa(N + 1); // sa[i] 1~i这些数有几个圈
for (int i = 1; i <= N; ++ i) {
string s = to_string(i);
for (auto si : s) {
sa[i] += mp[si];
}
sa[i] += sa[i - 1];
}
int tt = 1;
cin >> tt;
while (tt--) {
int a, b;
cin >> a >> b;
cout << sa[b] - sa[a - 1] << "\n";
}
}
K
Show Code A
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int n;
cin >> n;
cout << (10 - n % 10) % 10 << "\n";
}
标签:ZZJC,Point,int,题解,新生训练,nullptr,cin,tie,cout From: https://www.cnblogs.com/Proaes/p/18444685