• L2018 多项式A除以B


    #include <bits/stdc++.h>
    
    using namespace std;
    
    #define e first
    #define c second
    constexpr double eps = 1e-8;
    
    int main() {
        int n;
        cin >> n;
        map<int, double> q;
        int mx;
        for (int i = 0; i < n; i++) {
            int e, c;
            cin >> e >> c;
            q[e] = c;
            if (i == 0) mx = e;
        }
        int m;
        cin >> m;
        vector<pair<int, double>> y(m);
        for (int i = 0; i < m; i++) {
            cin >> y[i].e >> y[i].c;
        }
        vector<pair<int, double>> res;
        while (mx >= y[0].e) {
            double change = q[mx] / y[0].c;
            int diff = mx - y[0].e;
            if (fabs(change) >= 0.05) {
                res.push_back({diff, change});
                for (int i = 0; i < m; i++) {
                    q[y[i].e + diff] -= change * y[i].c;
                }
    
            } else mx--;
            while (mx >= y[0].e && fabs(q[mx]) < 0.05) mx--;
        }
    
        cout << res.size();
        if (res.empty()) cout << " 0 0.0";
        for (int i = 0; i < res.size(); i++) {
              printf(" %d %.1f", res[i].e, res[i].c);
        }
        puts("");
        res.clear();
        while (mx >= 0) {
            if (fabs(q[mx]) >= 0.05) {
                res.push_back({mx, q[mx]});
            }
            mx--;
        }
        cout << res.size();
        if (res.empty()) cout << " 0 0.0";
        for (int i = 0; i < res.size(); i++) {
            printf(" %d %.1f",res[i].e,res[i].c);
        }
    
        return 0;
    }
    
    
  • 相关阅读:
    内存分配问题
    C++ assert 的一点说明
    强大的stringstream
    C++中随机数
    C++ 中new
    C++ 中string 详解 转载自 博客园
    未命名名字空间
    使用ifstream和getline读取文件内容[c++]
    6.bootstrap练习笔记-缩略图和list-group
    3.bootstrap练习笔记-媒体内容
  • 原文地址:https://www.cnblogs.com/ZhengLijie/p/16026201.html
Copyright © 2020-2023  润新知