UVA839——天平
来源:互联网 发布:淘宝空间图片协议在哪 编辑:程序博客网 时间:2024/05/24 04:24
描述:
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.
#include<cstdio>#include<cstring>#include<iostream>#include<algorithm>#include<cmath>#include<string>#include<vector>#include<queue>#include<stack>#include<set>#include<map>//#define file#define PI 3.1415926#define MAX(A,B) ((A)>(B)?(A):(B))#define ll long long#define fordo(A,B,C) for(int (A)=(B);(A)<=(C);(A)++)using namespace std;bool solve(int& W){ int W1,D1,W2,D2; bool b1=true; bool b2=true; cin>>W1>>D1>>W2>>D2; if(!W1)//这里很奇怪,当我用W1==0时VJ就会报WA,只有!W1这种表示法可以过,貌似这两者没区别吧…… b1=solve(W1);//当存在子天平,求解。 if(!W2) b2=solve(W2); W=W1+W2;//由子天平重量计算该天平重量 return b1&&b2&&(W1*D1==W2*D2); //递归求解:当该托盘的子天平都平衡,并且该天平平衡,则返回该天平平衡。}int main(){ #ifdef file freopen("test.in", "r", stdin); freopen("test.out", "w", stdout); #endif // file int T,W; cin>>T; while(T--) { if(solve(W)) cout<<"YES"<<endl; else cout<<"NO"<<endl; if(T) cout<<endl; } return 0;}
- UVA839——天平
- Uva839-天平
- UVa839-Not so Mobile (天平)
- Not so Mobile 天平 UVA839
- Uva839 Not so Mobile(天平)
- 【DFS】UVa839 天平(Not so Mobile)
- Uva839——Not so Mobile
- uva839
- uva839
- UVA839
- uva839
- uva839
- UVa839
- UVA839
- UVa839
- UVA839
- 蓝桥杯训练:爆搜——天平称重
- 天平
- 在IDEA中只用键盘快速选中某个单词
- Communication System dp 动态规划 || 贪心
- HDU 排序
- SGU 103 Traffic Lights(最短路)
- apache虚拟主机配置
- UVA839——天平
- QT将TableWidget 导出为excel的几种方法
- Linux下git通过proxy访问github
- Dubbo与Zookeeper、SpringMVC整合和使用(负载均衡、容错)
- js闭包相关的内容
- 使用Keil MDK以及标准外设库创建STM32工程
- oracle多行数据合并成一行
- Android Studio正式版签名的时候出现:Android xxx is not translated in zh
- EasyUI—点击tab内容中的链接,在父级tab上新增一个tab