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的更多相关文章
- [转]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 ...
- SQL函数
1,字符串截取拼接 CONCAT(),'****');SUBSTRING_INDEX(c.context,'}',1);SUBSTRING_INDEX(a.task_context,':',-1) a ...
- NEERC 2010, Eastern subregional contest
只能把补了的题目放这儿了,先留个坑,怕忘记. Problem G URAL 1806 Mobile Telegraphs 题意是:给定n个电话号码,每个号码是一个长度为10的仅含'0'~'9'的字符串 ...
- windows下nginx的安装及使用方法入门
nginx功能之一可以启动一个本地服务器,通过配置server_name和root目录等来访问目标文件 一. 下载 http://nginx.org/ 下载后解压 二. 修改配置文件 ngin ...
- Edge Intelligence: On-Demand Deep Learning Model Co-Inference with Device-Edge Synergy
边缘智能:按需深度学习模型和设备边缘协同的共同推理 本文为SIGCOMM 2018 Workshop (Mobile Edge Communications, MECOMM)论文. 笔者翻译了该论文. ...
- 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 ...
- Nginx安装及配置详解包括windows环境
nginx概述 nginx是一款自由的.开源的.高性能的HTTP服务器和反向代理服务器:同时也是一个IMAP.POP3.SMTP代理服务器:nginx可以作为一个HTTP服务器进行网站的发布处理,另外 ...
- SQL SERVER解析Json
外包的项目,有很多信息存储在JSON中,无论是查询还是修改信息都十分麻烦.找了一些实用的SQL Function去解析,并附修改例子. 使用过程: 1. 需要在SQL新建自定义类型 table: Hi ...
- group by 并且 count(1)的linq写法
SELECT [MobleNo],count(1) FROM [CustMobleNo] group by [MobleNo] GO ===作用等于=== var rst = from c in da ...
随机推荐
- Java 类型信息
<Thinking in Java 4th>第14章 类型信息 运行时类型信息(Run-Time Type Identification)使得你可以在程序运行时发现和使用类型信息. 14. ...
- Spark RDD概念学习系列之RDD的创建(六)
RDD的创建 两种方式来创建RDD: 1)由一个已经存在的Scala集合创建 2)由外部存储系统的数据集创建,包括本地文件系统,还有所有Hadoop支持的数据集,比如HDFS.Cassandra.H ...
- C++ 16进制转10进制
#include <stdio.h>#include <string.h>unsigned long f(char* str){ unsigned long var=0; un ...
- vs2012 密匙
旗舰版 YKCW6-BPFPF-BT8C9-7DCTH-QXGWC
- OperateParticleWithCodes
[OperateParticleWithCodes] Listing 6-6 shows how you might configure an emitter’s scale property. Th ...
- vim插件开发初步
[vim插件开发初步] 将如下代码存在helloworld.vim, 放在~/.vim/plugin目录下,插件即可生效.:w保存代码后, 用:source命令执行后,也可以使用Helloworld命 ...
- HDU1963Investment(DP)
简单DP,题解见代码
- WSARecv()
简述:从一个套接口接收数据. #include <winsock2.h> int WSAAPI WSARecv ( SOCKET s, LPWSABUF lpBuffers, DWORD ...
- C++开发必看 四种强制类型转换的总结 [转]
一.C风格的强制类型转换(Type Cast)很简单,不管什么类型的转换统统是: TYPE b = (TYPE)a 二.C++风格的类型转换提供了4种类型转换操作符来应对不同场合的应用. co ...
- C++ 中 int,char*,string,CString之间相互转换-整理
<多字符集下> #include <string> //使用C++标准库的string类时, 定义时 std::string str; using namespace std; ...