UVa11020 · Efficient Solutions

题目:http://uva.onlinejudge.org/external/110/11020.pdf

Problem IEfficient 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 of Falling Stars."

The princess of Centauri Prime is the galaxy‘s most eligible bachelorette of the year. She has hopeful grooms lined up in front of the royal palace for a chance to spend 5 minutes to try and impress her. After 5 minutes, the gentleman is carried out of the royal chambers by the palace guards, and the princess makes a decision. She rates the lad on his lineage and charm by giving him a score for each of the two properties. On Centauri Prime, low scores are better than high scores.

Suppose that she observes two gentlemen - 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 one of B‘s scores is better than A‘s, and the other score is not worse. She considers a gentleman to be efficient (or Pareto-optimal) if she has not yet met any other gentleman who dominates him. She maintains a list of efficient grooms and updates it after each 5-minute presentation.

Given the queue of bachelors and the scores assigned to them by the princess, determine the number of entries in the list of efficient groomsafter each performance.

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

Each one starts with a line containing n (0≤n≤15000) - the size of the queue. The next 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 the size of the list of efficient grooms after the ithupdate. Print an empty line between 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.

做法:STL太神了。。学了set及multiset的一些用法,这题用multiset维护,很裸,马上就学treap啦。。

UVa11020 · Efficient Solutions

时间: 2024-12-19 10:14:42

UVa11020 · Efficient Solutions的相关文章

UVA 11020 - Efficient Solutions(set)

UVA 11020 - Efficient Solutions 题目链接 题意:每个人有两个属性值(x, y),对于每一个人(x,y)而言,当有另一个人(x', y'),如果他们的属性值满足x' < x, y' <= y或x' <= x, y' < y的话,这个人会失去优势,每次添加一个人,并输出当前优势人个数 思路:由于每个人失去优势后,不可能再得到优势,所以失去优势就可以当成删去这些点,这样的话,就可以用一个multiset来维护点集,每次加入一个点,利用lowerbound,

UVA - 11020 - Efficient Solutions (multiset实现BST)

Efficient Solutions 题目传送:Efficient Solutions AC代码: #include <map> #include <set> #include <cmath> #include <deque> #include <queue> #include <stack> #include <cstdio> #include <cctype> #include <string>

uva 11020 Efficient Solutions

题意:给你n个人,有两个属性x.y,如果不存在另外一个人x2,y2满足 x2<=x,y2<y 或者 x2<x,y2<=y,那么就称这个人是有优势的,每次给你一个人得信息,问你当前有优势的人的人数是多少? 思路:刘汝佳训练指南P228 mutiset+lower_bound+upper_bound 1 #include<cstdio> 2 #include<cstring> 3 #include<algorithm> 4 #include<s

UVA 110020 Efficient Solutions (STL)

把一个人看出一个二维的点,优势的点就是就原点为左下角,这个点为右上角的矩形,包含除了右上角以外边界,其他任意地方不存在点. 那么所有有优势的点将会形成一条下凹的曲线. 因为可能有重点,用multiset,按照x优先,相同时再比较y的顺序排序,动态维护满足条件的总人数. 当新加的P点的y坐标大于左边的点的时候没有优势,忽略,用lower_bound判断一下. 当新加的P点有优势,但是可能使得其他的的点失去优势,依次把后面的点不满足条件的点删除. 红黑树好复杂. #include<bits/stdc

UVA - 11020 Efficient Solutions(Multiset)

本题利用multiset解决.根据题意,如果我们用P(x,y)表示一个人,因为人可以相同,所以用multiset.我们会发现,如果所有人群都是有优势的,那么这些点呈现一个递减的趋势.如果刚刚插入一个人,他是否有优势该如何判断呢?只需要看他左边相邻的点的y坐标是否比他小即可.而如果这个人是有优势的,那么需要先把这个人插入到集合中,然后从upper_bound(P)开始,逐个删除没有优势的点,注意删除时候应写为s.erase(it++),因为删除时候会导致指针向左移动一位,因此还需要it++.这样,

UVA 11020 Efficient Solutions+multiset的应用

题目链接:点击进入 首先来讲,很容易看到我们其实只要维护优势人群的集合:如果加入一个新的人,我们首先看一下优势人群中是否有人会让这个人失去优势,如果没有,则将这个人插入集合中,但要注意到这个人的插入可能会让其它的人失去优势.所以要求这个集合要能支持快速查询和修改操作:而multiset恰好能能满足这个需要. 代码如下: #include<iostream> #include<cstdio> #include<cstring> #include<set> us

算法范式

算法:按步骤解决问题的过程. An algorithm is a step-by-step procedure for solving a problem. 范式:思考问题的模式. "Pattern of thought" which governs scientific apprehension during a certain period of time. 算法范式:为问题构建高效解决方案的常规方法. General approaches to the construction

Numbering Paths (Uva 125 floyd+dp思想)

Numbering Paths Time Limit: 3000MS   Memory Limit: Unknown   64bit IO Format: %lld & %llu Submit Status Description Background Problems that process input and generate a simple ``yes'' or ``no'' answer are called decision problems. One class of decis

Natively Compiled Code: A Comeback?

RAD Studio and Natively Compiled Code In today's development landscape, natively compiled code is making a significant comeback. RAD Studio has always been focused on it. In today's development landscape, natively compiled code is making a significan