2 shunfurh shunfurh 于 2017.09.17 00:15 提问

Polly Nomials

The Avian Computation Mission of the International Ornithologists Union is dedicated to the study of intelligence in birds, and specifically the study of computational ability. One of the most promising projects so far is the "Polly Nomial" project on parrot intelligence, run by Dr. Albert B. Tross and his assistants, Clifford Swallow and Perry Keet. In the ACM, parrots are trained to carry out simple polynomial computations involving integers, variables, and simple arithmetic operators.
When shown a formula consisting of a polynomial with non-negative integer coefficients and one variable x, each parrot uses a special beak-operated PDA, or "Parrot Digital Assistant," to tap out a sequence of operations for computing the polynomial. The PDA operates much like a calculator. It has keys marked with the following symbols: the digits from 0 through 9, the symbol 'x', and the operators '+', '*', and '='. (The x key is internally associated with an integer constant by Al B. Tross for testing purposes, but the parrot sees only the 'x'.)

For instance, if the parrot were presented with the polynomial

x^3 + x + 11

the parrot might tap the following sequence of symbols:

x, *, x, *, x, +, x, +, 1, 1, =

The PDA has no extra memory, so each * or + operation is applied to the previous contents of the
display and whatever succeeding operand is entered. If the polynomial had been

x^3 + 2x^2 + 11

then the parrot would not have been able to "save" the value of x^3 while calculating the value of 2x^2. Instead, a different order of operations would be needed, for instance:

x, +, 2, *, x, *, x, +, 1, 1, =

The cost of a calculation is the number of key presses. The cost of computing x^3+x+11 in the example above is 11 (four presses of the x key, two presses of '*', two presses of '+', two presses of the digit '1', and the '=' key). It so happens that this is the minimal cost for this particular expression using the PDA.

You are to write a program that finds the least costly way for a parrot to compute a number of polynomial expressions. Because parrots are, after all, just bird-brains, they are intimidated by polynomials whose high-order coefficient is any value except 1, so this condition is always imposed.

Input

Input consists of a sequence of lines, each containing a polynomial and an x value. Each polynomial anx^n+an-1xn^-1+ . . . +a0 is represented by its degree followed by the non-negative coefficients an, . . ., a0 of decreasing powers of x, where an is always 1. Degrees are between 1 and 100. The coefficients are followed on the same line by an integer value for the variable x, which is always either 1 or -1. The input is terminated by a single line containing the values 0 0.

Output

For each polynomial, print the polynomial number followed by the value of the polynomial at the given integer value x and the minimum cost of computing the polynomial; imitate the formatting in the sample output.

Sample Input

3 1 0 1 11 1
3 1 0 2 11 -1
0 0

Sample Output

Polynomial 1: 13 11
Polynomial 2: 8 11

1个回答

