当前位置:网站首页>[exercise-5] (UVA 839) not so mobile (balance)
[exercise-5] (UVA 839) not so mobile (balance)
2022-07-06 15:56:00 【Flame car】
Translate :
Enter a tree scale , Judge whether it is balanced according to the principle of equal moment . The so-called equal moment , Namely W1D1 = W2D2, among W1 and W2 Are the weights of the left and right weights ,D For distance .
Recursion ( Preface ) Mode input : The format of each balance is W1 D1 W2 D2, When W1 or W2 by 0 when , It means that we should “ Weights ” It's actually a balance , Next, I will describe the scale . When W1=W2=0 when , I will first describe the left balance , Then there is the right balance .
recursive .
AC Code :
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5+5;
const ll mod = 1e9+7;
int solve(int &w)
{
int w1,d1,w2,d2;
int x1=1,x2=1;
cin>>w1>>d1>>w2>>d2;
if(!w1) x1 = solve(w1);
if(!w2) x2 = solve(w2);
w = w1+w2;
return x1 && x2 && (w1 * d1 == w2 * d2);
}
int main()
{
int n,w;
cin>>n;
while(n--)
{
if(solve(w))
cout<<"YES"<<endl;
else
cout<<"NO"<<endl;
cout<<endl;
}
}
to x1 and x2 The assignment is 1 It's because on the last floor , He has no left-right balance , So the default is 1.
Because it is preordered recursion , So our input is first root, then left and then right . According to the introduction of the topic, you can also know , It must be a balanced binary tree .
At first, I thought I could not add w, It turned out ,w Must be added and participate in recursion , If not , Then only the bottom layer can complete the calculation 
Like in the picture above , Only 1 * 1 = 1 * 1 and 2 * 4 = 4 * 2 and 3* 2 = 6 * 1 It can be calculated if you don't add w Words .
After adding, the sum of the following two balls will be returned each time, so you can find out whether the two balances are balanced . And so on , Recursion completes .
边栏推荐
- China exterior wall cladding (EWC) market trend report, technical dynamic innovation and market forecast
- C语言是低级和高级的分水岭
- Determine the Photo Position
- Learning record: STM32F103 clock system overview working principle
- China chart recorder market trend report, technology dynamic innovation and market forecast
- 差分(一维,二维,三维) 蓝桥杯三体攻击
- E. Breaking the Wall
- Information security - security professional name | CVE | rce | POC | Vul | 0day
- 【高老师UML软件建模基础】20级云班课习题答案合集
- Opencv learning log 15 count the number of solder joints and output
猜你喜欢

程序员的你,有哪些炫技的代码写法?

Information security - Analysis of security orchestration automation and response (soar) technology

【高老师软件需求分析】20级云班课习题答案合集

STM32如何使用STLINK下载程序:点亮LED跑马灯(库版本)

【高老师UML软件建模基础】20级云班课习题答案合集

Information security - threat detection - Flink broadcast stream broadcaststate dual stream merging application in filtering security logs

渗透测试 ( 7 ) --- 漏洞扫描工具 Nessus

Penetration test (2) -- penetration test system, target, GoogleHacking, Kali tool

Penetration testing (5) -- a collection of practical skills of scanning King nmap and penetration testing tools

MATLAB综合练习:信号与系统中的应用
随机推荐
Cost accounting [13]
Shell脚本编程
China's salt water membrane market trend report, technological innovation and market forecast
Cost accounting [22]
STM32如何使用STLINK下载程序:点亮LED跑马灯(库版本)
Borg Maze (BFS+最小生成树)(解题报告)
Opencv learning log 33 Gaussian mean filtering
信息安全-威胁检测-flink广播流BroadcastState双流合并应用在过滤安全日志
Opencv learning log 30 -- histogram equalization
渗透测试 ( 1 ) --- 必备 工具、导航
【练习-2】(Uva 712) S-Trees (S树)
Penetration testing (5) -- a collection of practical skills of scanning King nmap and penetration testing tools
0-1背包問題(一)
Opencv learning log 16 paperclip count
Truck History
1010 things that college students majoring in it must do before graduation
Cost accounting [18]
Cost accounting [16]
CS zero foundation introductory learning record
动态规划前路径问题