http://codeforces.com/contest/749/problem/D

题意:有几个人在拍卖场竞价,一共有n次喊价,有q个询问,每一个询问有一个num,接下来num个人从这次拍卖中除去,问对于每一个询问减掉num个人后是谁赢了拍卖,最小的价格是多少。

思路:昨晚不会做。想法好神奇(我太弱)。对于每个人用 set-S 装起来其每次喊价的下标,然后用一个数组order按价格从大到小的顺序将每个人装起来,对于每一个询问,把这num个人丢到一个 set-s 里面,然后在order里面找没出现过在 s 里面的,那么这个人 x 就是这场拍卖的胜者,那么还要考虑他喊的最低价格,将 x 也丢到 s 里面,再找一个 y,这个 y 是第二个大的,所以在 S[x] 里面二分找大于 y 喊过的最大价格就是答案了。

 #include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <iostream>
#include <stack>
#include <map>
#include <queue>
#include <set>
using namespace std;
typedef long long LL;
#define N 200010
#define INF 0x3f3f3f3f
bool vis[N];
int v[N][];
vector<int> order;
set<int> S[N]; int main()
{
int n;
cin >> n;
for(int i = ; i < n; i++) {
scanf("%d%d", &v[i][], &v[i][]);
S[v[i][]].insert(i);
}
for(int i = n - ; i >= ; i--) {
if(!vis[v[i][]]) {
vis[v[i][]] = ;
order.push_back(v[i][]);
}
}
int q;
cin >> q;
while(q--) {
set<int> s;
int num;
scanf("%d", &num);
while(num--) {
int k;
scanf("%d", &k);
s.insert(k);
}
int x = -, y = -;
for(int i = ; i < order.size(); i++) {
if(s.find(order[i]) == s.end()) {
x = order[i];
break;
}
}
if(x == -) puts("0 0");
else {
s.insert(x);
for(int i = ; i < order.size(); i++) {
if(s.find(order[i]) == s.end()) {
y = order[i];
break;
}
}
if(y == -) {
printf("%d %d\n", x, v[*S[x].begin()][]);
} else {
set<int>::iterator it = S[y].end();
int pos = *(--it);
it = S[x].upper_bound(pos);
printf("%d %d\n", x, v[*it][]);
}
}
}
return ;
}

Codeforces 749D:Leaving Auction(set+二分)的更多相关文章

  1. Codeforces 749D. Leaving Auction set+二分

    D. Leaving Auction time limit per test: 2 seconds memory limit per test:256 megabytes input:standard ...

  2. codeforces 749D Leaving Auction(二分)

    题目链接:http://codeforces.com/problemset/problem/749/D 题意:就是类似竞拍,然后报价肯定要比上一个高,然后查询输入k个数表示那些人的竞拍无效, 输出最后 ...

  3. CodeForces 749D Leaving Auction

    二分查找,$set$. 对于某一次询问,如果把人删光了,那么输出$0$ $0$. 如果只剩下$1$个人,那么输出那个人喊的最低价格. 如果剩下的人数有大于等于两个, 这时最底下出现的情景必然是红色部分 ...

  4. cf 749D Leaving Auction

    Leaving Auction time limit per test 2 seconds memory limit per test 256 megabytes input standard inp ...

  5. CF749D Leaving Auction set排序查找

    CodeForces 749D. Leaving Auction 传送门 There are n people taking part in auction today. The rules of a ...

  6. Leaving Auction

    Leaving Auction 题目链接:http://codeforces.com/contest/749/problem/D 二分 本来以为是哪种神奇的数据结构,没想到sort+lower_bon ...

  7. 【codeforces 749D】Leaving Auction

    [题目链接]:http://codeforces.com/problemset/problem/749/D [题意] 有n个人在竞价; 按照时间的顺序给出n次竞价(可能有一些人没有参加竞价); 每次竞 ...

  8. Leaving Auction CodeForces - 749D (set,贪心,模拟)

    大意: 若干个人参加拍卖会, 给定每个人出价顺序, 保证价格递增, q个询问, 给出k个人的编号, 求删除这k个人的所有出价后, 最终谁赢, 他最少出价多少. set维护每个人最后一次投票的时间, 每 ...

  9. Leaving Auction CF 749D

    题目:http://codeforces.com/problemset/problem/749/D 题目大意: 有n个人竞拍,也有n个叫牌,一个人可以有多个叫价牌,但也可能有一些人根本不叫价 每个叫牌 ...

随机推荐

  1. HDU1978 记忆化搜索

    How many ways Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Tot ...

  2. 测试常用SQL注入语句大全

    转载自Cracer,标题:<渗透常用SQL注入语句大全>,链接http://www.xxxx.com/?p=2226 1.判断有无注入点 整形参数判断 1.直接加' 2.and 1=1 3 ...

  3. iOS Core Animation

    1.什么是Core Animation? 它是一套包含图形绘制,投影,动画的OC类集合.它就是一个framework.通过CoreAnimation提供的接口,你可以方便完成自己所想要的动画. 2.我 ...

  4. Emule Xtreme Kid eD2K 设置

    设置udp和tcp端口: 测试结果必须为通过,若不通过, 1.请将主机ip丢入路由器DMZ区(设置将以上端口与本机ip地址绑定) 2.在windows防火墙中加入以上端口允许通行项 测试结果: 其它一 ...

  5. php中英字符串截取

    <?php @header('Content-type: text/html; charset=UTF-8'); function Ctruncate($str = '', $len = 0, ...

  6. IOS第二天多线程-01-延时执行

    **********延时执行 #import "HMViewController.h" @interface HMViewController () @end @implement ...

  7. 基于 ThinkPHP 3.2.3 的页面静态化功能的实现

    PHP 的页面静态化有多种实现方式,比如使用输出缓冲(output buffering),该种方式是把数据缓存在 PHP 的缓冲区(内存)中,下一次取数据时直接从缓冲区中读取数据,从而避免了脚本的编译 ...

  8. Mysql查看版本号的五种方式介绍

    Mysql查看版本号的五种方式介绍 作者: 字体:[增加 减小] 类型:转载 时间:2013-05-03   一.使用命令行模式进入mysql会看到最开始的提示符;二.命令行中使用status可以看到 ...

  9. 杂-lowbit

    int lowbit(int x){ )); } int lowbit(int x){ return x&-x; }

  10. MYSQL中创建存储过程实现向表中循环插入数据

    首先在test数据库中先创建一个表test: CREATE TABLE test( ID INT PRIMARY KEY AUTO_INCREMENT ,test_name VARCHAR(20),t ...