Leaving Auction CodeForces - 749D (set,贪心,模拟)
大意: 若干个人参加拍卖会, 给定每个人出价顺序, 保证价格递增, 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,贪心,模拟)的更多相关文章
- Leaving Auction CF 749D
题目:http://codeforces.com/problemset/problem/749/D 题目大意: 有n个人竞拍,也有n个叫牌,一个人可以有多个叫价牌,但也可能有一些人根本不叫价 每个叫牌 ...
- Codeforces 950C Zebras ( 贪心 && 模拟 )
题意 : 给出一个 01 串,要求你将其分隔出若干个子序列 ( 每个数字只能属于某一个子序列 ) ,子序列必须满足由 0 开头和结尾,且中间需 01 交替构成.若无法做到,则输出 -1. 分析 : ...
- CodeForces 6C(贪心 + 模拟)
题目链接 思路如下 贪心的思想,⚠️女士优先的策略,当它们吃掉之前的物品所用的时间相同的时候,此时女士先开始 继续吃 题解如下 #include<iostream> using names ...
- Codeforces 749D. Leaving Auction set+二分
D. Leaving Auction time limit per test: 2 seconds memory limit per test:256 megabytes input:standard ...
- 贪心+模拟 Codeforces Round #288 (Div. 2) C. Anya and Ghosts
题目传送门 /* 贪心 + 模拟:首先,如果蜡烛的燃烧时间小于最少需要点燃的蜡烛数一定是-1(蜡烛是1秒点一支), num[g[i]]记录每个鬼访问时已点燃的蜡烛数,若不够,tmp为还需要的蜡烛数, ...
- CodeForces ---596B--Wilbur and Array(贪心模拟)
Wilbur and Array Time Limit: 2000MS Memory Limit: 262144KB 64bit IO Format: %I64d & %I64u Su ...
- cf 749D Leaving Auction
Leaving Auction time limit per test 2 seconds memory limit per test 256 megabytes input standard inp ...
- 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 ...
随机推荐
- selenium实现chrome分屏截图的合并
selenium的截图功能在chrome下无法实现,但是可以操作滚动条来一屏一屏的截图,然后再合并成一张图,合并图片的代码在网上找的,十分感谢那位朋友,具体解决方案如下:直接上代码: def capt ...
- XSS这段时间的学习总结
0X01利用平台payload获取COOKIE 本机IP 192.168.1.100 靶机win7 192.168.1.102 我们先创建一个cookie的项目 然后在可以执行xss的地方插入我们的恶 ...
- C++入门经典-例5.17-右值引用的定义
1:右值引用的定义: 类型 && i=被引用的对象: 左值与右值的区别在于,右值是临时变量,例如,函数的返回值,并且无法被改变. 当右值引用被初始化后,临时变量消失. 代码如下: // ...
- lyf基础作业
include <stdio.h> include <stdlib.h> int main (void) { FILE * fp; int a[10]; int max=0; ...
- Tracer使用
1.选择event List可以迅速完成操作,而选择simulation就会一步一步地执行操作,但是如果都点了下方的Delete删了记录的话,所有的机器都是该整个流程执行完毕的结果.
- java特殊运算符
按位运算符 定义:按位运算符是来操作整数基本数据类型中的单个“比特”(bit),即二进制位,位运算符会对两个参数中对应的位执行布尔代数运算,并最终生成一个结果. 分类:与(&).或(|).异或 ...
- centos6.4编译gcc6.4
#!/bin/bash dir=$(pwd) echo $dir cd $dir #wget https://gmplib.org/download/gmp/gmp-6.1.2.tar.xz .tar ...
- 一、基础篇--1.2Java集合-ArrayList和Vector的区别
ArrayList和Vector的区别 ArrayList和Vector都是基于动态数组实现的. 区别 ArrayList是非线程安全的,Vector是线程安全的. Vector的方法都加了同步锁 ...
- gromacs2018使用踩坑记--insert-molecules
1] gmx插入分子[ -f [<.gro / .g96 / ...>] ] [ -ci [<.gro / .g96 / ...>] ] [ -ip [<.dat> ...
- leetcode 137单词接龙
直接层序遍历,结果有部分测试样例超时: class Solution { public: int ladderLength(string beginWord, string endWord, vect ...