中山市东区信息学竞赛2025 题目解析
声明
有些题目是不一样的!
但是代码是可以参考的!
作者https://blog.csdn.net/2401_89382924?spm=1011.2415.3001.5343
题目
代码
第一题
#include <stdio.h>struct milk_t
{int now, max;void Scanf(void) {scanf("%d%d", &max, &now);}
};void GetMilk_t(milk_t& a1, milk_t& a2)
{// a1 -> a2;if (a1.now + a2.now <= a1.max)a1.now += a2.now, a2.now = 0;elsea2.now = a2.now - (a1.max - a1.now), a1.now = a1.max;
}int n;
int main()
{scanf("%d", &n);milk_t a, b, c;a.Scanf(), b.Scanf(), c.Scanf();for (int i = 1; i <= n; i++){if (i % 3 == 1) GetMilk_t(b, a);if (i % 3 == 2) GetMilk_t(c, b);if (i % 3 == 0) GetMilk_t(a, c);}printf("%d\n%d\n%d", a.now, b.now, c.now);return 0;
}
题目2
#include <stdio.h>
#include <string>
#include <iostream>
#include <algorithm>using namespace std;
struct nba_t
{int year;string name;bool operator < (nba_t p){return year < p.year;}
}a[100005];int n;
int main()
{scanf("%d", &n);for (int i = 1; i <= n; i++)cin >> a[i].name >> a[i].year;sort(a + 1, a + n + 1);for (int i = 1; i <= n; i++)cout << a[i].year << ' ' << a[i].name << endl;return 0;
}
题目3
#include <stdio.h>int n, Map[505][505];// 1up 2down 3left 4right
int px[] = {-1, 1, 0, 0};
int py[] = {0, 0, -1, 1};
void dfs(int x, int y, int c, int& step)
{if (Map[x][y] == n * n)return ;for (int i = 0; i < 4; i++){int tx = x + px[i], ty = y + py[i];if (tx < 0 || ty < 0 || tx >= n || ty >= n) continue;if (Map[tx][ty] == Map[x][y] + 1){if (c != i) step++;dfs(tx, ty, i, step);break;}}
}
int main()
{scanf("%d", &n);if (n == 1){printf("0");return 0;}int x1, y1;for (int i = 0; i < n; i++){for (int j = 0; j < n; j++){scanf("%d", &Map[i][j]);if (Map[i][j] == 1)x1 = i, y1 = j;}}for (int i = 0; i < 4; i++){int tx = x1 + px[i], ty = y1 + py[i];if (tx < 0 || ty < 0 || tx >= n || ty >= n) continue;if (Map[tx][ty] == 2){int step = 0;dfs(x1, y1, i, step);printf("%d", step);return 0;}}return 0;
}
题目4
#include <stdio.h>
#include <queue>
using std::queue;char Map[65][65];
int vis[65][65][65][65], n;
int px[] = {-1, 1, 0, 0};
int py[] = {0, 0, -1, 1};#define check(p1) (p1.x < 0 || p1.y < 0 || p1.x >= n || p1.y >= n)
struct Pos_t {int x, y; Pos_t(int _x=0, int _y=0) : x(_x), y (_y) {};};
struct Node_t {Pos_t p1, p2;int step;
};
int bfs(Node_t start)
{queue<Node_t> q1;q1.push(start);vis[start.p1.x][start.p1.y][start.p2.x][start.p2.y] = 1;while (q1.size()) {Node_t qFront = q1.front(); q1.pop();if (qFront.p1.x == qFront.p2.x && qFront.p1.y == qFront.p2.y) return qFront.step;for (int i = 0; i < 4; i++){Node_t qTemp = qFront;qTemp.p1.x += px[i], qTemp.p1.y += py[i], qTemp.p2.x += px[i], qTemp.p2.y += py[i], qTemp.step ++;bool f1 = true, f2 = true;if (check(qTemp.p1))f1 = false;else if (Map[qTemp.p1.x][qTemp.p1.y] == '#') f1 = false;if (check(qTemp.p2))f2 = false;else if (Map[qTemp.p2.x][qTemp.p2.y] == '#') f2 = false;if (!f1 && !f2) // 全部越界 不要玩了continue;if (!f1) // 第一个人越界 -> 停在原来的位置qTemp.p1 = qFront.p1;if (!f2) // 第二个人越界qTemp.p2 = qFront.p2;if (vis[qTemp.p1.x][qTemp.p1.y][qTemp.p2.x][qTemp.p2.y] == 1) // 做过了continue;q1.push(qTemp);vis[qTemp.p1.x][qTemp.p1.y][qTemp.p2.x][qTemp.p2.y] = 1;}}return -1;
}
int main()
{Node_t start; bool f = true;start.step = 0;scanf("%d", &n);for (int i = 0; i < n; i++)for (int j = 0; j < n; j++){char ch;
// scanf("%c", &Map[i][j]);while ((ch = getchar()) == '\n' || ch == '\r');Map[i][j] = ch;if (Map[i][j] == 'P'){if (f) start.p1 = Pos_t(i, j), f = false;else start.p2 = Pos_t(i, j);}}printf("%d", bfs(start));return 0;
}
题目5
#include <stdio.h>int n, t;
int cnt[3];
long long sum = 0;
#define Gay(p) {printf("%d", n - p); return 0;}
int main()
{scanf("%d", &n);for (int i = 0; i < n; i++){scanf("%d", &t);sum += t;cnt[t % 3] ++;}sum %= 3;if (sum == 1){// 余数是1// 使用一个余数是1的数字if (cnt[1] >= 1)Gay(1)// 使用2个余数是2的数字// 16 = 2 + 2 + 12if (cnt[2] >= 2)Gay(2)}if (sum == 2){// 余数是2// 使用一个余数是2的数字if (cnt[2] >= 1)Gay(1);// 使用两个余数是1的数字if (cnt[1] >= 2)Gay(2);}if (sum == 0)Gay(0)return 0;
}