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=; return w1+w2; } int main()
{
int n;cin>>n;
while(n--)
{
flag=;
dfs();
if(flag)printf("YES\n");else printf("NO\n");
if(n)printf("\n");
} return ;
}
LRJ是return判断 引用来传递! 都很巧妙
LRJ的方法:
#include<bits/stdc++.h>
using namespace std; bool judge(int &w)
{
bool b1=true ,b2=true;
int w1,d1,w2,d2;
cin>>w1>>d1>>w2>>d2;
if(!w1) b1=judge(w1);
if(!w2) b2=judge(w2);
w=w1+w2;
return b1&&b2&&(w1*d1==w2*d2);
} int main()
{ int cas;cin>>cas;
while(cas--)
{ int w=; if(judge(w))printf("YES\n");
else printf("NO\n"); if(cas) cout<<endl; } return ;
}
6-9 天平 uva839的更多相关文章
- 二叉树的递归遍历 天平UVa839
题意:输入一个树状的天平,利用杠杆原理,根据力矩是否相等(W1D1==W1D2)判断天平是否平衡 解题思路:1.由于判断天平是否平衡,当W1和W2都为0的时候,会先输入左子树,再输入右子树 2.此时的 ...
- 题解【UVA839】天平 Not so Mobile
Description Input Output Examples Input 1 0 2 0 4 0 3 0 1 1 1 1 1 2 4 4 2 1 6 3 2 Output YES Transla ...
- 6_9 天平(UVa839)<二叉树的DFS>
前一个ubiquous通信小工具,移动只是一个由弦和电线组成的结构五彩缤纷的东西.这种移动通常被发现悬挂在小婴儿的摇篮.图说明了一个简单的移动.它只是一个电线,悬挂的一个字符串,每一个对象的对象.它可 ...
- UVa839 Not so Mobile
我的解法: 建树,递归判断 #include<cstdio> #include<cstring> #include<iostream> #include< ...
- UVa 12166 修改天平
https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...
- BZOJ 1111: [POI2007]四进制的天平Wag
1111: [POI2007]四进制的天平Wag Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 223 Solved: 151[Submit][St ...
- UVa 1354 Mobile Computing | GOJ 1320 不加修饰的天平问题 (例题 7-7)
传送门1(UVa): https://uva.onlinejudge.org/external/13/1354.pdf 传送门2(GOJ): http://acm.gdufe.edu.cn/Probl ...
- bzoj:1673 [Usaco2005 Dec]Scales 天平
Description Farmer John has a balance for weighing the cows. He also has a set of N (1 <= N <= ...
- UVA-12166 天平性质+字符处理
这题思维难度很大,关键是总结这个性质. 1.天平性质:某个秤砣重量为w,高度为h,如果要让这个天平平衡并且以这个秤砣为基准,那么整个天平的总重量为w*(2^h) 2.利用这个性质:题目要求秤砣数量改变 ...
随机推荐
- Linux - sort 排序
-t # 指定排序时所用的栏位分隔字符 -n # 依照数值的大小排序 -r # 以相反的顺序来排序 -f # 排序时,将小写字母视为大写字母 -d # 排序时,处理英文字母.数字及空格字符外,忽略其他 ...
- python的安装和pycharm的安装
下载地址 官网:https://www.python.org/downloads/release/python-372/ Window 平台安装 Python: Add python xx to ...
- 第15月第22天 libz.dylib
1. 3.在弹出的对话框中输入"cmd"+"shift"+"g" 4 4.输入/usr/lib https://jingyan.baidu. ...
- How to scroll down with Phantomjs to load dynamic content
page.open('http://example.com/?q=houston', function () { // Checks for bottom div and scrolls down f ...
- WCF错误远程服务器返回了意外响应: (413) Request Entity Too Large。解决方案
这个问题出现的原因是 调用wcf服务的时候传递的参数 长度太大 wcf数据传输采用的默认的大小是65535字节. ---------------------------------------- ...
- HTML学习笔记07-头部
HTML <head> 元素 <head> 元素包含了所有的头部标签元素.在 <head>元素中你可以插入脚本(scripts), 样式文件(CSS),及各种met ...
- Windows10 中在指定目录下启动Powershell
(1)首先进入该目录: (2)按住shift键,且同时在该目录空白处鼠标右击,打开右键菜单: (3)此时可以发现,在右键菜单中,多了一项,叫做[在此处打开Powershell窗口(s)],点击该项: ...
- TCP/IP五层层次模型
TCP/IP层次模型共分为五层:应用层HTTP.传输层TCP.网络层IP.数据链路层Data-link.物理层physical.· 应用层-应用层是所有用户所面向的应用程序的统称.IC ...
- 随机森林学习-2-sklearn
# -*- coding: utf-8 -*- """ RandomForestClassifier skleran的9个模型在3份数据上的使用. 1. 知识点: skl ...
- html中子界面与父界面相互操作或传值
一.在使用iframe的页面,要操作这个iframe里面的DOM元素可以用: contentWindow.contentDocument(测试的时候chrom浏览器,要在服务器环境下) content ...