https://vjudge.net/problem/UVA-839
题意:判断天平是否平衡
二叉树递归判断
#include<cstdio> using namespace std; bool judge(int &w) { int wl,dl,wr,dr; scanf("%d%d%d%d",&wl,&dl,&wr,&dr); bool l=true,r=true; if(!wl) l=judge(wl); if(!wr) r=judge(wr); w=wl+wr; return l && r && wl*dl==wr*dr; } int main() { int T,w; scanf("%d",&T); while(T--) { if(judge(w)) printf("YES "); else printf("NO "); if(T) puts(""); } }