UVA - 10719 Quotient Polynomial

点击打开链接

由一个多项式确定另一个多项式,就是一个找规律题。

假设:   p(x)=a*x^4+b*x^3+c*x^2+d*x+f          q(x)=a1*x^3+b1*x^2+c1*x+d    因为 p(x) = (x-1) * q(x)   所以

a1=a   b1-a1*k=b   c1-k*b1=c   d1-k*c1=d   就可以把对应系数求出来。

#include<cstdio>
#include<cstring>
int f1[10005],f2[10005];
char s[100000];
int main()
{
    //freopen("a.txt","r",stdin);
    int k,i,n,cnt;
    while(~scanf("%d",&k))
    {
        getchar();
        n=cnt=0;
        int flag=0;
        gets(s);
        int l=strlen(s);
        for(i=0;i<l;i++)
        {
            if(s[i]=='-') flag=1;
            else if(s[i]>='0'&&s[i]<='9') cnt=cnt*10+s[i]-'0';
            else
            {
                if(flag) {cnt=-cnt;flag=0;}
                f1[n++]=cnt;
                //printf("%d\n",cnt);
                cnt=0;
            }
        }
        if(flag) f1[n++]=-1*cnt;
        else f1[n++]=cnt;
       // printf("%d %d\n",cnt,n);
        f2[0]=f1[0];
        for(i=1;i<n;i++)
        {
            f2[i]=f1[i]+f2[i-1]*k;
        }
        printf("q(x):");
        for(i=0;i<n-1;i++)
            printf(" %d",f2[i]);
        printf("\n");
        printf("r = %d\n",f2[n-1]);
        printf("\n");
    }
    return 0;
}
时间: 2024-10-04 06:51:31

UVA - 10719 Quotient Polynomial的相关文章

UVA题目分类

题目 Volume 0. Getting Started 开始10055 - Hashmat the Brave Warrior 10071 - Back to High School Physics 10300 - Ecological Premium 458 - The Decoder 494 - Kindergarten Counting Game 414 - Machined Surfaces 490 - Rotating Sentences 445 - Marvelous Mazes

UVA 10951 - Polynomial GCD(数论)

UVA 10951 - Polynomial GCD 题目链接 题意:给定两个多项式,求多项式的gcd,要求首项次数为1,多项式中的运算都%n,并且n为素数. 思路:和gcd基本一样,只不过传入的是两个多项式,由于有%n这个条件,所以计算过程可以用乘法逆去计算除法模,然后最后输出的时候每项除掉首项的次数就是答案了. 代码: #include <stdio.h> #include <string.h> #include <vector> using namespace s

uva 10951 - Polynomial GCD(欧几里得)

题目链接:uva 10951 - Polynomial GCD 题目大意:给出n和两个多项式,求两个多项式在所有操作均模n的情况下最大公约数是多少. 解题思路:欧几里得算法,就是为多项式这个数据类型重载取模运算符,需要注意的是在多项式除多项的过程中,为了保证各项系数为整数,需要将整个多项式的系数整体扩大至一定倍数,碰到先除后模的时候要用逆元. #include <cstdio> #include <cstring> const int maxn = 105; int M; void

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

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

【数论】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 (最大公共多项式)

Description Problem C Polynomial GCD Input: standard input Output: standard output Given two polynomials f(x) and g(x) in Zn, you have to find their GCD polynomial, ie, a polynomial r(x) (also in Zn) which has the greatest degree of all the polynomia

UVa 498 - Polly the Polynomial

题目:一直多项式的系数,求不同的x对应多项式的值. 分析:数学题,简单题.直接代入多项式计算即可. 说明:注意输入格式. #include <iostream> #include <cstdlib> #include <cstring> #include <cstdio> using namespace std; int temp,c[10000]; int main() { int n; while ((temp = getchar()) != EOF)

UVa 10105 - Polynomial Coefficients

题目:给你一个多项式(x1+x2+..+xk)^ n,求x1^k1*x2^k2*..*xn^kn的系数. 分析:组合数学,多项式系数. 系数为:C(n,k1)* C(n-k1,k2)* .. *C(n-k1-..-kn-1,kn)= n! /(k1!k2!..kn!). 说明:好久没怎么刷题了╮(╯▽╰)╭. #include <iostream> using namespace std; int f[13],p[13]; int main() { f[0] = 1; for (int i =

UVA - 586 Instant Complexity

Description  Instant Complexity  Analyzing the run-time complexity of algorithms is an important tool for designing efficient programs that solve a problem. An algorithm that runs in linear time is usually much faster than analgorithm that takes quad