UVA 839 (13.08.20)

本文探讨了如何通过递归算法解决平衡复杂天平的问题,包括处理嵌套天平的平衡计算,涉及数学原理和编程实现。


Not so Mobile

Before being an ubiquous communications gadget, a mobile wasjust a structure made of strings and wires suspending colourfullthings. This kind of mobile is usually found hanging over cradlesof small babies.

\epsfbox{p839a.eps}

The figure illustrates a simple mobile. It is just a wire,suspended by a string, with an object on each side. It can also beseen as a kind of lever with the fulcrum on the point where thestring ties the wire. From the lever principle we know that tobalance a simple mobile the product of the weight of the objectsby their distance to the fulcrum must be equal. That isWl×Dl = Wr×Drwhere Dl is the left distance, Dr is theright distance, Wl is the left weight and Wris the right weight.


In a more complex mobile the object may be replaced by asub-mobile, as shown in the next figure. In this case it is not sostraightforward to check if the mobile is balanced so we need youto write a program that, given a description of a mobile as input,checks whether the mobile is in equilibrium or not.

\epsfbox{p839b.eps}

Input

The input begins with a single positive integer on a line by itself indicatingthe number of the cases following, each of them as described below.This line is followed by a blank line, and there is also a blank line betweentwo consecutive inputs.


The input is composed of several lines, each containing 4 integersseparated by a single space. The 4 integers represent thedistances of each object to the fulcrum and their weights, in theformat: WlDlWrDr

If Wl or Wr is zero then there is a sub-mobile hanging fromthat end and the following lines define the the sub-mobile. Inthis case we compute the weight of the sub-mobile as the sum ofweights of all its objects, disregarding the weight of the wiresand strings. If both Wl and Wr are zero then the followinglines define two sub-mobiles: first the left then the right one.

Output

For each test case, the output must follow the description below.The outputs of two consecutive cases will be separated by a blank line.


Write `YES' if the mobile is in equilibrium, write `NO' otherwise.

Sample Input

1

0 2 0 4
0 3 0 1
1 1 1 1
2 4 4 2
1 6 3 2

Sample Output

YES

题意:

输入数据,描绘了一个天平,要求天平要平衡,其中有嵌套进去的天平,也要求不能倾斜~

然后平衡的公式应该都知道吧:w1 * d1 = w2 * d2;

思路:

递归不解释,数据出现0的时候就是递归的入口~


AC代码:

#include<stdio.h>

int flag;

int getW(int w) {
    int tw1, td1, tw2, td2;
    int p1, p2;
    if(w == 0) {
        scanf("%d %d %d %d", &tw1, &td1, &tw2, &td2);
        p1 = getW(tw1) * td1;
        p2 = getW(tw2) * td2;
        if(p1 == p2)
            return (p1/td1 + p2/td2);
        else {
            flag = 0;
            return -1;
        }
    }
    else
        return w;
}

int main() {
    int T;
    scanf("%d", &T);
    while(T--) {
        int w1, d1, w2, d2;
        int p1, p2;
        flag = 1;
        scanf("%d %d %d %d", &w1, &d1, &w2, &d2);
        p1 = getW(w1) * d1;
        p2 = getW(w2) * d2;
        if(p1 == p2 && flag == 1) {
            printf("YES\n");
            if(T)
                printf("\n");
        }
        else {
            printf("NO\n");
            if(T)
                printf("\n");
        }
    }
    return 0;
}

