铺墙纸

#include<iostream>
#include<string>
using namespace std;

int main()
{
    int t;
    cin >> t;
    while (t--)
    {
        int n, m;
        cin >> n >> m;
        char a[700][700];
        for (int i = 0; i < n; i++)
        {
            for (int j = 0; j < n; j++)
            {
                cin >> a[i][j];
            }
        }
        string s;
        getline(cin, s);
        getline(cin, s);

        int x = n;
        char b[700][700];
        if (n != 1)
        {
            if (n != m)
            {
                do
                {
                    x += 2;
                    if (x >= m && x % n == 0) break;
                } while (1);
            }


            int st = (x - m) / 2;
            int num = x / 3;

            int idx = 0;

            for (int i = 0; i < x; i++)
            {
                int j = i % n;
                int k = 0;
                idx = 0;
                while (idx < x)
                {

                    k = idx % n;
                    b[i][idx] = a[j][k];
                    k++;
                    idx++;
                }
            }
            for (int i = st; i < m + st; i++)
            {
                for (int j = st; j < m + st; j++)
                {
                    cout << b[i][j];
                }
                cout << endl;
            }
            cout << endl;
        }
        else
        {
            for (int i = 0; i < m; i++)
            {
                for (int j = 0; j < m; j++)
                {
                    cout << a[0][0];
                }
                cout << endl;
            }
            cout << endl;
        }
    }
}

相交正方形面积

#include<iostream>
#include<string>
#include<cstring>
#include<vector>
using namespace std;
vector<vector<int>> vec(501, vector<int>(4));
bool yx[501];    //是否有效

bool cd(vector<int> vec1, vector<int> vec2)        //是否重叠
{
    return !(vec1[2] <= vec2[0] || vec2[2] <= vec1[0] || vec1[3] <= vec2[1] || vec2[3] <= vec1[1]);
}

int area(int a, int b, int c, int d, int e, int f, int g, int h)    //重叠区域面积
{
    if (!(c <= e || g <= a || h <= b || d <= f))
    {
        int a1 = (d - b) * (c - a);
        int a2 = (h - f) * (g - e);
        return a1 + a2 - (min(c, g) - max(a, e)) * (min(d, h) - max(b, f));
    }

    return 0;
}

int main()
{
    int t;
    cin >> t;
    while (t--)
    {
        vec.clear();
        memset(yx, 0, sizeof(yx));
        int n;
        cin >> n;
        while (n--)
        {
            int x0, y0, x1, y1;
            cin >> x0 >> y0 >> x1 >> y1;
            vec.push_back({ x0,y0,x1,y1 });
        }

        for (int i = 0; i < vec.size() - 1; i++)
        {
            bool flag = false;
            int j = i + 1;
            if (yx[i] == true) continue;
            for (j = i + 1; j < vec.size(); j++)
            {

                if (cd(vec[i], vec[j]))
                {
                    flag = true;
                    break;
                }
            }
            if (flag)
            {
                yx[i] = true;
                yx[j] = true;
            }
            else yx[i] = false;
        }
        int sum = 0;
        for (int i = 0; i < vec.size() - 1; i++)
        {
            if (yx[i] == false) continue;
            for (int j = i + 1; j < vec.size(); j++)
            {
                if (yx[j] == false) continue;
                sum += area(vec[i][0], vec[i][1], vec[i][2], vec[i][3], vec[j][0], vec[j][1], vec[j][2], vec[j][3]);
            }
        }
        cout << sum << endl;
    }

}

Q.E.D.