TIANKENG’s restaurant

來源:互聯網
上載者:User

標籤:acm   掃描   

題目連結

  • 題意:
    n組人,每組一行輸入:人數,到達時間,離開時間。問人數最多是多少(如果同一時刻有人到有人離開,那麼先讓人離開)
  • 分析:
    把一組人拆成兩個點,左端點和右端點,從左向右掃描。如果遇到一個左端點,加入集合中;如果遇到一個右端點,就把集合中對應的點刪去即可。
const int MAXN = 110000;struct Node{    int num, isr, id, time;    bool operator< (const Node& rhs) const    {        if (time != rhs.time)            return time < rhs.time;        return isr > rhs.isr;    }} ipt[MAXN];int main(){    int T, a, b, c, d, n, num;    RI(T);    FE(kase, 1, T)    {        RI(n);        REP(i, n)        {            scanf("%d %d:%d %d:%d", &num, &a, &b, &c, &d);            int x = i << 1, y = x | 1;            ipt[x].isr = 0;            ipt[x].time = a * 60 + b;            ipt[y].isr = 1;            ipt[y].time = c * 60 + d;            ipt[x].id = ipt[y].id = i;            ipt[x].num = ipt[y].num = num;        }        n <<= 1;        sort(ipt, ipt + n);        set<int> st;        int ans = 0, tans = 0;        REP(i, n)        {            if (ipt[i].isr)            {                st.erase(ipt[i].id);                tans -= ipt[i].num;            }            else            {                st.insert(ipt[i].id);                tans += ipt[i].num;            }            ans = max(ans, tans);        }        WI(ans);    }    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.