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 ...
随机推荐
- MyEclipse 代码自动提示
默认 myeclipse,输入.才会出现代码提示,不能根据单词前缀提示. 按以下设置就很爽了 .abcdefghijklmnopqrstuvwxyz(,
- [翻译]创建ASP.NET WebApi RESTful 服务(10)
通过URI实现版本管理 另一种实现版本管理的方式就是通过URI来进行处理,类似于http://localhost:{your_port}/api/v1/students/.这种方式的好处是使用者可以清 ...
- Linux下的crontab定时执行任务命令详解
在LINUX中,周期执行的任务一般由cron这个守护进程来处理[ps -ef|grep cron].cron读取一个或多个配置文件,这些配置文件中包含了命令行及其调用时间.cron的配置文件称为“cr ...
- vim之pydiction插件
[vim之pydiction插件] It consists of three main files: python_pydiction.vim -- Vim plugin. complete-dict ...
- Win7系统下利用U盘安装Ubuntu14.04麒麟版
转自http://www.360doc.cn/article/14743053_335473181.html 重要提示:在采用u盘安装ubuntu分区时,所有磁盘一定要全部设置成逻辑分区,包括根目录/ ...
- 查找DOM
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- chrome 41 空格
chrome 41对半角空格的解析 当做一个汉字宽度来处理了. 导致很多网站出现异常. 目前能想到的方法是删掉用来规范格式的空格. 老版chrome chrome41 和讯网也有这种问题 有更好的处理 ...
- Ext_两种处理服务器端返回值的方式
1.Form表单提交返回值处理 //提交基本信息表单 f.form.submit({ clientValidation:true, //表单提交后台处理地址 url:' ...
- undefined index : HTTP_RAW_POST_DATA
国内私募机构九鼎控股打造APP,来就送 20元现金领取地址:http://jdb.jiudingcapital.com/phone.html 内部邀请码:C8E245J (不写邀请码,没有现金送) 国 ...
- Beyond Compare3 添加到右键菜单
Beyond Compare 是个优秀的工具,我们经常用于对比文件和文件夹,右键点点就可以调用对比,着实很方便.但从3.2版本之前,我们可以从设置中将bc关联到文件夹和文件右键,但之后的版本已经找不到 ...