UVA839 - Not so Mobile

题意:距离*重量,要使整个天平各个节点左右相等

思路:利用递归,从最底层判断是否相等

#include<stdio.h>

int flag;

int dfs() {
	int wl, dl, wr, dr;
	scanf("%d %d %d %d", &wl, &dl, &wr, &dr);
	if (wl == 0)
		wl = dfs();
	if (wr == 0)
		wr = dfs();
	if (wl * dl == wr * dr) 
		return wl + wr;	
	else
		return flag = 0;	
}

int main() {
	int cas;
	scanf("%d", &cas);
	while (cas--) {
		flag = 1;
		dfs();	
		if (flag)	
			printf("YES\n");
		else
			printf("NO\n");
		if (cas)	
			printf("\n");	
	}
	return 0;
}



你可能感兴趣的:(UVA839 - Not so Mobile)