UVA 11020,uva11020

來源:互聯網
上載者:User

UVA 11020,uva11020
UVA 11020 - Efficient Solutions

題目連結

題意:每個人有兩個屬性值(x, y),對於每一個人(x,y)而言,當有另一個人(x', y'),如果他們的屬性值滿足x' < x, y' <= y或x' <= x, y' < y的話,這個人會失去優勢,每次添加一個人,並輸出當前優勢人個數

思路:由於每個人失去優勢後,不可能再得到優勢,所以失去優勢就可以當成刪去這些點,這樣的話,就可以用一個multiset來維護點集,每次加入一個點,利用lowerbound,upper_bound二分尋找旁邊點的位置來進行判斷和刪點

代碼:

#include <cstdio>#include <cstring>#include <iostream>#include <set>using namespace std;int t, n;struct Point {    int x, y;    bool operator < (const Point &c) const {if (x == c.x) return y < c.y;return x < c.x;    }};multiset<Point> s;multiset<Point>::iterator it;int main() {    int cas = 0;    cin >> t;    while (t--) {s.clear();cin >> n;Point u;cout << "Case #" << ++cas << ":" << endl;while (n--) {    cin >> u.x >> u.y;    it = s.lower_bound(u);    if (it == s.begin() || (--it)->y > u.y) {s.insert(u);it = s.upper_bound(u);while (it != s.end() && it->y >= u.y) s.erase(it++);    }    cout << s.size() << endl;}if (t) cout << endl;    }    return 0;}





聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.