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优化----explain的列分析
sql语句优化: : sql语句的时间花在哪儿? 答: 等待时间 , 执行时间. 等待时间:看是不是被锁住了,那就不是语句层面了是服务端层面了,看连接数内存. 执行时间:到底取出多少行,一次性取出1万 ...
- sjtu oj 1201. SuperXOR
Description Pangzi recently realized that bitwise XOR operation is just an addition without carries. ...
- 多线程、死锁、线程安全、同步方法、代码块、休眠、守护线程、Thread、Runnable(二十三)
1.多线程的引入 * 1.什么是线程 * 线程是程序执行的一条路径, 一个进程中可以包含多条线程 * 多线程并发执行可以提高程序的效率, 可以同时完成多项工作* 2.多线程的应用场景 * 红蜘蛛同时共 ...
- Scrapy爬虫报错:ModuleNotFoundError: No module named 'win32api'
运行 scrapy crawl douban_spider 出现报错: 解决办法:安装pywin32,下载适配安装的Python版本(64位,Python3.6) 下载地址: https://sour ...
- WPF 之Converter
WPF 之Converter Leo 在我们做项目的时候,经常会遇见这样的事情: 在数据中我们定义的是true,false 而在现实的时候则可能要求男,女 我们还得能定义成了0,1,2,3,4,5, ...
- 四叉树 bnuoj
点击打开题目链接 建树+广搜一棵树:最下面有更短代码(很巧妙). #include<iostream> #include<stdio.h> #include<queue& ...
- c++11实现DLL帮助类
用过DLL的人都会发现,在C++中调用dll中的函数有点繁琐,调用过程如下:在加载dll后还要定义一个对应的函数指针类型,接着调用GetProcAddress获取函数地址,再转成函数指针,最后调用函数 ...
- BZOJ_1563_[NOI2009]诗人小G_决策单调性
BZOJ_1563_[NOI2009]诗人小G_决策单调性 Description Input Output 对于每组数据,若最小的不协调度不超过1018,则第一行一个数表示不协调度若最小的不协调度超 ...
- LINUX-进程的概念
计算机中,CPU是最宝贵的资源,为了提高CPU的利用率,引入了多道程序设计的概念.当内存中多个程序存在时,如果不对人们熟悉的“程序”的概念加以扩充,就无法刻画多个程序共同运行时系统呈现出的特征. 一. ...
- HBase之一:HBase原理和设计
一.简介 HBase —— Hadoop Database的简称,Google BigTable的另一种开源实现方式,从问世之初,就为了解决用大量廉价的机器高速存取海量数据.实现数据分布式存储提供可靠 ...