一个简单的矩阵乘法计算
#include <bits/stdc++.h>
using namespace std;
const int Len = 1e3+10;
#define ll long long
ll I[Len][Len],KK[Len][Len],ans[Len][Len];
int N,M,K,L;
int main()
{
cin>>N>>M>>K>>L;
for(int i = 0;i < N; ++i) {
for(int j = 0;j < M; ++j) {
cin>>I[i][j];
}
}
for(int i = 0;i < K; ++i) {
for(int j = 0;j < L; ++j) {
cin>>KK[i][j];
}
}
for(int i = 0;i < N; ++i) {
for(int j = 0;j < M; ++j) {
ll res = 0;
//x,y表示的是二维数组的I,a、b表示的是卷积核
for(int a = 0,x = i - K/2;a < K && x < N; ++a,++x) {
if(x < 0) continue;
for(int b = 0,y = j - L/2;b < L && y < M; ++b,++y){
if(x < 0 || y < 0) continue;
res += I[x][y] * KK[a][b];
}
}
if(res < 0) res = 0;
if(res > 255) res = 255;
ans[i][j] = res;
}
}
for(int i = 0;i < N; ++i) {
for(int j = 0;j < M; ++j) {
cout<<ans[i][j]<<" \n"[j == M-1];
}
}
return 0;
}
DFS染色即可,将读到的图01化
#include <bits/stdc++.h>
using namespace std;
const int Len = 1e3+10;
int mp[Len][Len];
int N,M;
bool vis[Len][Len];
int dx[4]={-1,1,0,0},dy[4] = {0,0,1,-1};
int cnt;
void dfs(int x,int y) {
if(vis[x][y] || mp[x][y] == 0) return;
cnt++;
vis[x][y] = true;
for(int i = 0;i < 4; ++i) {
int nx = x + dx[i];
int ny = y + dy[i];
dfs(nx,ny);
}
}
int main()
{
cin>>N>>M;
for(int i = 1;i <= N; ++i) {
for(int j = 1;j <= M; ++j) {
cin>>mp[i][j];
}
}
int temp;
for(int i = 1;i <= N; ++i) {
for(int j = 1;j <= M; ++j) {
cin>>temp;
mp[i][j] = temp == mp[i][j];
}
}
int ans = 0;
for(int i = 1;i <= N; ++i) {
for(int j = 1;j <= M; ++j) {
if(mp[i][j] && vis[i][j] == false) {
cnt = 0;
dfs(i,j);
ans = max(ans,cnt);
}
}
}
cout<<ans<<endl;
return 0;
}
/*
5 5
1 5 3 2 5
* * 4 * 2
3 * * * *
1 3 * * 8
4 * * * *
1 5 3 2 5
2 3 4 6 2
3 3 3 4 1
1 3 4 5 8
4 2 7 3 8
*/
不知道咋做,直接猜了个40%
#include <bits/stdc++.h>#科大讯飞##笔试题目##C/C++##关于秋招我想说##2023秋招#
using namespace std;
int main()
{
printf("x\ty\tz\t\n");
printf("3\t4\t5\t");
return 0;
}
/*
ans1 = 17
ans2 = 20;
*/