POJ-2527 Polynomial Remains-多項式相除
Polynomial Remains
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 1240 | Accepted: 702 |
Description

compute the remainder r(x) when a(x) is divided by xk+1.
Input
The input consists of a number of cases. The first line of each case specifies the two integers n and k (0 <= n, k <= 10000). The next n+1 integers give the coefficients of a(x), starting from a0 and ending with an. The input is
terminated if n = k = -1.
Output
For each case, output the coefficients of the remainder on one line, starting from the constant coefficient r0. If the remainder is 0, print only the constant coefficient. Otherwise, print only the first d+1 coefficients for a
remainder of degree d. Separate the coefficients by a single space.
You may assume that the coefficients of the remainder can be represented by 32-bit integers.
You may assume that the coefficients of the remainder can be represented by 32-bit integers.
Sample Input
5 2 6 3 3 2 0 1 5 2 0 0 3 2 0 1 4 1 1 4 1 1 1 6 3 2 3 -3 4 1 0 1 1 0 5 1 0 0 7 3 5 1 2 3 4 -1 -1
Sample Output
3 2 -3 -1 -2 -1 2 -3 0 0 1 2 3 4
Source
Alberta Collegiate Programming Contest 2003.10.18
因為輸入輸出資料太多,所以用cin、cout會超時。。
#include <iostream>
#include <cstdio>
using namespace std;
const int maxn = 10010;
int main()
{
int n,k;
int val[maxn];
while(scanf("%d%d",&n,&k)!=EOF,n!=-1 || k !=-1)
{
int i;
for(i = 0 ; i <= n ; ++i)
{
scanf("%d",&val[i]);
}
//進行除法運算
for(i = n ; i >= k ; --i)
{
if(val[i] == 0)
{
continue;
}
val[i-k] = val[i-k] - val[i];
val[i] = 0;
}
//調整陣列長度,即高位的0不用輸出
int t = n;
while(val[t] == 0 && t > 0)
{
--t;
}
for(i = 0 ; i < t ; ++i)
{
printf("%d ",val[i]);
}
printf("%d\n",val[t]);
}
return 0;
}
因為輸入輸出資料太多,所以用cin、cout會超時。。
相關文章
- 多項式
- 多項式除法
- 多項式乘法
- 多項式全家桶
- 多項式半家桶
- 生成函式與多項式函式
- 多項式求和 hd 2011
- 【模板】多項式乘法逆
- 多項式學習筆記筆記
- [ABC137F] Polynomial Construction 題解Struct
- PAT6-2 多項式求值
- 普通有限多項式筆記筆記
- 一元稀疏多項式相加
- 核函式 多項式核函式 高斯核函式(常用)函式
- 【組合數學】多項式定理 ( 多項式係數 | 多重集全排列 | 對應放球子模型方案數 | 多項式係數相關恆等式 )模型恆等式
- 一元多項式的應用
- Tensorflow教程(前二)——多項式迴歸
- 正交多項式介紹及應用
- 題解 P10249【【模板】多項式複合函式】函式
- 15.6 用多項式一致逼近連續函式函式
- CF156D-Prufer序列、多項式定理
- MATLAB求多項式係數及次數Matlab
- 怎樣解題|題4.3.12:多項式展開
- [PAT B] 1010 一元多項式求導求導
- 使用梯度下降法實現多項式迴歸梯度
- 特徵工程:互動特徵與多項式特徵理解特徵工程
- 用多項式的逆優化dp總結優化
- 輾轉相除法
- 數論函式群在數論多項式生成函式集上的作用函式
- 【機器學習】多項式迴歸原理介紹機器學習
- 【機器學習】多項式迴歸python實現機器學習Python
- 【機器學習】多項式迴歸sklearn實現機器學習
- 題解 P5809【【模板】多項式複合逆】
- PAT-B 1010 一元多項式求導求導
- java的多項式的加減乘除和賦值Java賦值
- LeetCode 29——兩數相除LeetCode
- 輾轉相除法原理
- python LeetCode 兩數相除PythonLeetCode
- 29.兩數相除