UVA 11020 - Efficient Solutions



Problem I
Efficient Solutions

Input: Standard Input

Output: Standard Output

"Our marriage ceremonies are solemn, sober
moments of reflection; also regret, disagreement,
argument and mutual recrimination. Once you know
it can't get any worse, you can relax and enjoy
the marriage."

J.Michael Straczynski, "The Deconstruction ofFalling Stars."

The princess of Centauri Prime isthe galaxy's most eligible bachelorette of the year.She has hopeful grooms lined up in front of the royal palace for a chance tospend 5 minutes to try and impress her. After 5 minutes, the gentleman iscarried out of the royal chambers by the palace guards, and the princess makesa decision. She rates the lad on his lineage and charm by giving him a scorefor each of the two properties. On Centauri Prime, low scores are better thanhigh scores.

Suppose that she observes twogentlemen - A and B. She assigns A the scores LA and CA(for lineage and charm, respectively). B receives scores LB and CB.Then A is dominated by B if either

  • LB < LA and CB <= CA, or
  • LB <= LA and CB < CA.

In other words, if at least oneof B's scores is better than A's, and the other score is not worse. Sheconsiders a gentleman to be efficient (or Pareto-optimal) if she has notyet met any other gentleman who dominates him. She maintains a list of efficient grooms and updates itafter each 5-minute presentation.

Given the queue of bachelors andthe scores assigned to them by the princess, determine the number of entries inthe list of efficient grooms aftereach performance.

Input
The first line of input gives the number ofcases, N (0<N<40). N test cases follow.

Each one starts with a linecontaining n (0≤n≤15000) - the size of the queue. Thenext n lines will each contain two scores (integers in the range [0, 109]).Initially, the list is empty.

Output
For each test case, output one line containing "Case #x:"followed by n lines, line i containing thesize of the list of efficient groomsafter the ith update. Print an empty linebetween test cases.

 

Sample Input

Sample Output

4
1
100 200
2
100 200
101 202
2
100 200
200 100
5
11 20
20 10
20 10
100 20
1 1
Case #1:
1
 
Case #2:
1
1
 
Case #3:
1
2
 
Case #4:
1
2
3
3
1

Problemsetter: Igor Naverniouk
Special Thanks: Yury Kholondyrev

 

Warming: The judge input file size is about 1.2 MB.


大白原题,就当了解下set的用处和用法。


#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
#include <string>
#include <map>
#include <cmath>
#include <queue>
#include <set>

using namespace std;

//#define WIN
#ifdef WIN
typedef __int64 LL;
#define iform "%I64d"
#define oform "%I64d\n"
#else
typedef long long LL;
#define iform "%lld"
#define oform "%lld\n"
#endif

#define S64I(a) scanf(iform, &(a))
#define P64I(a) printf(oform, (a))
#define FOR(i, s, t) for(int (i)=(s); (i)<(t); (i)++)

const int INF = 0x3f3f3f3f;
const double eps = 10e-9;
const double PI = (4.0*atan(1.0));

struct Node {
    int x, y;
    Node(int _x=0, int _y=0) {
        x = _x;
        y = _y;
    }
    bool operator < (const Node & b) const {
        return x != b.x ? x < b.x : y < b.y;
    }
};

multiset<Node> S;
multiset<Node>::iterator it;

int main() {
    int T;

    scanf("%d", &T);
    for(int kase=1; kase<=T; kase++) {
        if(kase != 1) putchar('\n');
        printf("Case #%d:\n", kase);
        int n;
        S.clear();
        scanf("%d", &n);
        while(n--) {
            int x, y;
            scanf("%d%d", &x, &y);
            Node t(x, y);
            it = S.lower_bound(t);
            if(it == S.begin() || (--it)->y > t.y) {
                S.insert(t);
                it = S.upper_bound(t);
                while(it != S.end() && it->y >= t.y) S.erase(it++);
            }
            printf("%d\n", (int)S.size());
        }
    }

    return 0;
}








  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值