天平

#include<cstdio> #include<iostream> #include<algorithm> using namespace std; bool solve(int &w) { int w1, w2, d1, d2; cin >> w1 >> d1 >> w2 >> d2; bool left = true, right = true; if(!w1)left = solve(w1);//一举两得,将w1和2用引用的方式传入下一个递归函数中,可以将w1和2的值改变,改为下一个地方两个称重量之和,如果子称想等的话就是true if(!w2)right = solve(w2); w = w1 + w2; return left && right && (w1 * d1 == w2 * d2); } int main(void) { int T,w; cin >> T; while (T--) { if (solve(w)) cout << "YES\n"; else cout << "NO\n"; if (T)cout << endl; } return 0; }
计算机小白记录学习过程,喜欢就点个推荐和关注吧O(∩_∩)O哈哈~

浙公网安备 33010602011771号