A. Number of Apartments(暴力出奇迹) Educational Codeforces Round 96 (Rated for Div. 2)

原题链接: https://codeforces.com/contest/1430/problem/A

在这里插入图片描述
测试样例

input
4
30
67
4
14
output
2 2 2
7 5 3
-1
0 0 2

题意: 在一栋建筑中可能有 3 3 3个窗户, 5 5 5个窗户, 7 7 7个窗户的公寓。现在给出窗户数,要你输出一个可能的公寓数量。

解题思路: 由于 n n n很小,直接暴力枚举判断就行,水题。

AC代码

/*
*邮箱:[email protected]
*blog:https://me.csdn.net/hzf0701
*注:文章若有任何问题请私信我或评论区留言,谢谢支持。
*
*/
#include<bits/stdc++.h>	//POJ不支持

#define rep(i,a,n) for (int i=a;i<=n;i++)//i为循环变量,a为初始值,n为界限值,递增
#define per(i,a,n) for (int i=a;i>=n;i--)//i为循环变量, a为初始值,n为界限值,递减。
#define pb push_back
#define IOS ios::sync_with_stdio(false);cin.tie(0); cout.tie(0)
#define fi first
#define se second
#define mp make_pair

using namespace std;

const int inf = 0x3f3f3f3f;//无穷大
const int maxn = 1e5;//最大值。
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll>  pll;
typedef pair<int, int> pii;
//*******************************分割线,以上为自定义代码模板***************************************//

int t,n;
int main(){
    
    
	//freopen("in.txt", "r", stdin);//提交的时候要注释掉
	IOS;
	while(cin>>t){
    
    
		while(t--){
    
    
			cin>>n;
			bool flag=false;
			for(int i=0;i<=n/3;i++){
    
    
				for(int j=0;j<=n/5;j++){
    
    
					for(int q=0;q<=n/7;q++){
    
    
						if(i*3+j*5+q*7==n){
    
    
							flag=true;
							cout<<i<<" "<<j<<" "<<q<<endl;
							break;
						}
					}
					if(flag)break;
				}
				if(flag)break;
			}
			if(!flag){
    
    
				cout<<-1<<endl;
			}
		}
	}
	return 0;
}

猜你喜欢

转载自blog.csdn.net/hzf0701/article/details/109015423