Codeforces 46D Parking Lot(貪心類比),codeforces46d

來源:互聯網
上載者:User

Codeforces 46D Parking Lot(貪心類比),codeforces46d
Codeforces 46D Parking Lot

題目連結

開線段樹專題開出了這題。。看似要用區間合并求連續最大區間,其實不需要。因為詢問才100個,直接set暴力去類比即可,每次車進來就從左往右找到一個合適位置

代碼:

#include <cstdio>#include <cstring>#include <set>using namespace std;const int N = 100005;int L, b, f, n;set<int> g;set<int>::iterator u, v;int save[N][2];int main() {scanf("%d%d%d", &L, &b, &f);scanf("%d", &n);g.insert(-b); g.insert(L + f);int op, x;for (int i = 1; i <= n; i++) {scanf("%d%d", &op, &x);if (op == 1) {int flag = 1;for (u = g.begin(); u != g.end(); u++) {v = u; v++;if (v != g.end() && *u + b + x + f <= *v) {g.insert(*u + b); g.insert(*u + b + x);save[i][0] = *u + b; save[i][1] = *u + b + x;printf("%d\n", *u + b);flag = 0;break;}u++;}if (flag) printf("-1\n");} else {g.erase(save[x][0]);g.erase(save[x][1]);}}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.