Quotient Polynomial

2024-08-24 22:38
文章标签 quotient polynomial

本文主要是介绍Quotient Polynomial,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

第一次的时候理解错题意了,以为是输入与K有关。。。我也不知道我怎么想的。。。反正后来改对啦

Problem B

Quotient Polynomial

Time Limit

2 Seconds

A polynomial of degree n can be expressed as

If k is any integer then we can write:

Here q(x) is called the quotient polynomial of p(x) of degree (n-1) and r is any integer which is called the remainder.

For example, if p(x) = x- 7x2+ 15x - 8 and k = 3 then q(x) = x- 4x + 3 and r = 1. Again if p(x) = x- 7x2+ 15x - 9 and k = 3 thenq(x) = x- 4x + 3 and r = 0.

In this problem you have to find the quotient polynomial q(x) and the remainder rAll the input and output data will fit in 32-bit signed integer.

Input
Your program should accept an even number of lines of text. Each pair of line will represent one test case. The first line will contain an integer value for k. The second line will contain a list of integers (an, an-1, … a0), which represent the set of co-efficient of a polynomialp(x). Here 1 ≤ n ≤ 10000. Input is terminated by <EOF>.

Output
For each pair of lines, your program should print exactly two lines. The first line should contain the coefficients of the quotient polynomial. Print the reminder in second line. There is a blank space before and after the ‘=’ sign. Print a blank line after the output of each test case. For exact format, follow the given sample.

Sample Input

Output for Sample Input

3
1 –7 15 –8
3
1 –7 15 –9

q(x): 1 -4 3
r = 1

q(x): 1 -4 3
r = 0


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include <stdio.h>
#include <string.h>
int a[15000];
int b[15000];
int main()
{int k, i, j;char s;while(scanf("%d",&k)!=EOF){memset(a,0,sizeof(a));memset(b,0,sizeof(b));for(i = 0; ; i++){scanf("%d%c",&a[i], &s);if(i==0)b[0] = a[i];else{b[i] = a[i] + k * b[i-1];}if(s=='\n') break;}printf("q(x): ");for(j = 0; j < i; j++){if(j != i - 1)printf("%d ", b[j]);elseprintf("%d\n", b[j]);}printf("r = %d\n\n", b[i]);}return 0;
}

这篇关于Quotient Polynomial的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1103803

相关文章

Spark MLlib 特征工程系列—特征转换Polynomial Expansion

Spark MLlib 特征工程系列—特征转换Polynomial Expansion 1. Polynomial Expansion 简介 PolynomialExpansion 是 Spark MLlib 中的一种特征转换工具,主要用于将原始特征进行多项式扩展。多项式扩展通过生成原始特征的所有多项式组合来增加特征的维度,从而提高模型的表达能力。这种方法在非线性问题的建模中非常有用,因为它允

1204 ACdream Integration of Polynomial(数学:简单求积分)

很容易的一个题,但是题目有个坑 比如说输入: 1 -1 1 输出结果应该为:-1/2 2 而不是:1/-2 2 但是题目中又没有说清楚 感觉是因为题目不严谨 代码如下: #include <cstdio>#include <cstring>#include <iostream>#include <algorithm>#define MAXN 1010#define

【ocean】报错*Error* quotient: can‘t handle (nil / nil)

这个情况比较复杂,有很多种情况,一般nil代表没有值,ciw中会具体提示哪一行错误,但如果是一个procedure,他不会提示得那么仔细 Error* quotient: can’t handle (nil / nil) Error load: error while loading file - “xxx.ocn” at line 183网上看还有error,提示值晶体管值不对,原来读文件时候多

polynomial regression

在上一节所介绍的非线性回归分析,首先要求我们对回归方程的函数模型做出判断。虽然在一些特定的情况下我们可以比较容易地做到这一点,但是在许多实际问题上常常会令我们不知所措。根据高等数学知识我们知道,任何曲线可以近似地用多项式表示,所以在这种情况下我们可以用多项式进行逼近,即多项式回归分析。     一、多项式回归方法 假设变量y与x的关系为p次多项式,且在xi处对y的随机误差  (i=1,2,…,

吴恩达机器学习-可选实验室:特征工程和多项式回归(Feature Engineering and Polynomial Regression)

文章目录 目标工具特征工程和多项式回归概述多项式特征选择功能备用视图扩展功能复杂的功能 恭喜! 目标 在本实验中,你将:探索特征工程和多项式回归,它们允许您使用线性回归的机制来拟合非常复杂,甚至非常非线性的函数。 工具 您将利用在以前的实验中开发的函数以及matplotlib和NumPy。 import numpy as npimport matplotlib.pypl

【DataStructure】Another usage of List: Polynomial

Statements: This blog was written by me, but most of content  is quoted from book【Data Structure with Java Hubbard】  【Description】 Apolynomialis a mathematical function of the form:

线性回归(linear_regression),多项式回归(polynomial regression)(Tensorflow实现)

#回归import numpy as npimport tensorflow as tfimport matplotlib.pyplot as pltn_observations=100xs=np.linspace(-3,3,n_observations)ys=np.sin(xs)+np.random.uniform(-0.5,0.5,n_observations)plt.scatt

1.1介绍与多项式曲线拟合(Polynomial Curve Fitting)

今天开始学Pattern Recognition and Machine Learning (PRML),章节1.1,介绍与多项式曲线拟合(Polynomial Curve Fitting) 转载请注明源地址:http://www.cnblogs.com/xbinworld/archive/2013/04/21/3034300.html    Pattern Recognition

abc D - Polynomial division

传送门:D - Polynomial division 题目大意:给出A(x)和C(x)多项式的序数,A(x)*B(x) = C(x),求B(x)。 坑:这题不能够顺着想,那样会很复杂,但是一旦把数组倒过来,先求B(m),题意就会明朗很多了。 #include <bits/stdc++.h>using namespace std;int main() {int N, M;cin >> N >

PCL-表面(Surface)Smoothing and normal estimation based on polynomial reconstruction

Moving Least Squares(MLS) 移动最小二乘法,可以用来平滑和重采样,接下来将介绍使用方法。https://en.wikipedia.org/wiki/Moving_least_squares(MLS介绍) 使用统计分析很难去除一些数据不规则(由小距离测量误差引起)。 要创建完整的模型,必须考虑光泽表面以及数据中的遮挡。 在无法获得额外扫描的情况下,解决方案是使用重采样算法,