G - Not so Mobile

Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu

 
 

Description

Before being an ubiquous communications gadget, a mobile was just a structure made of strings and wires suspending colourfull things. This kind of mobile is usually found hanging over cradles of small babies.

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

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

Input

The
input begins with a single positive integer on a line by itself
indicating the 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 between two consecutive inputs.

The input is composed of several lines, each containing 4 integers
separated by a single space. The 4 integers represent the distances of
each object to the fulcrum and their weights, in the format:
Wl Dl Wr Dr

If Wl or Wr
is zero then there is a sub-mobile hanging from that end and the
following lines define the the sub-mobile. In this case we compute the
weight of the sub-mobile as the sum of weights of all its objects,
disregarding the weight of the wires and strings. If both Wl and Wr are zero then the following lines 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

一道巧妙使用引用巧妙解答的题目。有点小思维难度。是一道不错的题目。

 #include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <list>
#include <iomanip>
#include <cstdlib>
#include <sstream>
using namespace std;
const int INF=0x5fffffff;
const double EXP=1e-;
const int mod=;
const int MS=; 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 ;
}

G - Not so Mobile的更多相关文章

  1. [转]An introduction to OAuth 2.0 using Facebook in ASP.NET Core

    本文转自:http://andrewlock.net/an-introduction-to-oauth-2-using-facebook-in-asp-net-core/ This is the ne ...

  2. SQL函数

    1,字符串截取拼接 CONCAT(),'****');SUBSTRING_INDEX(c.context,'}',1);SUBSTRING_INDEX(a.task_context,':',-1) a ...

  3. NEERC 2010, Eastern subregional contest

    只能把补了的题目放这儿了,先留个坑,怕忘记. Problem G URAL 1806 Mobile Telegraphs 题意是:给定n个电话号码,每个号码是一个长度为10的仅含'0'~'9'的字符串 ...

  4. windows下nginx的安装及使用方法入门

    nginx功能之一可以启动一个本地服务器,通过配置server_name和root目录等来访问目标文件 一. 下载 http://nginx.org/   下载后解压   二. 修改配置文件 ngin ...

  5. Edge Intelligence: On-Demand Deep Learning Model Co-Inference with Device-Edge Synergy

    边缘智能:按需深度学习模型和设备边缘协同的共同推理 本文为SIGCOMM 2018 Workshop (Mobile Edge Communications, MECOMM)论文. 笔者翻译了该论文. ...

  6. react-native获取设备信息组件(react-native-device-info)

    转载链接:http://www.ncloud.hk/%E6%8A%80%E6%9C%AF%E5%88%86%E4%BA%AB/react-native-acquisition-device-infor ...

  7. Nginx安装及配置详解包括windows环境

    nginx概述 nginx是一款自由的.开源的.高性能的HTTP服务器和反向代理服务器:同时也是一个IMAP.POP3.SMTP代理服务器:nginx可以作为一个HTTP服务器进行网站的发布处理,另外 ...

  8. SQL SERVER解析Json

    外包的项目,有很多信息存储在JSON中,无论是查询还是修改信息都十分麻烦.找了一些实用的SQL Function去解析,并附修改例子. 使用过程: 1. 需要在SQL新建自定义类型 table: Hi ...

  9. group by 并且 count(1)的linq写法

    SELECT [MobleNo],count(1) FROM [CustMobleNo] group by [MobleNo] GO ===作用等于=== var rst = from c in da ...

随机推荐

  1. 转】Mahout分步式程序开发 聚类Kmeans

    原博文出自于: http://blog.fens.me/hadoop-mahout-kmeans/ 感谢! Mahout分步式程序开发 聚类Kmeans Hadoop家族系列文章,主要介绍Hadoop ...

  2. 转】启动tomcat时 错误: 代理抛出异常 : java.rmi.server.ExportException: Port already in use: 1099的解决办法

    原博文出自于:http://www.cnblogs.com/xdp-gacl/p/5288399.html   感谢! 一.问题描述 今天一来公司,在IntelliJ IDEA 中启动Tomcat服务 ...

  3. JVM系列四:生产环境参数实例及分析【生产环境实例增加中】

    java application项目(非web项目) 改进前: -Xms128m-Xmx128m-XX:NewSize=64m-XX:PermSize=64m-XX:+UseConcMarkSweep ...

  4. HDU 5839 Special Tetrahedron (2016CCPC网络赛08) (暴力+剪枝)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5839 在一个三维坐标,给你n个点,问你有多少个四面体(4个点,6条边) 且满足至少四边相等 其余两边不 ...

  5. HDU 1394Minimum Inversion Number(线段树)

    题目大意是说给你一个数组(N个),没戏可以将其首部的k(k<N)个元素移动至尾部,这样总共会形成N个序列 现在要求这n个序列中逆序对数最少的那一个序列有多少个逆序对 最初的确是没太多思路,就算知 ...

  6. 实现jsp网站添加到收藏夹

    var ctrl = (navigator.userAgent.toLowerCase()).indexOf('mac') != -1 ? 'Command/Cmd': 'CTRL';         ...

  7. Plan04.学习与提升

    虽然工作没有继续做自己最喜欢的Android的开发,对于自己来说,从事J2EE又是一种挑战,自己 可以学习更多的东西,开阔自己的眼界,而不是局限在Android的应用开发领域. 工作这段时间,自己学到 ...

  8. Linux编译安装RTL8192CU芯片驱动,使用TP_LINK wn823n无线网卡

    前几天给自己的台式电脑安装了Window 7+CentOS 6.4 Linux双系统,发现在Windows 7下面可以正常使用TP_LINK wn823n无线网卡来连接无线网络,但是在Linux下面, ...

  9. Unity3d:播放物理目录下的MP3文件

    u3d里,是支持播放MP3文件的,但要放到资源里,不支持播放物理目录下的MP3文件.由于界面上无需显示,只是当作背景音乐来播放,所以想到调用c#的组件来解决此问题.主要代码都在附件中,根据需要加到自己 ...

  10. installshield Basic 工程每次安装完提示重启电脑

     将Sequence中的ScheduleReboot Action的Condition清空即可.