暴力枚举。
#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
int res1,res2;
int main(){
int a,b,c;//女生 男生 寝室数
cin>>a>>b>>c;
int minsub = inf;
for(int i=2;i<a;i++){//i表示女生几人间
if(a % i == 0 && c-a/i > 0 && b % (c-a/i)==0){
int female = a/i;//女生需要几间
int male = c-female;//男生需要几间
int ns = i;//女生几人间
int nans = b / (c-a/i);//男生几人间
if(abs(ns - nans)<minsub){//人数差
minsub = abs(ns - nans);
res1=female;
res2=male;
}
}
}
if(minsub==inf){
cout << "No Solution" << '\n';
}else{
cout << res1 << " " << res2;
}
return 0;
}
标签:女生,int,095,寝室,female,L1,男生
From: https://www.cnblogs.com/chengyiyuki/p/18109966