题目链接:https://vjudge.net/problem/UVA-839
题解:仔细读懂题目之后,会发现,本题就是使用递归求解计算WL*DL==WR*DR,解题过程中,递归函数的引用参数非常有意思。以后可以借鉴。
代码:
#include<iostream>
using namespace std;
bool solve(int &w) {
int WL, DL, WR, DR;
cin >> WL >> DL >> WR >> DR;
bool b1 = 1, b2 = 1;
if (!WL)b1 = solve(WL);
if (!WR)b2 = solve(WR);
w = WL + WR;
return b1 && b2 && (WL*DL == WR * DR);
}
int main()
{
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
int T, W = 0;
cin >> T;
while (T--) {
W = 0;
if (solve(W))cout << "YES" << endl;
else cout << "NO" << endl;
if (T)cout << endl;
}
return 0;
}