首页 > 其他分享 >UVa 10719 Quotient Polynomial (数学)

UVa 10719 Quotient Polynomial (数学)

时间:2023-04-12 13:06:34浏览次数:50  
标签:int should will polynomial integer Polynomial UVa line 10719


10719 - Quotient Polynomial

Time limit: 3.000 seconds

http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=99&page=show_problem&problem=1660

A polynomial of degree n can be expressed as

If k is any integer then we can write:

Here q(x) is called the quotient polynomial of p(x) of degree (n-1) and r is any integer which is called the remainder.

For example, if p(x) = x- 7x2+ 15x - 8 and k = 3 then q(x) = x- 4x + 3 and r = 1. Again if p(x) = x- 7x2+ 15x - 9 and k = 3 then q(x) = x- 4x + 3 and r = 0.

In this problem you have to find the quotient polynomial q(x) and the remainder r. All the input and output data will fit in 32-bit signed integer.

InputYour program should accept an even number of lines of text. Each pair of line will represent one test case. The first line will contain an integer value for k. The second line will contain a list of integers (an, an-1, … a0), which represent the set of co-efficient of a polynomial p(x). Here 1 ≤ n ≤ 10000. Input is terminated by <EOF>.

OutputFor each pair of lines, your program should print exactly two lines. The first line should contain the coefficients of the quotient polynomial. Print the reminder in second line. There is a blank space before and after the ‘=’ sign. Print a blank line after the output of each test case. For exact format, follow the given sample.

Sample Input

Output for Sample Input

3
1 –7 15 –8
3
1 –7 15 –9

q(x): 1 -4 3
r = 1

q(x): 1 -4 3
r = 0


思路:q(x)中除了最高次项的系数与p(x)最高项的系数相同,其它系数有一个规律q[i] = p[i] + k * q[i - 1].(可用大除法证之)


完整代码:

/*0.089s*/

#include<cstdio>

int p[10010], q[10010];

int main(void)
{
	int k, n;
	char c;
	while (~scanf("%d", &k))
	{
        c = 1;
		for (n = 0; c != '\n'; n++)
			scanf("%d%c", &p[n], &c);
		q[0] = p[0];
		for (int i = 1; i < n; i++)
			q[i] = p[i] + k * q[i - 1];
		printf("q(x):");
		for (int i = 0; i < n - 1; i++)
			printf(" %d", q[i]);
		printf("\nr = %d\n\n", q[n - 1]);
	}
	return 0;
}



标签:int,should,will,polynomial,integer,Polynomial,UVa,line,10719
From: https://blog.51cto.com/u_5535544/6185477

相关文章

  • UVa 103 Stacking Boxes (DP&DAG)
    103-StackingBoxesTimelimit:3.000secondshttp://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=114&page=show_problem&problem=39BackgroundSomeconceptsinMathematicsandComputerSciencearesimpleinoneortw......
  • UVa 11129 An antiarithmetic permutation (构造题&想法题&分治)
    11129-AnantiarithmeticpermutationTimelimit:3.000secondshttp://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=113&page=show_problem&problem=2070Apermutationof n+1 isabijectivefunctionoftheinitial n+1......
  • UVa 10041 Vito's Family (中位数&快速选择)
    10041-Vito'sFamilyTimelimit:3.000secondshttp://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=113&page=show_problem&problem=982BackgroundTheworld-knowngangsterVitoDeadstoneismovingtoNewYork.He......
  • UVa 706 / POJ 1102 LCD Display (模拟)
    706-LCDDisplayTimelimit:3.000secondshttp://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=647http://poj.org/problem?id=1102Afriendofyouhasjustboughtanewcomputer.Untilno......
  • UVa 757 / POJ 1042 / East Central North America 1999 Gone Fishing (枚举&贪心&想
    757-GoneFishingTimelimit:3.000secondshttp://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=698http://poj.org/problem?id=1042Johnisgoingonafishingtrip.Hehas h hoursavailable( ),andther......
  • UVa 408 Uniform Generator (最大公约数&证明)
    408-UniformGeneratorTimelimit:3.000secondshttp://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=100&page=show_problem&problem=349Computersimulationsoftenrequirerandomnumbers.Onewaytogeneratepseudo-r......
  • UVa 350 Pseudo-Random Numbers (伪随机数的循环长度)
    350-Pseudo-RandomNumbersTimelimit:3.000secondshttp://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=100&page=show_problem&problem=286Computersnormallycannotgeneratereallyrandomnumbers,butfrequentlyar......
  • UVa 568 Just the Facts (数论&打表&不打表)
    568-JusttheFactsTimelimit:3.000secondshttp://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=100&page=show_problem&problem=509Theexpression N!,readas``N factorial,"denotestheproductofthefirst N......
  • UVa 10112 Myacm Triangles (枚举&计算几何)
    10112-MyacmTrianglesTimelimit:3.000secondshttp://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=101&page=show_problem&problem=1053TherehasbeenconsiderablearcheologicalworkontheancientMyacmculture......
  • UVa 374 Big Mod (快速幂取模)
    374-BigModTimelimit:3.000secondshttp://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=310Calculateforlargevaluesof B, P,and M usinganefficientalgorithm.(That'sright,......