首页 > 其他 > 详细

POJ 2527 Polynomial Remains 多项式运算

时间:2015-08-13 12:10:53      阅读:228      评论:0      收藏:0      [点我收藏+]
Polynomial Remains
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 1236   Accepted: 700

Description

技术分享Given the polynomial 
a(x) = an xn + ... + a1 x + a0,

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. 

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

AC代码

#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;
int main(){
    int n,k;
    int my[10000+10];
    while(cin>>n>>k){
        if(n==-1&&k==-1)break;
        for(int i=0;i<=n;i++)cin>>my[i];
        ///for(int i=n;i>0;--i)cout<<my[i]<<"x^"<<i<<'+';
        ///cout<<my[0]<<'\12';
        for(int i=n;i>=k;--i){
            if(my[i]==0)continue;
            my[i-k]=my[i-k]-my[i];
            my[i]=0;
        }
        int len=n;
        while(len>=0&&!my[len])len--;
        for(int i=0;i<len;++i)cout<<my[i]<<' ';
        cout<<my[len]<<'\12';
    }
    return 0;
}


版权声明:本文为博主原创文章,未经博主允许不得转载。

POJ 2527 Polynomial Remains 多项式运算

原文:http://blog.csdn.net/zp___waj/article/details/47609147

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!