1 条题解

  • 0
    @ 2025-9-9 23:46:55

    C :

    #include<stdio.h>
    int fun(int y1,int y2,int y3,int y4)
    {return ((y1+y2)*y3+y4);}
    int main()
    {
    	int T,max,y[5],s[12],i,p=0;
    	scanf("%d",&T);
    	while(T--)
    	{
    		for(i=0;i<4;i++)
    			scanf("%d",&y[i]);
    		s[0]=fun(y[0],y[1],y[2],y[3]);
    		s[1]=fun(y[0],y[1],y[3],y[2]);
    		s[2]=fun(y[0],y[2],y[1],y[3]);
    		s[3]=fun(y[0],y[2],y[3],y[1]);
    		s[4]=fun(y[0],y[3],y[1],y[2]);
    		s[5]=fun(y[0],y[3],y[2],y[1]);
    		s[6]=fun(y[1],y[2],y[0],y[3]);
    		s[7]=fun(y[1],y[2],y[3],y[0]);
    		s[8]=fun(y[1],y[3],y[2],y[0]);
    		s[9]=fun(y[1],y[3],y[0],y[2]);
    		s[10]=fun(y[2],y[3],y[0],y[1]);
    		s[11]=fun(y[2],y[3],y[1],y[0]);
    		max=s[0];
    		for(i=1;i<12;i++)
    			if(s[i]>max)
    				max=s[i];
    		printf("Case %d: %d\n",++p,max);
    	}
    	return 0;
    }
    
    

    C++ :

    #include<iostream>
    using namespace std;
    int main()
    {
    	int n;
    	cin >> n;
    	int flag = 0;
    	while (n--){
    		flag++;
    		int a[4];
    		for (int i = 0; i < 4; i++)
    			cin >> a[i];
    		int sum = -99999;
    		for (int i = 0; i < 4; i++)
    		for (int j = 0; j < 4; j++)
    		{
    			if (j == i)
    				continue;
    			for (int l = 0; l < 4; l++)
    			{
    				if (l == j || l == i)
    					continue;
    
    				for (int f = 0; f < 4; f++){
    					if (f == i || f == j || f == l)
    						continue;
    					if (sum < (a[i] + a[j])*a[l] + a[f])
    						sum = (a[i] + a[j])*a[l] + a[f];
    				}
    			}
    		}
    		cout <<"Case "<<flag<<": "<< sum << endl;
    	}
    }
    
    • 1

    信息

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