四级三套卷子难易程度

四级三套卷子难易程度

首页技巧更新时间:2025-02-25 00:10:44

1单项选择题

2判断题

3编程实战

黑白方块

题目分析

暴力枚举所有 4x4 的长方形,判断周围一圈为白色,中间为黑色,每个长方形最多判断 16 次。只要有一个格子不满足要求就判断下一个长方形。只要找到一个满足要求的长方形,就输出 “Yes”。

参考程序

#include <bits/stdc .h> using namespace std; const int N = 110; int n, m; int g[N][N]; bool judge(int i, int j){ for(int x = i; x <= i 3; x ){ for(int y = j; y <= j 3; y ){ // cout << g[x][y]; if(x == i || x == i 3 || y == j || y == j 3) { if(g[x][y] != 0){ // flag = false; return false; } } else { if(g[x][y] != 1) return false; } } // puts(""); } // puts(""); return true; } bool check(){ for(int i = 1; i <= n - 3; i ){ for(int j = 1; j <= m - 3; j ){ bool r = judge(i, j); if(r) return r; } } return false; } int main() { int T; cin >> T; while(T--){ memset(g, 0, sizeof g); cin >> n >> m; for(int i = 1; i <= n; i ){ for(int j = 1; j <= m; j ){ char ch; cin >> ch; g[i][j] = ch - '0'; } } check() ? puts("Yes") : puts("No"); } return 0; }

区间排序

题目分析

按照题目难度,过于简单,不是很合适放到四级第二题位置。

调用 sort 排序,模拟。

参考程序

#include <bits/stdc .h> using namespace std; int n; int a[110]; int main() { cin >> n; for(int i = 1; i <= n; i ) cin >> a[i]; int q; cin >> q; while(q--){ int L, R; cin >> L >> R; sort(a L, a R 1); } for(int i = 1; i <= n; i ) cout << a[i] << ' '; return 0; },

大家还看了
也许喜欢
更多栏目

© 1998-2024 shitiku.com.cn,All Rights Reserved.