Uva 10719

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, ifp(x) = x3- 7x2+ 15x - 8andk = 3thenq(x) = x2- 4x + 3andr = 1. Again ifp(x) = x3- 7x2+ 15x - 9andk = 3thenq(x) = x2- 4x + 3and 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
 
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<ctype.h>
int poly[10010];
int main()
{

    int r, k, cnt, i, flag;
    char temp[20], ch;
    while(scanf("%d", &k) != EOF)
    {
        getchar();
        cnt = i = flag = 0;
        while((ch = getchar()) != EOF && ch != '\n')
        {
            if(ch != ' ')
            {
                temp[i++] = ch;
                flag = 1;
            }
            else if(flag)
            {
                flag = 0;
                temp[i] = '\0';
                poly[cnt++] = atoi(temp);
                i = 0;
            }
        }
        if(flag) 
        {
            temp[i] = '\0';
            poly[cnt++] = atoi(temp);
        }
        if(cnt-1 == 0) flag = 0;
        else flag = poly[0];
        printf("q(x): %d", flag);
        for(i=1; i<cnt; ++i)
        {
            poly[i] = poly[i] + k*poly[i-1];
            if(i != cnt-1) printf(" %d", poly[i]);
        }
        printf("\nr = %d\n\n", poly[cnt-1]);
        
    }
    return 0;
}

解题思路:
题目的意思再清楚不过,给你式子中的 k,和 p(x)式子各项的系数,要你求出满足这个式子      中的q(x)的系数和 r 的值,在草稿纸上可以得出:

设 p(x) = An*x^n + An-1*x^(n-1) + An-2*x^(n-2) + ...... + A0

    q(x) = a`x^(n-1) + b`x^(n-2) + c`x^(n-3) + ...... + d`x^0

则 由 p(x) = (x-k)*q(x) + r 得:

a`x^(n-1) + b`x^(n-2) + c`x^(n-3) + ...... + d`x^0 = (x-k)*(a`x^(n-1) + b`x^(n-2) + c`x^(n-3) + ...... + d`x^0) + r

化简提起相同指数的x的指数可以得出:

a` = An;  b` = An-1 + k*a`;  c` = An-2 + k*b`;  ......  r = A0 + k*d`

这样答案就出来了

PS:不要忘记了在每一个case后都要输出一个空行,而且一开始的输入也要花点心思处理一下

                            


<script type="text/javascript"> </script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
牙科就诊管理系统利用当下成熟完善的SSM框架,使用跨平台的可开发大型商业网站的Java语言,以及最受欢迎的RDBMS应用软件之一的Mysql数据库进行程序开发。实现了用户在线查看数据。管理员管理病例管理、字典管理、公告管理、药单管理、药品管理、药品收藏管理、药品评价管理、药品订单管理、牙医管理、牙医收藏管理、牙医评价管理、牙医挂号管理、用户管理、管理员管理等功能。牙科就诊管理系统的开发根据操作人员需要设计的界面简洁美观,在功能模块布局上跟同类型网站保持一致,程序在实现基本要求功能时,也为数据信息面临的安全问题提供了一些实用的解决方案。可以说该程序在帮助管理者高效率地处理工作事务的同时,也实现了数据信息的整体化,规范化与自动化。 管理员在后台主要管理病例管理、字典管理、公告管理、药单管理、药品管理、药品收藏管理、药品评价管理、药品订单管理、牙医管理、牙医收藏管理、牙医评价管理、牙医挂号管理、用户管理、管理员管理等。 牙医列表页面,此页面提供给管理员的功能有:查看牙医、新增牙医、修改牙医、删除牙医等。公告信息管理页面提供的功能操作有:新增公告,修改公告,删除公告操作。公告类型管理页面显示所有公告类型,在此页面既可以让管理员添加新的公告信息类型,也能对已有的公告类型信息执行编辑更新,失效的公告类型信息也能让管理员快速删除。药品管理页面,此页面提供给管理员的功能有:新增药品,修改药品,删除药品。药品类型管理页面,此页面提供给管理员的功能有:新增药品类型,修改药品类型,删除药品类型。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值