Sicily 1710. Painted Calculator

来源:互联网 发布:服务器远程端口号查询 编辑:程序博客网 时间:2024/06/07 18:29

1710. Painted Calculator

Constraints

Time Limit: 5 secs, Memory Limit: 32 MB

Description

Patrick has a four function calculator; unfortunately his sister has decided to be a traditional `evil sibling' and has painted over the display. The calculator still functions, but of course you can't see the results. This calculator has a display constructed from seven-segment LEDs. The figure on the left below illustrates how the seven LED segments at each digit position are arranged. The figure on the right shows which segments are illuminated to display each of the ten decimal digits.

 

This particular calculator only displays three digits of accuracy. There are three seven segment digits, and there are no decimal points since all math is performed using integers (with truncation where appropriate).

If the number on the display happens to be negative, there is a minus sign in front of the number. For a number such as -6, this is done by making the rightmost digit a `6' and using the middle segment of the next digit over as the minus sign. For a number such as -123, there is one additional segment to the left of the display. Thus, the number -112 lights up 10 segments, made up of 9 for the number, and one more for the minus sign. The display thus ranges from `-999' to `999'. There is no `plus sign' for positive numbers.

In order to prove that the calculator still operates, and justify scraping off the paint, the back cover is removed and an ammeter is attached to the display. An ammeter measures the current consumed by the device, and each segment of a digit consumes 5 milliamps. Thus, to display a number such as `798' the current consumption can be predicted as follows:

 


Digit 7 -- 3 segments lit = 15 milliamps 
Digit 9 -- 6 segments lit = 30 milliamps 
Digit 8 -- 7 segments lit = 35 milliamps 
Total = 80 milliamps

 


Of course, it's apparent that the number `897' also consumes the same amount of current, as does `789' or, for that matter, `-891'.

The calculator allows you to enter numbers with an optional minus sign and up to three digits, and to either add, subtract, multiply, or divide the numbers. Patrick wishes to prove that the functionality of the calculator is intact, so he enters `949' and measures 80 milliamps. Then he pushes the subtract key. Next he enters `51' and measures 35 milliamps. After pressing the `=' key the result should be `898', measuring 100 milliamps. As a second example, he enters `-5', then pushes the addition key. He then enters `-4' and presses equal. The answer is `-9'; the measurements were 30 milliamps, 25 milliamps, and 35 milliamps respectively.

Patrick's sister claims that this is a trick, so she presents him with the following problem: given the current consumption (in milliamps) of operand X, operand Y, and result Z, and given an unknown operation Op, determine the number of possible values for X Op Y = Z, assuming that possible solutions exist.

Note that in all cases, there are only three digits on the display. Although the input values of 80, 35, and 100 potentially could represent 12337 = 949*13 , this is not possible because 12337 is too large for the three digit display to hold.

 


Example

An example is as shown above; for inputs 80, 35, and 100 one possibility is ` 925 - 117 = 808 '. Some input combinations may have no result. For the inputs 35, 10, and 10 the answer is `No solutions.' For any given input set, the program should the number of solutions found.

Input

There will be multiple cases. Each input line except the last contains three integer values between 0 and 999,inclusive, each separated by a space, which are the X, Y, and Z values for a single case. Each number is in milliamps according to the above description. The last line will contain the single value 0, indicating the end of the problem set.

Output

Note that no leading zeros should be considered – the number “12” for example, is never entered on the alculator as “012” even though the result of the calculation may be the same. Thus, no expression should contain numbers with leading zeros, either as input or as result. For each case, find all possible expressions and report how many there are in a grammatically correct form, as shown below, as well as echoing back the input.

Sample Input

10 10 510 20 3010 30 2030 65 6030 65 6530 95 9535 35 1100

Sample Output

0 solutions for 10 10 54 solutions for 10 20 301 solution for 10 30 20516 solutions for 30 65 60819 solutions for 30 65 65304 solutions for 30 95 95

2 solutions for 35 35 110

// Problem#: 1710// Submission#: 3323802// The source code is licensed under Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License// URI: http://creativecommons.org/licenses/by-nc-sa/3.0/// All Copyright reserved by Informatic Lab of Sun Yat-sen University#include <algorithm>#include <iostream>#include <string>#include <stdio.h>#include <queue>#include <string.h>#include <vector>#include <iomanip>#include <map>#include <stack>#include <functional>#include <list>#include <cmath>using namespace std;int ans[25][25][25];int cost[10] = {6, 2, 5, 5, 4, 5, 6, 3, 7, 6};inline int getCost(int n) {    if (n == 0) return 6;    int r = 0;    if (n < 0) {        r = 1;        n = -n;    }    while (n) {        r += cost[n % 10];        n /= 10;    }    return r;}void init() {    int a, b, c;    for (int i = -999; i < 1000; i++) {        a = getCost(i);        for (int j = -999; j < 1000; j++) {            b = getCost(j);            c = i + j;            if (-999 <= c && c <= 999) ans[a][b][getCost(c)]++;            c = i - j;            if (-999 <= c && c <= 999) ans[a][b][getCost(c)]++;            c = i * j;            if (-999 <= c && c <= 999) ans[a][b][getCost(c)]++;            if (j == 0) continue;            c = i / j;            if (-999 <= c && c <= 999) ans[a][b][getCost(c)]++;        }    }}int main() {    std::ios::sync_with_stdio(false);    init();    while (1) {        int a, b, c;        cin >> a;        if (a == 0) break;        cin >> b >> c;        if (a > 110 || b > 110 || c > 110) cout << "0 solutions for " << a << " " << b << " " << c << endl;        else if (ans[a / 5][b / 5][c / 5] == 1) cout << "1 solution for " << a << " " << b << " " << c << endl;        else cout << ans[a / 5][b / 5][c / 5] << " solutions for " << a << " " << b << " " << c << endl;    }    //getchar();    //getchar();        return 0;}                                 


0 0
原创粉丝点击