在输入过程中同时进行数据处理,代码简洁,效率较高

#include<iostream>
#include<cstdio> using namespace std; 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"<<endl; else cout<<"NO"<<endl;
if(T) cout<<endl;
}
return 0;
}

[ACM]Uva839-Not So Mobile(树状天平)的更多相关文章

  1. UVa839 Not so Mobile

      我的解法: 建树,递归判断 #include<cstdio> #include<cstring> #include<iostream> #include< ...

  2. UVa 839 -- Not so Mobile(树的递归输入)

    UVa 839 Not so Mobile(树的递归输入) 判断一个树状天平是否平衡,每个测试样例每行4个数 wl,dl,wr,dr,当wl*dl=wr*dr时,视为这个天平平衡,当wl或wr等于0是 ...

  3. HDU 5458 Stability(双连通分量+LCA+并查集+树状数组)(2015 ACM/ICPC Asia Regional Shenyang Online)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5458 Problem Description Given an undirected connecte ...

  4. poj 1195:Mobile phones(二维树状数组,矩阵求和)

    Mobile phones Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 14489   Accepted: 6735 De ...

  5. POJ 1195 Mobile phones(二维树状数组)

                                                                  Mobile phones Time Limit: 5000MS   Mem ...

  6. 【POJ1195】【二维树状数组】Mobile phones

    Description Suppose that the fourth generation mobile phone base stations in the Tampere area operat ...

  7. (简单) POJ 1195 Mobile phones,二维树状数组。

    Description Suppose that the fourth generation mobile phone base stations in the Tampere area operat ...

  8. 2018牛客网暑假ACM多校训练赛(第五场)H subseq 树状数组

    原文链接https://www.cnblogs.com/zhouzhendong/p/NowCoder-2018-Summer-Round5-H.html 题目传送门 - https://www.no ...

  9. 2018牛客网暑假ACM多校训练赛(第五场)F take 树状数组,期望

    原文链接https://www.cnblogs.com/zhouzhendong/p/NowCoder-2018-Summer-Round5-F.html 题目传送门 - https://www.no ...

  10. 2018牛客网暑期ACM多校训练营(第五场) F - take - [数学期望][树状数组]

    题目链接:https://www.nowcoder.com/acm/contest/143/F 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 262144K,其他语言524288K ...

随机推荐

  1. 随机生成不重复的几个数(Unity)

    using System.Collections.Generic; using UnityEngine; /// <summary> /// 随机数管理类 /// </summary ...

  2. 项目实训DAY7

    今天与昨天一样,查论文,并美化了一下功能界面的样式.

  3. 使用commitizen规范提交

    npm install -g commitizen cz-conventional-changelog echo '{ "path": "cz-conventional- ...

  4. 设置mode='out-on'导致路由切换过快路由加载报错 Failed to execute 'insertBefore' on 'Node'

    原代码: 解决代码: 原因未知

  5. sqlserver substring 函数截取text格式文本格式乱码导致的定位错误的问题

    描述:使用 charindex 函数对 text 字段所要截取的内容下标读取例如:str(表字段名称-类型text)= <p>●123456</p> 截取 123 , inde ...

  6. Java jsp视频标签

    视频标签: 直接显示 <embed src="视频地址.mp4" width="60" height="40"> 按钮点击 &l ...

  7. 跨域请求 jQuery的ajax jsonp的使用

    <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> &l ...

  8. rust 条件编译 Debug Release

    #[cfg(debug_assertions)] macro_rules! debug { () => (std::println!()); ($($arg:tt)*) => ({ pri ...

  9. 关于安装Wind金融终端后,启动QT后频繁跳出WDF.dll文件注册成功窗口的问题

    安装Wind金融终端后,启动QT后频繁跳出WDF.dll文件注册成功窗口的信息. 经过排查后发现,主要问题出在系统环境变量上. 安装了wind金融终端后,用户系统环境变量PATH里多了两个wind相关 ...

  10. Linux 提示符后面显示全路径

    vi /root/.bashrc # .bashrc # User specific aliases and functions alias rm='rm -i' alias cp='cp -i' a ...