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次竞价(可能有一些人没有参加竞价); 每次竞 ...
随机推荐
- sublime text2 相关插件及其应用
一.常见的插件 1.Emmet 'ctrl+up':切换文件: "ctrl+alt+enter":创建新的div标签: "shift+ctrl+." :查找相同 ...
- java的数字精确计算问题-BigDecimal
java的数字运算,偶尔会出现精度的问题,以下阐述的 java的BigDecimal类的使用. 例如: System.out.println(0.9+0.3); 结果1.2 System.out.pr ...
- linux防火墙过滤规则
一.linux防火墙基础 防火墙分为硬件防火墙和软件防火墙. 1.概述 linux 防火墙体系主要工作在网络层,针对TCP/IP数据包实施过滤和限制,属于典型的包过滤防火墙. 包过滤机制:netfil ...
- maven实战(2)-- m2eclipse插件配置
使用eclipse进行maven项目的开发,需要安装m2eclipse插件.下面介绍该插件的配置,插件的安装在此不作介绍. 配置m2eclipse 先决条件:已安装maven,m2eclipse 以上 ...
- ng 表单提交验证
http://www.runoob.com/try/try.php?filename=try_ng_validate
- IOCP编程小结(中)
上一篇主要谈了一些基本理念,本篇将谈谈我个人总结的一些IOCP编程技巧. 网络游戏前端服务器的需求和设计 首先介绍一下这个服务器的技术背景.在分布式网络游戏服务器中,前端连接服务器是一种很常见的设计. ...
- 【旧文章搬运】CsrssWalker学习笔记
原文发表于百度空间及看雪论坛,2009-05-13 看雪论坛地址:https://bbs.pediy.com/thread-89708.htm============================= ...
- 关于cout输出精度问题
#include <iostream.h> #include <iomanip.h> void main(void) { cout.setf(ios::fixed); cout ...
- linux中vfork对打开文件的处理
vfork和fork fork()函数是拷贝一个父进程的副本,拥有独立的代码段 数据段 堆栈空间 然而vfork是共享父亲进程的代码以及代码段 vfork是可以根据需要复制父进程空间,这样很大程度的提 ...
- MongoDb 本机删除密码的方法
Terminal Inflection LINUX ESOTERICA, FIXES AND RANTS About Errors Resolved Linux Recommended Books W ...