数-----天平 (UVa839)递归

本文探讨了一种使用递归算法解决平衡条件问题的方法。通过输入两个重量和对应的距离,程序判断是否满足平衡条件,即左侧重量乘以距离等于右侧重量乘以距离。此算法在工程力学和物理学科中具有广泛应用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

//#include <bits/stdc++.h>
#include <iostream>
#include <stdio.h>
#include <string>
#include <map>
#include <set>
#include <sstream>
#include <vector>
#include <algorithm>
#include <cstring>
#include <queue>
#include <iomanip>
#include <cmath>
using namespace std;

const int maxv = 10000 + 10;

bool solve(int& w)
{
	int  w1, d1, w2, d2;
	bool b1 = true, b2 = true;
	cin >> w1 >> d1 >> w2 >> d2;
	if(!w1) b1 = solve(w1);
	if(!w2) b2 = solve(w2);
	w = w1 + w2;
	return b1 && b2 && (w1 * d1 == w2 * d2);
} 

int main() 
{
	int t,W;
	cin>>t;
	while(t--)
	{
		if(solve(W))
			cout<<"Yes\n";
		else
			cout<<"No\n";
		if(t)
			cout<<"\n";
	}
	return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值