文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>1045.分段线性插值

1045.分段线性插值

时间:2010-11-11  来源:gzzcracker

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <map>
using namespace std;

int main(int argc, char* argv[]) {
    map<int, int> mp;
    map<int, int>::iterator it;
    double x0, y0, x1, y1, ans;
    int n, x, y;
    char ch;

    mp[-1000000000] = 0;
    mp[1000000000] = 0;

    scanf("%d", &n);
    while (n--) {
        scanf(" %c", &ch);
        if (ch == 'A') {
            scanf("%d %d", &x, &y);
            mp[x] = y;
        } else {
            scanf("%d", &x);
            if (mp.find(x) != mp.end()) {
                ans = mp[x];
            } else {
                it = mp.upper_bound(x);
                x1 = it->first;
                y1 = it->second;
                it--;
                x0 = it->first;
                y0 = it->second;
                ans = y0 * (x - x1) / (x0 - x1) + y1 * (x - x0) / (x1 - x0);
            }
            printf("%.6f\n", ans);
        }
    }

    return 0;
}


相关阅读 更多 +
排行榜 更多 +
辰域智控app

辰域智控app

系统工具 下载
网医联盟app

网医联盟app

运动健身 下载
汇丰汇选App

汇丰汇选App

金融理财 下载