B - Lever
来源:互联网 发布:韶关网络布线方案 编辑:程序博客网 时间:2024/06/06 17:04
Description
You have a description of a lever as string s. We'll represent the string length as record |s|, then the lever looks as a horizontal bar with weights of length |s| - 1 with exactly one pivot. We will assume that the bar is a segment on the Ox axis between points 0 and |s| - 1.
The decoding of the lever description is given below.
- If the i-th character of the string equals "^", that means that at coordinate i there is the pivot under the bar.
- If the i-th character of the string equals "=", that means that at coordinate i there is nothing lying on the bar.
- If the i-th character of the string equals digit c (1-9), that means that at coordinate i there is a weight of mass c on the bar.
Your task is, given the lever description, print if it will be in balance or not. Assume that the bar doesn't weight anything. Assume that the bar initially is in balance then all weights are simultaneously put on it. After that the bar either tilts to the left, or tilts to the right, or is in balance.
Input
The first line contains the lever description as a non-empty string s(3 ≤ |s| ≤ 106), consisting of digits (1-9) and characters "^" and "=". It is guaranteed that the line contains exactly one character "^". It is guaranteed that the pivot of the lever isn't located in any end of the lever bar.
To solve the problem you may need 64-bit integer numbers. Please, do not forget to use them in your programs.
Output
Print "left" if the given lever tilts to the left, "right" if it tilts to the right and "balance", if it is in balance.
Sample Input
=^==
balance
9===^==1
left
2==^7==
right
41^52==
balance
分析:这道题看懂以后就是一道物理题,杠杆原理,相比大家都还记得把,力臂*力矩的问题,很明显,如果哪边重了就肯定要倾斜。下面给出这道题的代码。
参考代码如下:
#include<iostream>#include<cstdio>#include<cmath>using namespace std;int main(){char s[1000008];int i, j, L1 = 1, L2 = 1;long long a1 = 0, a2 = 0;scanf("%s", s);for(i=0;s[i]!='\n';i++){if(s[i]=='^'){break;}}j = i;for(i=j-1;i>=0;i--){if(s[i]!='='){a1+=(s[i]-48)*L1;}L1++;}for (i=j+1;s[i]!='\0';i++){if(s[i]!='='){a2+=(s[i]-48)*L2;}L2++;}if (a1>a2){printf("left\n");}else if (a1<a2){printf("right\n");}else{printf("balance\n");}return 0;}
- B - Lever
- Lever
- A. Lever
- codeforces--12.24--A. Lever
- JDE报表-lever break
- CF 221div2 A. Lever
- Codeforces Round #221 (Div. 2) A. Lever
- 四级时间管理(Four Lever Time Manage)
- Performance Comparison Studies With Real-Life Scenarios in an Experimental Data Taking Context Lever
- b
- b
- b
- //b
- B
- b
- B
- B
- B
- 《高效学习OpenGL》之 其他裁剪平面 glClipPlane()
- 孩子羽球巨大的进步
- 寒假训练--字典树--B - Compound Words
- Google首席软件工程师Joshua Bloch谈如何设计一款优秀的API
- Oracle中dual表的用途介绍
- B - Lever
- 什么是程序员的优秀品质?
- TexturePacker 制作NGUI Atla
- 国内从事计算机视觉(CV)领域的公司
- 调用CreateProcess()之后,如何等待子进程初始化完毕。
- JVM 内存结构
- 浙江大学ACM俱乐部——1023坑爹的黑店
- [生化危机5]的图形渲染讲解
- Android surfaceview详解