Temp

· · 闲话

同学借鉴版↓

#include<bits/stdc++.h>
using namespace std;
int r, c, a[105][105], m[105][105], maxx = 1000000, k, ans;
char t;
int main()
{
    cin >> r >> c >> k;
    for(int i = 1; i <= r; i++)
    {
        for(int j = 1; j <= c; j++)
        {
            cin >> t;
            if(t == 'o') a[i][j] = 1;
        }
    }
    for(int i = 1; i <= r; i++)
        for(int j = 1; j <= c; j++)
            m[i][j] = m[i - 1][j] + m[i][j - 1] - m[i - 1][j - 1] + a[i][j];
    for(int i = 1; i <= r; i++)
    {
        for(int j = 1; j <= c; j++)
        {
            for(int x = i; x <= r; x++)
            {
                for(int y = j; y <= c; y++)
                {
                    if(m[x][y] - m[i - 1][y] - m[x][j - 1] + m[i - 1][j - 1] == k)
                    {
                        ans = (i - 1) + (j - 1) + (r - x) + (c - y);
                        ans += min((i - 1), (r - x));
                        ans += min((j - 1), (c - y));
                        maxx = min(maxx, ans);
                    }
                }
            }
        }
    }
    if(maxx == 1000000) maxx = -1;
    cout << maxx;
    return 0;
}

陈曦予路过(~ ̄▽ ̄)~

点个赞吧~TAT

Code 暂存处👇

#include<bits/stdc++.h>
using namespace std;

const int MAXN = 5e4 + 5; 
long long n, d1[MAXN], d2[MAXN];
struct whole
{
    long long to, w;
};
vector <whole> edge[MAXN << 1];
void dfs1(long long u, long long f)
{
    for(int i = 0; i < edge[u].size(); i++)
    {
        long long to
    }
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    cin >> n;
    for(int i = 1; i < n; i++)
    {
        long long u, v, w;
        cin >> u >> v >> w;
        edge[u].push_back((whole) {v, w});
        edge[v].push_back((whole) {u, w});
    }

    return 0;
}