zoukankan      html  css  js  c++  java
  • POJ 多项式加法

    题解:

            采用顺序表。考虑到题目中没有规定指数上界,为避免RE,拟不采用数组。参考了http://blog.csdn.net/inlovecy/article/details/15208473后,最终采用map。

    源码:

    #include <iostream>
    #include <map>
    using namespace std;
    
    int main()
    {
        int n;
        cin >> n;
        while (n--) {
            int exp = 0, t1, t2, c = 2;
            bool flg = false;
            map<int, int>ep;
            while (c--) 
                while (cin >> t1 >> t2) {
                    if (t2 < 0) break;
                    if (ep.find(t2) != ep.end())ep[t2] += t1;
                    else ep.insert(make_pair(t2, t1));
                }
            for (map<int, int>::reverse_iterator it = ep.rbegin(); it != ep.rend(); it++) {
                if (it->second == 0)continue;
                cout << "[ " << it->second << " " << it->first << " ] ";
                flg = true;
            }
            if(flg) cout << endl;
        }
        return 0;
    }
  • 相关阅读:
    17111 Football team
    Train Problem I (HDU 100题纪念)
    迷宫问题
    图形点扫描
    看病要排队(stl)
    水果
    Prime Ring Problem
    N皇后问题
    2^x mod n = 1
    Queuing
  • 原文地址:https://www.cnblogs.com/Jeffrey-Y/p/9279898.html
Copyright © 2011-2022 走看看