6-9 天平 uva839

这题十分巧妙!!代码精简!强大的递归!!!

边读边判断   先读到底部  慢慢往上判断   难点在于传递w1+w2

有一个比LRJ更加简便的方法  return传递  全局变量判断

#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <cmath>

using namespace std;
int flag;


int dfs()
{
    int d1,w1,d2,w2;cin>>w1>>d1>>w2>>d2;
    if(!w1)w1=dfs();
    if(!w2)w2=dfs();
    if(w1*d1!=w2*d2)flag=0;


    return w1+w2;

}


int main()
{
    int n;cin>>n;
    while(n--)
    {
        flag=1;
        dfs();
        if(flag)printf("YES\n");else printf("NO\n");
        if(n)printf("\n");
    }

    return 0;
}
View Code

LRJ是return判断   引用来传递!  都很巧妙

猜你喜欢

转载自www.cnblogs.com/bxd123/p/10290064.html