【记录】「COCI 2024/2025」四道模拟赛/8.13

打得心情很不好的一场,一直在调试,被初二的吵得头痛。

后面一个小时去管纪律了,最终榜六。


P14466 COCI 2025/2026 #1 押韵 / Rima - 洛谷

一时忘记 substr 怎么用了,竟然做了半小时?!

cpp 复制代码
#include<bits/stdc++.h>
using namespace std;

const int N = 25;
int ans[5];
string mp[5];

int main () {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n, m, K;
    cin >> n >> m >> K;
    memset(ans, 0, sizeof(ans));
    
    for (int i = 1; i <= n; i ++) {
        if (i % 4 == 1) {
            for (int j = 1; j <= 4; j ++) {
                mp[j] = "";
            }
        }
        
        string ss;
        for (int j = 1; j <= m; j ++) {
            string s;
            cin >> s;
            if (j == m) {
                ss = s;
            }
        }
        
        // 处理最后一个单词
        int now = i % 4;
        if (now == 0) now = 4;
        
        if (ss.length() >= K) {
            mp[now] = ss.substr(ss.length() - K);
        } 
		else {
            mp[now] = ""; 
        }
        
        if (now == 4) {
            if (mp[1] == mp[2] && mp[3] == mp[4] && 
                mp[1] != "" && mp[2] != "" && mp[3] != "" && mp[4] != "") {
                ans[1] ++;
            }
            if (mp[1] == mp[3] && mp[2] == mp[4] &&
                mp[1] != "" && mp[2] != "" && mp[3] != "" && mp[4] != "") {
                ans[2] ++;
            }
            if (mp[1] == mp[4] && mp[2] == mp[3] &&
                mp[1] != "" && mp[2] != "" && mp[3] != "" && mp[4] != "") {
                ans[3] ++;
            }
        }
    } 
    
    cout << ans[1] << " " << ans[2] << " " << ans[3] << "\n";
    
    return 0;
}

P14467 COCI 2025/2026 #1 扔球 / Krugomet - 洛谷

套路题。我该怎么说,一开始完全没往 st 表想。

后来意识到球的总数是不会变的,即只需要确定每个人的球最终传给了谁。

问了下 wyh 和不和环有关,他说没关,就大胆往这方面想了。

然后调了 40 分钟,死因是 st 定义数组时二维空间写反了。

绝对不会再犯这种错误。

cpp 复制代码
#include<bits/stdc++.h>
using namespace std;

const int N = 1e5 + 10;
typedef long long LL;
LL a[N], s[N];
LL st[50][N];
LL sum[N];
LL K;

int get_(int x) {
	LL kk = K; 
	for (int i = 0; i <= 34; i ++) {
		if (kk & (1ll << i)) {
			x = st[i][x];
		}
	}
	return x;
}

int main () {
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int n;
	cin >> n >> K;
	
	for (int i = 1; i <= n; i ++) {
		cin >> a[i];
	}
	
	memset(st, 0, sizeof(st));
	for (int i = 1; i <= n; i ++) {
		cin >> s[i];
		st[0][i] = s[i];
	}
	
	for (int no = 1; no <= 34; no ++) {
		for (int i = 1; i <= n; i ++) {
			st[no][i] = st[no - 1][st[no - 1][i]];
		}
	}
	
	memset(sum, 0, sizeof(sum));
	for (int i = 1; i <= n; i ++) {
		int x = get_(i);
		sum[x] += a[i];
	}
	
	LL mx = 0;
	for (int i = 1; i <= n; i ++) {
		mx = max(mx, sum[i]);
	}
	cout << mx << "\n";
	
	for (int i = 1; i <= n; i ++) if (sum[i] == mx) {
		cout << i << " ";
	}
	cout << "\n";
	return 0;
} 

P14469 COCI 2025/2026 #1 皇后 / Kraljica - 洛谷

卡常卡得很崩溃的一道,严重感觉时限应该开大点。

看了题解感觉没有任何区别,但人家就是跑得快,最后抄题解过了。

自己的码只有 106 分。

cpp 复制代码
#include<bits/stdc++.h>
using namespace std;

const int N = 1005;
const int dx[] = {1, -1, 0, 0, 1, 1, -1, -1};
const int dy[] = {0, 0, 1, -1, -1, 1, -1, 1};

int n, m;
char c[N][N];
bool vis[N][N], wall[N][N];
vector<pair<int,int>> portal[10];

struct node {
    int x, y, step;
};

queue<node> q;

bool check(int x, int y) {
    if(x < 1 || x > n || y < 1 || y > m) return false;
    if(c[x][y] == '#') return false;
    return true;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    cin >> n >> m;
    for(int i = 1; i <= n; i++) {
        cin >> (c[i] + 1);
        for(int j = 1; j <= m; j++) {
            if(c[i][j] == 'S') {
                q.push({i, j, 0});
                vis[i][j] = true;
            }
            if(c[i][j] >= '0' && c[i][j] <= '9') {
                portal[c[i][j] - '0'].push_back({i, j});
            }
            if(c[i][j] == '#') {
                wall[i][j] = true;
            }
        }
    }
    
    while(!q.empty()) {
        node u = q.front();
        q.pop();
        
        if(c[u.x][u.y] == 'E') {
            cout << u.step << endl;
            return 0;
        }
        
        // 8个方向扩展
        for(int i = 0; i < 8; i++) {
            int t = 1;
            while(true) {
                int nx = u.x + t * dx[i];
                int ny = u.y + t * dy[i];
                t++;
                
                // 先检查是否访问过,再检查是否合法(与正确代码一致)
                if(vis[nx][ny]) continue;
                if(!check(nx, ny)) break;
                
                vis[nx][ny] = true;
                q.push({nx, ny, u.step + 1});
                
                // 处理传送门
                if(c[nx][ny] >= '1' && c[nx][ny] <= '9') {
                    int id = c[nx][ny] - '0';
                    for(auto p : portal[id]) {
                        if(p.first == nx && p.second == ny) continue;
                        if(vis[p.first][p.second]) continue;
                        vis[p.first][p.second] = true;
                        q.push({p.first, p.second, u.step + 1});
                    }
                }
            }
        }
    }
    
    cout << -1 << endl;
    return 0;
}

后两道都单开:

P14468 COCI 2025/2026 #1 和谐 / Harmonija - 洛谷

【题解】P14468 COCI 2025/2026 #1 和谐 / Harmonija(线段树 DDP 版本)-CSDN博客

P14470 COCI 2025/2026 #1 松鼠 / Zagi - 洛谷

【题解】COCI 2025/2026 #1 松鼠 / Zagi-CSDN博客

相关推荐
.道阻且长.1 小时前
8.LeetCode算法习题讲解--滑动窗口--长度最小的子数组
算法·leetcode·职场和发展
(❁´◡`❁)Jimmy(❁´◡`❁)1 小时前
P1156 [USACO01OPEN] 垃圾陷阱
算法·动态规划
疯狂打码的少年2 小时前
【数据结构】二叉排序树(BST)的定义与操作
数据结构·笔记·算法
lally.2 小时前
整数等差数列超图中的三个非微扰现象
算法
Titan20242 小时前
Linux网络学习:套接字、UDP的封装与应用
linux·服务器·开发语言·网络·c++
wabs6662 小时前
关于字符串【力扣541.反转字符串II的思考】
数据结构·算法·leetcode·字符串
土司大王2 小时前
LeetCode hot100——移动零
java·算法·leetcode
Felven3 小时前
C2. Potions (Hard Version)
c++
Tyler_TXZ3 小时前
C++C语言之——树
c语言·c++·算法·