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) {
		int count = 0;
		while (temp != '\n') {
			if (temp == '-' || temp >= '0' && temp <= '9') {
				ungetc(temp, stdin);
				scanf("%d",&c[count ++]);
			}
			temp = getchar();
		}
		int flag = 0,data,sum;
		temp = getchar();
		while (temp != '\n') {
			if (temp == '-' || temp >= '0' && temp <= '9') {
				ungetc(temp, stdin);
				scanf("%d",&data);
				sum = 0;
				for (int i = 0 ; i < count ; ++ i) {
					sum *= data;
					sum += c[i];
				}
				if (flag) printf(" ");
				printf("%d",sum);
				flag = 1;
			}
			temp = getchar();
		}
		printf("\n");
	}
	return 0;
}
时间: 2024-08-29 05:27:32

UVa 498 - Polly the Polynomial的相关文章

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 - 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[10

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

UVA 12009 - Avaricious Maryanna(数论)

UVA 12009 - Avaricious Maryanna 题目链接 题意:给定一个n.求出n个数位组成的数字x,x^2的前面|x|位为x 思路:自己先暴力打了前几组数据,发现除了1中有0和1以外,其它数据都是由前一项往上再加入一位得到的,因此设新数字为(a?10k+x)2=(a?10k)2+x2+2?a?10k?x 因此(a?10k+x)=((a?10k)2+x2+2?a?10k?x)/10k%10 化简后得到x2/10k%10+2?a?x%10 因此仅仅要能求出x2/10k%10.然后再