POJ 2527 Polynomial Remains 多项式运算

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;
}

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

时间: 2024-10-27 07:27:26

POJ 2527 Polynomial Remains 多项式运算的相关文章

【数论】UVa 10586 - Polynomial Remains

Problem F: Polynomial Remains Given the polynomial a(x) = an xn + ... + a1 x + a0, compute the remainder r(x) when a(x) is divided by xk+1. The input consists of a number of cases. The first line of each case specifies the two integers n and k (0 ≤ n

UVA 10951 Polynomial GCD 多项式欧几里德求最大公共多项式

今天作比赛遇上了HDU3892,都分析出来怎么做了,可惜不会求多项式的最大公共多项式,当时写了半天,案例也没有跑出来,赛后搜了一下题解,发现有大神做出了,而且是有模版的,不过又搜了一下关于这方面的题目,很少,只发现了这一道,所以先做一下这一道吧 题意,给你两个多项式,求他们的最大公共多项式,然后输出即可,无齿的套用了别人的模版,呵呵! #include<iostream> #include<cstdio> #include<list> #include<algor

Matlab基础学习--------关系和逻辑运算及多项式运算

直接给出实例,实例中包含知识点的讲解: %% 关系运算符 % < <= > >= == ~=(不等于) % 比较魔方矩阵中大学元素的值大于4 % 魔方矩阵:矩阵的每行每列和两条对角线上的和都相等 a=magic(3) %生成一个3*3的魔方矩阵 a>4*ones(3) %与全为4的矩阵进行比较 magic(6) %生成6*6的魔方矩阵 %运行结果: % a = % % 8 1 6 % 3 5 7 % 4 9 2 % ans = % % 1 0 1 % 0 1 1 % 0 1

POJ 1845 Sumdiv【同余模运算+递归求等比数列和+快速幂运算】

快速幂运算在第一次训练时候就已经遇到过,这里不赘述 同余模运算也很简单,这里也不说了,无非是(a+b)%m (a*b)%m 把m弄到里面变成(a%m+b%m)%m   (a%m*b%m)%m 今天学的最重要的还是递归二分求等比数列 题目大意是给出A和B,求A^B的约数和 解这个题,首先,对A进行素因子分解得到 (PI(pi^ai))^B 然后我们有约数和公式: 对A=PI(p1^k1) A的所有因子之和为S = (1+p1+p1^2+p1^3+...p1^k1) * (1+p2+p2^2+p2^

POJ 2965-The Pilots Brothers&#39; refrigerator--位运算+BFS+回溯路径

The Pilots Brothers' refrigerator Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 18576   Accepted: 7108   Special Judge Description The game "The Pilots Brothers: following the stripy elephant" has a quest where a player needs to o

poj 2126 Factoring a Polynomial 数学多项式分解

题意: 给一个多项式,求它在实数域内的可分解性. 分析: 代数基本定理. 代码: //poj 2126 //sep9 #include <iostream> using namespace std; int main() { int n; scanf("%d",&n); int a,b,c; scanf("%d%d%d",&a,&b,&c); if(n>2) puts("NO"); else if

PTA 6-14 用单向链表完成多项式运算 (35 分)

输入两个多项式,计算它们的加.减及乘法, 将计算结果输出到屏幕上. 1) 输入:从键盘分两行分别输入两个多项式数据,每个多项式输入格式如下: n a1 m1 a2 m2 a3 m3 . .. ai mi.... an mn 其中n为多项式系数为非零的项数,ai为系数,mi为指数, 它们都是整数,该输入数据所表达的多项式意义为(其中符号^表示幂次): a1x^m1 + a2x^m2 + a3x^m3 + ...... + an x^mn 2)输出:先输出参与运算的两个多项式, 然后输出它们的运算结

FZU 2215 Simple Polynomial Problem (多项式乘法 栈)

Problem 2215 Simple Polynomial Problem Time Limit: 1000 mSec    Memory Limit : 32768 KB Problem Description You are given an polynomial of x consisting of only addition marks, multiplication marks, brackets, single digit numbers, and of course the le

poj 3046 Ant Counting 多项式乘法解可重组合数

题意: 裸的求可重组合数. 分析: 多项式乘法求系数的应用啊,不用dp. 代码: //poj 3046 //sep9 #include <iostream> using namespace std; const int maxN=1024; const int maxL=100024; const int mod=1000000; int num[maxN]; int coef[maxL]; int tmp[maxL]; int l1; void mul(int l2) { for(int i