caozhy
caozhy   Ds   Rxr 2017.09.30 21:38
已采纳
Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!
其他相关推荐
amazon polly tts
text to speech service provided by amazon aws cloud platform
FE pixel polly插件
粒子扩散效果,premiere plugin插件
“Final Effects”FE插件(全套63款)汉化版下载地址
以下是全套63款插件的中英文对照: Final Effects(简称Fe) FE Ball Action(球状运动) FE Bubbles(泡沫) FE Color Offset(颜色位移) FE Composite(合成) FE Flo Motion(失真运动) FE Griddler(矿筛) FE Image Wipe(图像擦除) FE Kaleida(发音体) FE Lens(透镜) FE Light Burst 2.5(灯光爆裂) FE Light Sweep(扫光) FE Page Turn(翻页) FE Particle Systems(粒子系统) FE Particle Systems II(粒子系统2) FE Particle Systems LE(粒子系统LE) FE Pixel Polly(像素剥离) FE Radial ScaleWipe(反射状的缩放擦拭) FE Rain(下雨) FE Scale Wipe(缩放擦除) FE Scatterize(分散) FE Slant(倾斜) FE Slant Matte(倾斜剪影) FE Snow(下雪) FE Sphere(球体) FE Star Burst(星爆式) FE Threshold(阀值) FE Threshold RGB(RGB阀值) FE Tiler(瓦盖) FE Twister(缠绕) Next Effect(简称Ne) FE Advanced 3D(高级三维) FE Bend It(弯曲) FE Cylinder(圆柱体) FE Drizzle(毛毛雨) FE Force Motion Blur(强大的运动模糊) FE Hair(毛发) FE Light Rays(体积光) FE Mr. Smoothie(圆滑) FE Power Pin(透视点) FE RepeTile(放射状模糊) FE Simple Wire Removal(擦除金属丝) FE Wide Time(放慢) Studio Effects(简称Se) FE Alpha Map(Alpha贴图) FE Bender(弯曲) FE Blobbylize(滴状斑点) FE Burn Film(燃烧的胶片) FE Glass(玻璃) FE Glass Wipe(擦拭玻璃) FE Glue Gun(喷胶枪) FE Grid Wipe(删格擦拭) FE Jaws(狭口) FE Light Wipe(扫光) FE Mr. Mercury(水银先生) FE Particle World(粒子世界) FE Ripple Pulse(涟漪发生器) FE Smear(涂污) FE Split(切开) FE Spotlight(聚光灯) FE Time Blend(时间混合) FE Time Blend FX(时间混合FX) FE Toner(调色剂) 【插件安装方法】安装方法很简单,按上面的地址下载后先进行解压,然后复制到 X:\Adobe\After Effects 6.5(或7.0)\Plug-ins\文件夹下即可 请大家注意一下:“Tiler.aex (瓦盖、瓦片效果)插件”没有汉化,因为非常不稳定,经常出现调用错误,不知道是什么原因。所以大家可以将它的扩展名改名,或移动到其他地方或者直接删除掉也可以。
Engineering Math - Matlab Programming
Contents 1 Engineering Problem Solving 1 1.1 Problem-Solving Process . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 1.2 ProblemSolving Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 1.3 Computing Software . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 1.4 Computing Terminology. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 2 Matlab Technical Computing Environment 14 2.1 Workspace,Windows, and Help . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14 2.2 ScalarMathematics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 2.3 BasicMathematical Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24 2.4 Computational Limitations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26 2.5 Display Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29 2.6 Accuracyand Precision . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33 3 Files and File Management 37 3.1 FileManagement Definitions and Commands . . . . . . . . . . . . . . . . . . . . . . 37 3.2 Saving and RestoringMatlab Information . . . . . . . . . . . . . . . . . . . . . . . . 39 3.3 ScriptM-Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43 3.4 Errors and Debugging . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47 3.5 Matlab Search Path, PathManagement, and Startup . . . . . . . . . . . . . . . . . . 49 i 4 Trigonometry and ComplexNum bers 51 4.1 Trigonometry . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51 4.2 Complex Numbers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57 4.3 Two-Dimensional Plotting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72 5 Arrays and Array Operations 81 5.1 Vector Array s. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81 5.2 Matrix Array s. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88 5.3 ArrayPlotting Capabilities . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93 6 Mathematical Functions and Applications 101 6.1 Signal Representation, Processing, and Plotting . . . . . . . . . . . . . . . . . . . . . 101 6.2 Poly nomials . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111 6.3 Partial Fraction Expansion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 120 6.4 Functions of Two
Matlab - Math Problems solving with Matlab Programming.pdf
1 Engineering Problem Solving 1 1.1 Problem-Solving Process . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 1.2 ProblemSolving Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 1.3 Computing Software . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 1.4 Computing Terminology. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 2 Matlab Technical Computing Environment 14 2.1 Workspace,Windows, and Help . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14 2.2 ScalarMathematics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 2.3 BasicMathematical Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24 2.4 Computational Limitations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26 2.5 Display Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29 2.6 Accuracyand Precision . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33 3 Files and File Management 37 3.1 FileManagement Definitions and Commands . . . . . . . . . . . . . . . . . . . . . . 37 3.2 Saving and RestoringMatlab Information . . . . . . . . . . . . . . . . . . . . . . . . 39 3.3 ScriptM-Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43 3.4 Errors and Debugging . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47 3.5 Matlab Search Path, PathManagement, and Startup . . . . . . . . . . . . . . . . . . 49 i 4 Trigonometry and ComplexNum bers 51 4.1 Trigonometry . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51 4.2 Complex Numbers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57 4.3 Two-Dimensional Plotting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72 5 Arrays and Array Operations 81 5.1 Vector Array s. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81 5.2 Matrix Array s. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88 5.3 ArrayPlotting Capabilities . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93 6 Mathematical Functions and Applications 101 6.1 Signal Representation, Processing, and Plotting . . . . . . . . . . . . . . . . . . . . . 101 6.2 Poly nomials . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111 6.3 Partial Fraction Expansion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 120 6.4 Functions of Two Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125 6.5 User-Defined Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129 6.6 Plotting Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133 7 DataAnalysis 135 7.1 Maximum andMinimum. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136 7.2 Sums and Products . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 140 7.3 Statistical Analy sis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143 7.4 Random Number Generation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 148 8 Selection Programming 155 8.1 Relational and Logical Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 155 8.2 Flow Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 161 8.3 Loops . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 165 8.4 Selection Statements in User-Defined Functions . . . . . . . . . . . . . . . . . . . . . 169 8.5 Update Processes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 171 ii 8.6 Applied ProblemSolving: Speech Signal Analy sis . . . . . . . . . . . . . . . . . . . . 175 9 Vectors, Matrices and Linear Algebra 180 9.1 Vectors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 181 9.2 Matrices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 187 9.3 Solutions to Sy stems of Linear Equations . . . . . . . . . . . . . . . . . . . . . . . . 196 9.4 Applied ProblemSolving: RobotMotion . . . . . . . . . . . . . . . . . . . . . . . . . 202 10 Curve Fitting and Interpolation 207 10.1 MinimumMean-Square Error Curve Fitting . . . . . . . . . . . . . . . . . . . . . . . 207 10.2 Applied Problem Solving: Hydraulic Engineering . . . . . . . . . . . . . . . . . . . . 213 10.3 Interpolation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 215 10.4 Applied ProblemSolving: Human Hearing . . . . . . . . . . . . . . . . . . . . . . . . 219 11 Integration and Differentiation 223 11.1 Numerical Integration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 223 11.2 Numerical Differentiation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 230 12 Strings, Time, Base Conversion and Bit Operations 239 12.1 Character Strings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 239 12.2 Time Computations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 244 12.3 Base Conversions and Bit Operations . . . . . . . . . . . . . . . . . . . . . . . . . . . 247 13 Symbolic Processing 250 13.1 Sy mbolic Expressions and Algebra . . . . . . . . . . . . . . . . . . . . . . . . . . . . 250 13.2 Manipulating Trigonometric Expressions . . . . . . . . . . . . . . . . . . . . . . . . . 257 13.3 Evaluating and Plotting Sy mbolic Expressions . . . . . . . . . . . . . . . . . . . . . 258 13.4 Solving Algebraic and Transcendental Equations . . . . . . . . . . . . . . . . . . . . 259 13.5 Calculus . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 262 13.6 Linear Algebra . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 266