UVA 839 Not so Mobile

#include <cstdio>

int judge() {
	int wl, dl, wr, dr;
	scanf("%d%d%d%d", &wl, &dl, &wr, &dr);
	if (wl == 0) //判断左边是否有子天平
		wl = judge();
	if (wr == 0) //判断右边是否有子天平
		wr = judge();
	if (wl == 0 || wr == 0) //假如左边或右边的重量为 0, 说明子天平不平衡, 返回 0,判断结束 
		return 0;
	return wl * dl == wr * dr ? wl + wr : 0; //假如天平平衡,则把天平的重量返回给上一级; 假如天平不平衡, 则返回 0;
}

int main() {
	int t;
	scanf("%d", &t);
	while (t--) {
		judge() ? printf("YES\n") : printf("NO\n");
		if (t) 
			printf("\n");
	}
	return 0;
}


你可能感兴趣的:(UVA 839 Not so Mobile)