ECNU2984. 数学手稿

返回目录

题目链接
在这里插入图片描述

#include <bits/stdc++.h>
using namespace std;

int main() {
    
    
    int T;
    cin>>T;
    int N,K;
    for(int t=0;t<T;t++){
    
    
        scanf("%d%d",&N,&K);
        printf("case #%d:\n",t);
        int m,w,c;//人数
        int cm,cw,cc;//消费
        int count=0;
        for(int i=0;i<=N;i++){
    
    
            cm=i*3;
            m=i;
            for(int j=0;j<=N-m;j++){
    
    
                cw=j*2;
                w=j;
                c=N-m-w;
                cc=c;
                if(cm+cw+cc==K){
    
    
                    count++;
                    printf("%d %d %d\n",m,w,c);
                }
            }
        }
        if(count==0){
    
    
            printf("-1\n");
        }
    }
}

猜你喜欢

转载自blog.csdn.net/a1920993165/article/details/129380901