博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
UVA10719 - Quotient Polynomial
阅读量:5234 次
发布时间:2019-06-14

本文共 1905 字,大约阅读时间需要 6 分钟。

忘了打空行了,做的时候想起了高中的数学老师 TAT

题目:

Problem B

Problem B

Quotient Polynomial

Time Limit

2 Seconds

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) = x3 - 7x2+ 15x - 8 and k = 3 then q(x) = x2 - 4x + 3 and r = 1. Again if p(x) = x3 - 7x2+ 15x - 9 and k = 3 then q(x) = x2 - 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.

Input

Your 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>.

Output

For 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

 

Problem setter:
Mohammed Shamsul Alam
Special thanks to Tanveer Ahsan

 

解答:

1 #include
2 int coe[10010]; 3 int res[10010]; 4 int main() 5 { 6 int k; 7 char c; 8 while(scanf("%d",&k)!=EOF) 9 {10 int i;11 k=-k;12 for(i=0;;i++)13 {14 scanf("%d%c",&coe[i],&c);15 if(c=='\n')16 break;17 }18 int n=i,tmp,hd=coe[0];19 for(i=0;i

 

转载于:https://www.cnblogs.com/terryX/archive/2013/03/03/2941591.html

你可能感兴趣的文章
Leetcode: Unique Binary Search Trees II
查看>>
C++ FFLIB 之FFDB: 使用 Mysql&Sqlite 实现CRUD
查看>>
Spring-hibernate整合
查看>>
c++ map
查看>>
exit和return的区别
查看>>
discuz 常用脚本格式化数据
查看>>
洛谷P2777
查看>>
PHPStorm2017设置字体与设置浏览器访问
查看>>
SQL查询总结 - wanglei
查看>>
安装cocoa pods时出现Operation not permitted - /usr/bin/xcodeproj的问题
查看>>
GIT笔记:将项目发布到码云
查看>>
JavaScript:学习笔记(7)——VAR、LET、CONST三种变量声明的区别
查看>>
JavaScript 鸭子模型
查看>>
SQL Server 如何查询表定义的列和索引信息
查看>>
GCD 之线程死锁
查看>>
NoSQL数据库常见分类
查看>>
一题多解 之 Bat
查看>>
Java 内部类
查看>>
{面试题7: 使用两个队列实现一个栈}
查看>>
【练习】使用事务和锁定语句
查看>>