buptoj 942:Lettree's Math Homework

时间限制 1000 ms  内存限制 65536 KB

题目描述

Little lettree is a middle school student who is clever but hates doing homework very much.
However, on this Qingming holiday, his math teacher assigned a lot of homework about fractions just like this:
Decomposite the fraction
 

(xa1)(xa2)...(xan)(xb1)(xb2)...(xbm)

 to this form:
 
c1xb1+c2xb2+...+cmxbm

 Clever lettree found that these are all repeat work and he need not calculate each fraction by himself. He just need a simple piece of computer program to do this.Now please help him do this simple work!

输入格式

Multiple test cases!

For each test case:

First line contains two integers  n,m(n<m6) , the amount of moleculars and denominators.
Second line contains n real numbers  ai  (Guarantee that  a1<a2<...<an 100<ai<100 ).
Third line contains m real numbers  bi  (Guarantee that  b1<b2<...<bm 100<bi<100 ).

Input ends with the end of file(EOF).

输出格式

For each test case,output one line of real numbers  ci ,accurate to 6 decimal places.


Hint
You should avoid  0.000000  in your output!

输入样例

2 3
4 50
12 50 76
2 4
58 73
30 44 72 78

输出样例

-0.125000 0.000000 1.125000
-0.042659 0.030462 0.001984
0.010212
数学太差。。。完全不会做,搜资料。找到一篇论文。http://www.math.wisc.edu/~park/Fall2011/integration/Partial%20Fraction.pdf

里面说的很清晰,f(x)/g(x)那里面的每一个Bi就是下面的xi-xj(i!=j)相乘做分母,然后xi带入f(x)做分子。

代码:

/*
USER_ID: test#299792458ms
PROBLEM: 942
SUBMISSION_TIME: 2016-03-21 16:03:50
*/
#pragma warning(disable:4996)
#include <iostream>
#include <functional>
#include <algorithm>
#include <cstring>
#include <vector>
#include <string>
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>
#include <deque>
#include <ctime>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
 
#define INF 0x33ffffff
 
#define eps 1e-6
const ll mod = 1000000007;
const int maxn = 505;
const double PI = acos(-1.0);
 
int n, m;
double a[10], b[10], c[10];
void solve()
{
    int i, j, k;
    double up, down;
    for (i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    for (i = 0; i < m; i++)
    {
        cin >> b[i];
    }
    for (i = 0; i < m; i++)
    {
        up = 1, down = 1;
        for (j = 0; j < n; j++)
        {
            up = up*(b[i] - a[j]);
        }
        for (j = 0; j < m; j++)
        {
            if (j == i)continue;
            down = down*(b[i] - b[j]);
        }
        c[i] = up / down;
        if (c[i] == -0.0)
            c[i] = 0.0;
        printf("%.6lf%c", c[i], i == m - 1 ? '\n' : ' ');
    }
 
}
 
int main()
{
#ifdef wangchong756 
    freopen("i.txt", "r", stdin);
    freopen("o.txt", "w", stdout);
    int time_wangchong756 = clock();
#endif
    while (scanf("%d%d", &n, &m) != EOF)
    {
        solve();
    }
 
    //system("pause");
    return 0;
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值