洛谷 - p2241 统计方形 (数学)

    技术2026-02-11  7

    题目传送 题意:

    思路: 一个长为2,宽为3的方形中: 长为2,宽为1的长方形的数量为:(2 - 0) * (3 - 1) + (2 - 1) * (3 - 0)

    正方形边长为1的数量为: (2-0) * (3-0) 边长为2的数量为: (2-1) * (3-1)

    子矩形的数量为原矩形的的长和宽减去一定长度来获得的,且长和宽减去的长度不能相同的为长方形,相同的为正方形,

    AC代码

    #include <bits/stdc++.h> inline long long read(){char c = getchar();long long x = 0,s = 1; while(c < '0' || c > '9') {if(c == '-') s = -1;c = getchar();} while(c >= '0' && c <= '9') {x = x*10 + c -'0';c = getchar();} return x*s;} using namespace std; #define NewNode (TreeNode *)malloc(sizeof(TreeNode)) #define Mem(a,b) memset(a,b,sizeof(a)) #define lowbit(x) (x)&(-x) const int N = 1e5 + 10; const long long INFINF = 0x7f7f7f7f7f7f7f; const int INF = 0x3f3f3f3f; const double EPS = 1e-7; const double EEE = exp(1); const int mod = 1e9+7; const double II = acos(-1); const double PP = (II*1.0)/(180.00); typedef long long ll; typedef unsigned long long ull; typedef pair<int,int> pii; typedef pair<ll,ll> piil; signed main() { std::ios::sync_with_stdio(false); cin.tie(0),cout.tie(0); // freopen("input.txt","r",stdin); // freopen("output.txt","w",stdout); int n,m; cin >> n >> m; ll a = 0,b = 0; for(int i = 0;i < n;i++) for(int j = 0;j < m;j++) i == j ? a += (n-i)*(m-j) : b += (n-i)*(m-j); cout << a << " " << b << endl; }
    Processed: 0.019, SQL: 9