当前位置:网站首页>[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 .
边栏推荐
- Learning record: USART serial communication
- Printing quality inspection and verification system Industry Research Report - market status analysis and development prospect forecast
- Research Report on market supply and demand and strategy of geosynthetics industry in China
- Research Report on surgical fluid treatment industry - market status analysis and development prospect prediction
- 7-1 懂的都懂 (20 分)
- 想应聘程序员,您的简历就该这样写【精华总结】
- 信息安全-安全专业名称|CVE|RCE|POC|VUL|0DAY
- Report on the market trend, technological innovation and market forecast of printing and decorative paper in China
- Cost accounting [23]
- Alice and Bob (2021牛客暑期多校训练营1)
猜你喜欢
Gartner: five suggestions on best practices for zero trust network access
基于web的照片数码冲印网站
TCP的三次握手与四次挥手
C语言必背代码大全
渗透测试 ( 8 ) --- Burp Suite Pro 官方文档
信息安全-安全编排自动化与响应 (SOAR) 技术解析
Information security - Epic vulnerability log4j vulnerability mechanism and preventive measures
Optimization method of path problem before dynamic planning
Penetration testing (5) -- a collection of practical skills of scanning King nmap and penetration testing tools
Information security - threat detection engine - common rule engine base performance comparison
随机推荐
C语言必背代码大全
信息安全-安全编排自动化与响应 (SOAR) 技术解析
Optimization method of path problem before dynamic planning
Accounting regulations and professional ethics [4]
B - 代码派对(女生赛)
【练习-10】 Unread Messages(未读消息)
通俗地理解什么是编程语言
China's earthwork tire market trend report, technical dynamic innovation and market forecast
渗透测试 ( 3 ) --- Metasploit Framework ( MSF )
渗透测试 ( 1 ) --- 必备 工具、导航
Research Report on market supply and demand and strategy of geosynthetics industry in China
Path problem before dynamic planning
Information security - security professional name | CVE | rce | POC | Vul | 0day
MySQL授予用户指定内容的操作权限
Learning record: STM32F103 clock system overview working principle
渗透测试 ( 4 ) --- Meterpreter 命令详解
Research Report on printed circuit board (PCB) connector industry - market status analysis and development prospect forecast
China earth moving machinery market trend report, technical dynamic innovation and market forecast
Cost accounting [24]
【练习-6】(PTA)分而治之