基于数据驱动的 Koopman 算子的递归神经网络模型线性化,用于纳米定位系统的预测控制研究(Matlab代码实现)内容概要:本文围绕“基于数据驱动的Koopman算子的递归神经网络模型线性化”展开,旨在研究纳米定位系统的预测控制问题,并提供完整的Matlab代码实现。文章结合数据驱动方法与Koopman算子理论,利用递归神经网络(RNN)对非线性系统进行建模与线性化处理,从而提升纳米级定位系统的精度与动态响应性能。该方法通过提取系统隐含动态特征,构建近似线性模型,便于后续模型预测控制(MPC)的设计与优化,适用于高精度自动化控制场景。文中还展示了相关实验验证与仿真结果,证明了该方法的有效性和先进性。; 适合人群:具备一定控制理论基础和Matlab编程能力,从事精密控制、智能制造、自动化或相关领域研究的研究生、科研人员及工程技术人员。; 使用场景及目标:①应用于纳米级精密定位系统(如原子力显微镜、半导体制造设备)中的高性能控制设计;②为非线性系统建模与线性化提供一种结合深度学习与现代控制理论的新思路;③帮助读者掌握Koopman算子、RNN建模与模型预测控制的综合应用。; 阅读建议:建议读者结合提供的Matlab代码逐段理解算法实现流程,重点关注数据预处理、RNN结构设计、Koopman观测矩阵构建及MPC控制器集成等关键环节,并可通过更换实际系统数据进行迁移验证,深化对方法泛化能力的理解。
将下边这个图标改为渐变色 <i data-v-3f2ed6ed="" class="ihelp_entrance_icon svgIcon"> <svg height="16" fill="none" viewBox="0 0 21 20.9197" xmlns="http://www.w3.org/2000/svg" width="16"> <desc>Created with Pixso.</desc> <defs></defs> <path id="path" d="M17.25 17.91L3.75 17.91C1.66 17.91 0 16.23 0 14.16L0 8.16C0 6.09 1.66 4.41 3.75 4.41L17.25 4.41C19.32 4.41 21 6.09 21 8.16L21 14.16C21 16.23 19.32 17.91 17.25 17.91ZM3.75 5.91C2.49 5.91 1.5 6.92 1.5 8.16L1.5 14.16C1.5 15.41 2.49 16.41 3.75 16.41L17.25 16.41C18.49 16.41 19.5 15.41 19.5 14.16L19.5 8.16C19.5 6.92 18.49 5.91 17.25 5.91L3.75 5.91ZM4.45 0.02C4.87 -0.09 5.28 0.15 5.38 0.54L6.55 4.89C6.66 5.3 6.41 5.7 6.03 5.81C5.62 5.91 5.2 5.67 5.09 5.28L3.94 0.93C3.83 0.53 4.06 0.12 4.45 0.02ZM16.53 0.02C16.12 -0.09 15.71 0.15 15.61 0.54L14.44 4.89C14.33 5.3 14.58 5.7 14.96 5.81C15.37 5.91 15.78 5.67 15.88 5.28L17.05 0.93C17.16 0.53 16.91 0.12 16.53 0.02ZM3.75 19.41L17.25 19.41C17.66 19.41 18 19.74 18 20.16C18 20.58 17.66 20.91 17.25 20.91L3.75 20.91C3.31 20.91 3 20.58 3 20.16C3 19.74 3.31 19.41 3.75 19.41ZM3.75 4.41L17.25 4.41C17.66 4.41 18 4.74 18 5.16C18 5.58 17.66 5.91 17.25 5.91L3.75 5.91C3.31 5.91 3 5.58 3 5.16C3 4.74 3.31 4.41 3.75 4.41ZM6.75 8.91C7.16 8.91 7.5 9.24 7.5 9.66L7.5 12.66C7.5 13.08 7.16 13.41 6.75 13.41C6.31 13.41 6 13.08 6 12.66L6 9.66C6 9.24 6.31 8.91 6.75 8.91ZM14.25 8.91C14.66 8.91 15 9.24 15 9.66L15 12.66C15 13.08 14.66 13.41 14.25 13.41C13.83 13.41 13.5 13.08 13.5 12.66L13.5 9.66C13.5 9.24 13.83 8.91 14.25 8.91Z" fill="#fff" fill-opacity="1.000000" fill-rule="nonzero"></path> </svg> </i>
08-05
要将你提供的 SVG 图标中的线条或形状颜色改为渐变色,可以使用 `<linearGradient>` 或 `<radialGradient>` 定义渐变色,并将其作为 `fill` 或 `stroke` 属性应用到 `<path>` 元素上。 以下是将该图标改为蓝紫渐变色的完整修改示例: ```xml <i class="ihelp_entrance_icon svgIcon"> <svg height="16" fill="none" viewBox="0 0 21 20.9197" xmlns="http://www.w3.org/2000/svg" width="16"> <desc>Created with Pixso.</desc> <defs> <!-- 定义蓝紫渐变 --> <linearGradient id="bluePurpleGradient" x1="0%" y1="0%" x2="100%" y2="0%"> <stop offset="0%" stop-color="blue" /> <stop offset="100%" stop-color="purple" /> </linearGradient> </defs> <!-- 应用渐变到 fill 或 stroke --> <path id="path" d="M17.25 17.91L3.75 17.91C1.66 17.91 0 16.23 0 14.16L0 8.16C0 6.09 1.66 4.41 3.75 4.41L17.25 4.41C19.32 4.41 21 6.09 21 8.16L21 14.16C21 16.23 19.32 17.91 17.25 17.91ZM3.75 5.91C2.49 5.91 1.5 6.92 1.5 8.16L1.5 14.16C1.5 15.41 2.49 16.41 3.75 16.41L17.25 16.41C18.49 16.41 19.5 15.41 19.5 14.16L19.5 8.16C19.5 6.92 18.49 5.91 17.25 5.91L3.75 5.91ZM4.45 0.02C4.87 -0.09 5.28 0.15 5.38 0.54L6.55 4.89C6.66 5.3 6.41 5.7 6.03 5.81C5.62 5.91 5.2 5.67 5.09 5.28L3.94 0.93C3.83 0.53 4.06 0.12 4.45 0.02ZM16.53 0.02C16.12 -0.09 15.71 0.15 15.61 0.54L14.44 4.89C14.33 5.3 14.58 5.7 14.96 5.81C15.37 5.91 15.78 5.67 15.88 5.28L17.05 0.93C17.16 0.53 16.91 0.12 16.53 0.02ZM3.75 19.41L17.25 19.41C17.66 19.41 18 19.74 18 20.16C18 20.58 17.66 20.91 17.25 20.91L3.75 20.91C3.31 20.91 3 20.58 3 20.16C3 19.74 3.31 19.41 3.75 19.41ZM3.75 4.41L17.25 4.41C17.66 4.41 18 4.74 18 5.16C18 5.58 17.66 5.91 17.25 5.91L3.75 5.91C3.31 5.91 3 5.58 3 5.16C3 4.74 3.31 4.41 3.75 4.41ZM6.75 8.91C7.16 8.91 7.5 9.24 7.5 9.66L7.5 12.66C7.5 13.08 7.16 13.41 6.75 13.41C6.31 13.41 6 13.08 6 12.66L6 9.66C6 9.24 6.31 8.91 6.75 8.91ZM14.25 8.91C14.66 8.91 15 9.24 15 9.66L15 12.66C15 13.08 14.66 13.41 14.25 13.41C13.83 13.41 13.5 13.08 13.5 12.66L13.5 9.66C13.5 9.24 13.83 8.91 14.25 8.91Z" fill="url(#bluePurpleGradient)" /> </svg> </i> ``` ### 修改说明: - 在 `<defs>` 中定义了一个名为 `bluePurpleGradient` 的线性渐变。 - 将原本的 `fill="#fff"` 替换为 `fill="url(#bluePurpleGradient)"`,将渐变应用到图标的填充颜色上。 - 你可以根据需要调整渐变的方向(通过 `x1`, `y1`, `x2`, `y2`)或颜色(通过 `stop-color`)。 ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值