CF749D Leaving Auction
题目链接:
http://codeforces.com/problemset/problem/749/D
题目大意:
一场拍卖会,共n个买家。这些买家共出价n次,有的买家可能一次都没有出价。每次出价用(ai,bi)表示,ai为此次出价人的编号,bi为价格。出价严格递增(bi<bi+1)并且没有玩家在一轮竞拍中在没有其他竞争对手的情况下自动增加自己的出价(ai!=ai+1)。现在给定q次查询,每次去掉一些出价者及其所有出价,问最后谁是赢家并且他以什么价格赢得拍卖品。
解题思路:
首先预处理所有的出价,保存每个买家的出价序列,最高出价和最低出价。然后维护一个set。其中保存出价者id和他的出价序列中的最高出价maxn,整个set按照maxn从大到小的顺序排序。对于每次查询,从set中删掉出局的人,如果此时set大小为0,输出“0 0”;大小为1,则只有一个买家,他赢得了拍卖品且价格为他的所有出价中的最小值;否则找maxn最高的人和第二高的人。最终的价格应该是在maxn最高的人的出价序列中比maxn第二高的人的最高出价高一点点的值。考虑到是有序的,二分即可。之后不要忘了把之前剔除掉的人再insert回来。
开始时我在set的每个节点中保存了相应买家的出价序列,结果T了很多次,真是被自己蠢哭了......
代码:
#include <iostream>
#include <cstdio>
#include <vector>
#include <set>
#include <algorithm>
#include <cstring>
using namespace std;
const int INF = 0x3f3f3f3f;
vector<int> G[];
int n, a, b;
int maxn[];
int minn[];
int d[];
int max(int a, int b)
{
return a > b ? a : b;
}
int min(int a, int b)
{
return a < b ? a : b;
}
struct node
{
int index;
int maxn;
};
struct cmp
{
bool operator ()(const node & a, const node & b)const
{
return a.maxn > b.maxn;
}
};
int main()
{
cin >> n;
memset(minn, 0x3f, sizeof(minn));
for (int i = ; i < n; i++)
{
scanf("%d %d", &a, &b);
G[a].push_back(b);
maxn[a] = max(maxn[a], b);
minn[a] = min(minn[a], b);
}
set<node, cmp> s;
for (int i = ; i <= n; i++)
{
if (G[i].size())
{
node tmp;
tmp.index = i;
tmp.maxn = maxn[i];
s.insert(tmp);
}
}
int T, x;
cin >> T;
for (int i = ; i < T; i++)
{
scanf("%d", &x);
for (int j = ; j < x; j++)
{
scanf("%d", &d[j]);
node t;
t.index = d[j];
t.maxn = maxn[d[j]];
s.erase(t);
}
if (s.size() == )
{
puts("0 0");
}
else if (s.size() == )
{
printf("%d %d\n", s.begin()->index, minn[s.begin()->index]);
}
else
{
set<node, cmp>::iterator t = s.begin();
node y;
y.index = t->index;
y.maxn = t->maxn;
s.erase(s.begin());
set<node, cmp>::iterator t2 = s.begin();
vector<int>::iterator it;
it = upper_bound(G[t->index].begin(), G[t->index].end(), t2->maxn);
if (it != G[t->index].end())
{
printf("%d %d\n", y.index, *it);
}
else
{
puts("0 0");
}
s.insert(y);
}
for (int j = ; j < x; j++)
{
node t;
t.index = d[j];
t.maxn = maxn[d[j]];
if (G[t.index].size())
s.insert(t);
}
}
return ;
}
CF749D Leaving Auction的更多相关文章
- CF749D Leaving Auction set排序查找
CodeForces 749D. Leaving Auction 传送门 There are n people taking part in auction today. The rules of a ...
- Leaving Auction
Leaving Auction 题目链接:http://codeforces.com/contest/749/problem/D 二分 本来以为是哪种神奇的数据结构,没想到sort+lower_bon ...
- Codeforces 749D. Leaving Auction set+二分
D. Leaving Auction time limit per test: 2 seconds memory limit per test:256 megabytes input:standard ...
- cf 749D Leaving Auction
Leaving Auction time limit per test 2 seconds memory limit per test 256 megabytes input standard inp ...
- Codeforces 749D:Leaving Auction(set+二分)
http://codeforces.com/contest/749/problem/D 题意:有几个人在拍卖场竞价,一共有n次喊价,有q个询问,每一个询问有一个num,接下来num个人从这次拍卖中除去 ...
- CodeForces 749D Leaving Auction
二分查找,$set$. 对于某一次询问,如果把人删光了,那么输出$0$ $0$. 如果只剩下$1$个人,那么输出那个人喊的最低价格. 如果剩下的人数有大于等于两个, 这时最底下出现的情景必然是红色部分 ...
- Leaving Auction CF 749D
题目:http://codeforces.com/problemset/problem/749/D 题目大意: 有n个人竞拍,也有n个叫牌,一个人可以有多个叫价牌,但也可能有一些人根本不叫价 每个叫牌 ...
- D. Leaving Auction 一题很好的思维题
http://codeforces.com/contest/749/problem/D 现在发现做题要把样例抄下来,然后画一画,这样才容易发现新大陆.嗯,以后做题就这样. 如果排除了被删除了的人,那么 ...
- 【codeforces 749D】Leaving Auction
[题目链接]:http://codeforces.com/problemset/problem/749/D [题意] 有n个人在竞价; 按照时间的顺序给出n次竞价(可能有一些人没有参加竞价); 每次竞 ...
随机推荐
- 附录: mysql show processlist中的State的意义
附录: mysql show processlist中的State的意义 Checking table 正在检查数据表(这是自动的). Closing tables 正在将表中修改的数据刷新到磁盘中, ...
- 数据库DCL、DDL、DML、DQL
SQL三部分:data manipulation language DCL: (控制)管理用户权限(GRANT.REVOKE),数据库整体配置 DDL: (定义)作用于数据库,表, ...
- ref 与 $refs 如何关联
先问大家一个简单的问题: 还有人记得 jquery 里面的 data 方法是如何让 DOM 节点绑定对应的数据对象的吗 有时候我们做节点关联设计的思路其实有一点类似,但是在 vue 里面多了很多概念, ...
- GPS常见故障
当出现故障时,依据可能原因进行排查. 下表列举典型故障及调试方法 现象 root cause 检查 实验 GPS无法开启/无法搜星 软件配置错误 SW 相关配置(如GPIO等) 录制mobile ...
- JS点击查看更多内容 控制段落文字展开折叠
JavaScript+jQuery实现的文字展开折叠效果,点击文字后文字内容会完整的显示出来,控制段落来显示文字,不需要的时候,可以再次点击后将内容折叠起来,也就是隐藏了一部分内容.点击查看更多的功能 ...
- 关于View转化成bitmap保存成图片
产品今天说项目分享时要分享出一张 封面图片 + 几行文字 + 二维码图片 的图片. 思索了一下 封面图片和二维码图片让后台给接口得到地址, 主要还是找个方式得到一个包含这些内容的图片.于是就想能不能 ...
- [SoapUI] Read data from response , use it to update parameter
import com.eviware.soapui.support.GroovyUtils def groovyUtils = new GroovyUtils( context ) def holde ...
- MultiAutoCompleteTextView
Activity_mian.xml <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android&qu ...
- Ruby: Print WIN32OLE method names in Ruby
class WIN32OLE def list_ole_methods method_names = ole_methods.collect {|m| m.name} puts m ...
- 安装Nginx作为文件服务器
我是在Windows上安装的,在Linux上也一样 #Windows server2008 R2 #Nginx1.12 Nginx安装包下载地址:http://nginx.org/en/downloa ...