首页 > 其他 > 详细

6-9 天平 uva839

时间:2019-01-18 23:50:36      阅读:304      评论:0      收藏:0      [点我收藏+]

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

 

边读边判断   先读到底部  慢慢往上判断   难点在于传递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判断   引用来传递!  都很巧妙

6-9 天平 uva839

原文:https://www.cnblogs.com/bxd123/p/10290064.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!