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

时间:2022-06-13 04:14:07

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

set维护每个人最后一次投票的时间, 每次询问直接暴力找到最后一个未删除的, 假设为$x$, 那么$x$就是最后赢家, 求最少出价的话, 只要$x$的出价大于$x$之前一位的最大出价即可.

#include <iostream>
#include <sstream>
#include <algorithm>
#include <cstdio>
#include <math.h>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <string.h>
#include <bitset>
#define REP(i,a,n) for(int i=a;i<=n;++i)
#define PER(i,a,n) for(int i=n;i>=a;--i)
#define hr putchar(10)
#define pb push_back
#define lc (o<<1)
#define rc (lc|1)
#define mid ((l+r)>>1)
#define ls lc,l,mid
#define rs rc,mid+1,r
#define x first
#define y second
#define io std::ios::sync_with_stdio(false)
#define endl '\n'
#define DB(a) ({REP(__i,1,n) cout<<a[__i]<<' ';hr;})
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int P = 1e9+7, INF = 0x3f3f3f3f;
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll qpow(ll a,ll n) {ll r=1%P;for (a%=P;n;a=a*a%P,n>>=1)if(n&1)r=r*a%P;return r;}
ll inv(ll x){return x<=1?1:inv(P%x)*(P-P/x)%P;}
inline int rd() {int x=0;char p=getchar();while(p<'0'||p>'9')p=getchar();while(p>='0'&&p<='9')x=x*10+p-'0',p=getchar();return x;}
//head const int N = 1e6+10;
int m, n, a[N], b[N], pos[N], no[N];
set<int> c[N]; int main() {
scanf("%d", &n);
REP(i,1,n) {
scanf("%d%d", a+i, b+i);
pos[a[i]] = i;
no[i] = a[i];
c[a[i]].insert(b[i]);
}
set<int,greater<int> > q;
REP(i,1,n) if (pos[i]) q.insert(pos[i]);
scanf("%d", &m);
REP(i,1,m) {
int k, t;
scanf("%d", &k);
set<int> del;
REP(i,1,k) scanf("%d", &t),del.insert(t);
int x = 0;
for (auto &&t:q) if (!del.count(no[t])) {
x = no[t];
del.insert(x);
break;
}
if (!x) {puts("0 0"); continue;}
int y = 0;
for (auto &&t:q) if (!del.count(no[t])) {
y = no[t];
break;
}
if (!y) printf("%d %d\n", x, *c[x].begin());
else {
int w = *(--c[y].end());
printf("%d %d\n", x, *c[x].lower_bound(w));
}
}
}

Leaving Auction CodeForces - 749D (set,贪心,模拟)的更多相关文章

  1. Leaving Auction CF 749D

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

  2. Codeforces 950C Zebras &lpar; 贪心 &amp&semi;&amp&semi; 模拟 &rpar;

    题意 : 给出一个 01 串,要求你将其分隔出若干个子序列 ( 每个数字只能属于某一个子序列 ) ,子序列必须满足由 0 开头和结尾,且中间需 01 交替构成.若无法做到,则输出 -1. 分析 :  ...

  3. CodeForces 6C(贪心 &plus; 模拟)

    题目链接 思路如下 贪心的思想,⚠️女士优先的策略,当它们吃掉之前的物品所用的时间相同的时候,此时女士先开始 继续吃 题解如下 #include<iostream> using names ...

  4. Codeforces 749D&period; Leaving Auction set&plus;二分

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

  5. 贪心&plus;模拟 Codeforces Round &num;288 &lpar;Div&period; 2&rpar; C&period; Anya and Ghosts

    题目传送门 /* 贪心 + 模拟:首先,如果蜡烛的燃烧时间小于最少需要点燃的蜡烛数一定是-1(蜡烛是1秒点一支), num[g[i]]记录每个鬼访问时已点燃的蜡烛数,若不够,tmp为还需要的蜡烛数, ...

  6. CodeForces ---596B--Wilbur and Array&lpar;贪心模拟&rpar;

    Wilbur and Array Time Limit: 2000MS   Memory Limit: 262144KB   64bit IO Format: %I64d & %I64u Su ...

  7. cf 749D Leaving Auction

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

  8. CF749D Leaving Auction set排序查找

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

  9. Leaving Auction

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

随机推荐

  1. getEnhancedMicrophone 方法

    [转]http://www.cnblogs.com/iBlogger/archive/2011/11/16/2251847.html Flex 4.6 SDK 提供了 getEnhancedMicro ...

  2. zookeeper入门学习

    1.基本概念 ZooKeeper是一个分布式的,开放源码的分布式应用程序协调服务,是Google的Chubby一个开源的实现,是Hadoop和Hbase的重要组件.它是一个为分布式应用提供一致性服务的 ...

  3. &lbrack;HTML&rsqb;HTML5实现可编辑表格

    HTML5实现的简单的可编辑表格 [HTML]代码 <!DOCTYPE html > <html > <head> <meta charset="u ...

  4. 【转】 IOS 项目配置--构建输出DIR

    原文网址:http://blog.csdn.net/fengsh998/article/details/8868871 通常在情一般都不建议使用绝对路径,因为写死之后,换环境,换平台,又要重新修改路径 ...

  5. delphi TToolBar

    工具栏  的属性 xe4的事件 Customizable OnCustomizeCanDelete OnCustomizeCanInsert OnCustomized OnCustomizeAdded ...

  6. AtCoder Beginner Contest 071 D - Coloring Dominoes

    Problem Statement We have a board with a 2×N grid. Snuke covered the board with N dominoes without o ...

  7. ISP PIPLINE &lpar;十四&rpar; AE&lpar;自动曝光&rpar;

    自动曝光可以可以通过调节 模拟增益,数字增益,曝光时间,光圈大小来调剂曝光. 曝光在ISP PIPLINE的位置. (先介绍一个额外的知识点: ) gamma compression(也就是de-ga ...

  8. CentOS 搭建git服务

    git服务器的搭建是非常简单的. 1. 安装git yum install git 2. 创建用户git groupadd git adduser git -g git passwd git 3. 创 ...

  9. js获取url参数值,并解决中文乱码

    <script type="text/javascript"> function GetQueryString(name) { var reg = new RegExp ...

  10. 在Linux下配置jdk的环境变量

    jdk下载地址: http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html 在根目录新建s ...