HDU Problem - 5938 Four Operations
題目鏈接
Problem Description
Little Ruins is a studious boy, recently he learned the four operations!Now he want to use four operations to generate a number, he takes a string which only contains digits ‘1’ - ‘9’, and split it into 55 intervals and add the four operations ‘+’, ‘-‘, ‘*’ and ‘/’ in order, then calculate the result(/ used as integer division).Now please help him to get the largest result.
Input
First line contains an integer TT, which indicates the number of test cases.Every test contains one line with a string only contains digits ‘1’-‘9’.Limits1≤T≤1051≤T≤1055≤length of string≤205≤length of string≤20
Output
For every test case, you should output ‘Case #x: y’, where x indicates the case number and counts from 1 and y is the result.
Sample Input
112345Sample Output
Case #1: 1AC
- 因為固定順序,所以只有一種形式:A + B - C * D / E,貪心使得(A+ B)越大,(C* D / E)越小,結果的大小關鍵在于(A + B),所以C、D、E都只占一位數最好,但是有可能出現類似9 * 9 / 1的情況,所以比較兩種方法,一個是C、D、E分別占一位數,一個是C、D都分別占一位數,E占兩位
總結
以上是生活随笔為你收集整理的HDU Problem - 5938 Four Operations的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: HDU Problem - 6214 S
- 下一篇: 牛客练习赛25 因数个数和