1 条题解

  • 0
    @ 2021-6-14 23:25:21

    C :

    #include<stdio.h>
    int main()
    {
    	int n,m,i,j,s=0,k=0,t;
    	scanf("%d%d",&n,&m);
    	if(n>m)
    	{
    		t=n;n=m;m=t;
    	}
    	for(i=0;i<n;i++)
    		s+=(n-i)*(m-i);
    	for(i=0;i<n;i++)
    		for(j=0;j<m;j++)
    			if(i==j)
    				;
    			else
    			    k+=(n-i)*(m-j);
    		printf("%d %d",s,k);
    		return 0;
    }
    

    C++ :

    #include<iostream>
    #include<cmath>
    using namespace std;
    int main()
    {
    	int t=0,r=0;
    	int m,n,min;
    	cin >> n >> m;
    	min = n>m ? m:n;
    	for(int i=0; i<min; ++i)
    		t+= (n-i)*(m-i);
    	for(int i=0; i<n; ++i)
    		for(int j=0; j<m; ++j)
    	{
    		r+=(n-i)*(m-j);
    	}
    	cout << t << " " << r-t << endl;
    	return 0;
    }
    
    

    Pascal :

    var m,n,i,j,a,b,c,d:longint;
    begin
      readln(n,m);
      for i:=1 to n do
       a:=a+i;
      for j:=1 to m do
       b:=b+j;
      c:=a*b;
      a:=0;b:=0;
      if m>n then
               begin
                 a:=m;b:=n;
               end
        else
          begin
            a:=n;b:=m;
          end;
      for i:=0 to b do
        d:=d+((m-i)*(n-i));
      writeln(d,' ',c-d);
    end.
    

    Java :

    import java.util.Scanner;
    
    public class Main {
    	public static int N, M;
     
    	public static void main(String[] args) {
    		// TODO Auto-generated method stub
    		Scanner sc = new Scanner(System.in);
    		N = sc.nextInt();
    		M = sc.nextInt();
    		int sumz = 0;
    		int sumc = 0;
    		if (N > M) {
    			for (int i = M - 1; i >= 0; i--) {
    				sumz += (N - i) * (M - i);
    			}
    		} else {
    			for (int i = N - 1; i >= 0; i--) {
    				sumz += (N - i) * (M - i);
    			}
    		}
    		// 长方形个数
    		sumc = N * M * (N + 1) * (M + 1) / 4 - sumz;
    		System.out.println(sumz + " " + sumc);
     
    	}
     
    }
    
    
    • 1

    信息

    ID
    185
    时间
    1000ms
    内存
    125MiB
    难度
    (无)
    标签
    递交数
    0
    已通过
    0
    上传者