CF376A.Lever

普及/提高-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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.

你有一个表示杠杆的字符串 $ s $。我们将字符串的长度记为 ∣s∣|s|,那么该杠杆看起来就像一根长度为 ∣s∣−1|s| - 1 的水平杆,杆上恰好有一个支点。我们假设该杆是 OxOx 轴上介于点 00 和 ∣s∣−1|s| - 1 之间的一条线段。

杠杆描述的解码规则如下:

  • 若字符串中第 ii 个字符为 ^,则表示在坐标 ii 处杆下方存在一个支点;
  • 若字符串中第 ii 个字符为 =,则表示在坐标 ii 处杆上没有任何物体;
  • 若字符串中第 ii 个字符为数字 cc(11–99),则表示在坐标 ii 处杆上放置了一个质量为 cc 的重物。

你的任务是:给定杠杆的描述,判断它是否处于平衡状态。假设杆本身质量为零;假设杆初始处于平衡状态,然后所有重物被同时放置到杆上。此后,杆将向左倾斜、向右倾斜,或保持平衡。

输入格式

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.

第一行包含一个非空字符串 ss(3 ≤ ∣s∣ ≤ 1063 \le |s| \le 10^6),用于描述杠杆,该字符串由数字(1–9)以及字符 ^ 和 = 组成。保证该行中恰好包含一个字符 ^。还保证支点(即 ^ 所在位置)不位于杠杆的任一端点处。

求解本题可能需要使用 64 位整数。请务必在您的程序中使用 64 位整数类型。

输出格式

Print "left" if the given lever tilts to the left, "right" if it tilts to the right and "balance", if it is in balance.

如果给定的杠杆向左倾斜,则输出 "left";如果向右倾斜,则输出 "right";如果处于平衡状态,则输出 "balance"。

输入输出样例

  • 输入#1

    =^==

    输出#1

    balance
  • 输入#2

    9===^==1

    输出#2

    left
  • 输入#3

    2==^7==

    输出#3

    right
  • 输入#4

    41^52==

    输出#4

    balance

说明/提示

As you solve the problem, you may find the following link useful to better understand how a lever functions: http://en.wikipedia.org/wiki/Lever.

The pictures to the examples:

在解题过程中,以下链接可能有助于您更好地理解杠杆的工作原理:http://zh.wikipedia.org/wiki/杠杆。

示例配图:

输入解题思路,AI测评打分。不知道怎么写?

首页