1 solutions

  • 0
    @ 2025-11-5 17:22:21

    C :

    //现有n块砖,要由n人一次搬完,假定男人一次可以搬4块,女人一次可以搬3块,两个小孩搬1块
    #include <stdio.h>
    
    int main()
    {
    	int n;
    	scanf("%d",&n);
    	int men;
    	int woman;
    	int children;
    	int flag = 0; 
    	for( men=1; men<=n/4; men++ ){
    		for( woman=1;woman<=n/3; woman++ ){
    			for( children=2; children<=2*n; children+=2 ){
    				if( men+woman+children==n&&men*4+woman*3+children/2==n ){
    					printf("men%d\nwomen%d\nchildren%d\n",men,woman,children);
    					flag = 1;
    				}
    			}
    		}
    	} 
    	
    	if( flag != 1 ){
    		printf("no result!");
    	}
    	return 0;
    }
    

    C++ :

    #include <iostream>
    using namespace std;
    int main(){
    	int x,y,z,n,c=0;
    	cin>>n;
    	for(x=1;x<n;x++){
    	 for(y=1;y<n;y++){
    	  for(z=1;z<n;z++){
    	    if(((double)n==4*(double)x+3*(double)y+(double)z/2)&&(n==x+y+z)){
    	    	cout<<"men"<<x<<endl;
    	    	cout<<"women"<<y<<endl;
    	    	cout<<"children"<<z<<endl;
    	    	c=1;
    		}
    	  }
         }
        }
        if(c==0){
        cout<<"no result!";
        }
    return 0;	
    }
    
    • 1

    Information

    ID
    18355
    Time
    2000ms
    Memory
    30MiB
    Difficulty
    (None)
    Tags
    # Submissions
    0
    Accepted
    0
    Uploaded By