TOJ4439微积分――曲线积分(数学,模拟)

传送门:点我

格林公式P,Q为关于x,y的函数。

现在为了方便起见,现给出x的积分上限1,积分下限0, y的积分上限x,积分下限0。

P只是关于Y的函数,Q只是关于X的函数。

输入

开始输入为测试组数n。每一组的开始输入Q的项数q和Q关于X的系数以及指数。接下来是P的多项式的项数p和P的关于Y的系数以及指数。

p<= 100, q <= 100。注意:指数是正整数,系数不为 0。

输出

每一组输出为一行,保留两位小数。

样例输入

2

1
2 2
1
3 3

2
1 1
2 2
2
1 1
2 2

样例输出

0.58
0.67

思路:

本质是套公式计算算偏导数

例如样例中第一个数据Q=2x^2,P=3y^3.

代入公式计算的就是

中间是4x-9y^2的原因:根据格林公式中,对Q求关于x的偏导,对P求对于y的偏导,两式相减得到4x-9y^2。

计算过程:

7/12 写成小数保留2位就是0.58

因此就模拟求导积分的过程就行了,因为上界下届都给定了,我套了个map存指数对应的系数(注意系数要用double)

代码:

#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <utility>
#include <bitset>
#define LL long long
#define pb push_back
#define mk make_pair
#define pill pair<int, int>
#define mst(a, b)    memset(a, b, sizeof a)
#define REP(i, x, n)    for(int i = x; i <= n; ++i)
#define pi acos(-1.0)
#define Max_N 1001
#define  inf 0x3f3f3f3f
#define N 1001
#define ll long long
using namespace std;
int main(){
     int _;
    for(scanf("%d",&_);_--;){
        int n;scanf("%d",&n);
        map<int,double>mp;
        while(n--){
            int x;double a;
            scanf("%lf%d",&a,&x);
            a*=x;
            x-=1;//求导 
            mp[x+1] += a;//积分之后乘以x 
        }
        int m;
        scanf("%d",&m);
        while(m--){
            int x;double a;
            scanf("%lf%d",&a,&x);
            mp[x] -= a;
        }
        double ans = 0;
        map<int,double>::iterator it = mp.begin();
        for(;it != mp.end() ;it++){
            double xi = it->second;
            int zhi = it->first;
            ans += xi/(1.0*(zhi+1));
        }
        printf("%.2lf\n",ans);
    }
}
/*
2
2
1 1
2 2
2
1 1
2 2
*/

猜你喜欢

转载自www.cnblogs.com/Esquecer/p/10307452.html