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 ...
随机推荐
- 洛谷P3294 [SCOI2016]背单词——题解
题目传送 阅读理解题题意解释可以看这位大佬的博客. 发现求后缀与倒序求前缀是等价的,而找前缀自然就想到了trie树.将所有字符串翻转后再建入trie树中,再对每一个字符串翻转后从trie树中找前缀,就 ...
- JavaWeb_Ajax通过JQuery和原生js异步传输数据
菜鸟教程 传送门 AJAX 优点:在不重新加载整个页面的情况下,可以与服务器交换数据并更新部分网页内容 XMLHttpRequest 对象 传送门 (一) [JQuery]定时发送ajax请求 (二) ...
- 创建新文件(包括上级文件夹),获取外置SD卡的根目录
public String hebGetExternalRootDir(String externalAndriodSubDirPath){ if ( externalAndriodSubDirPat ...
- java导入导出下载Excel,xls文件(带下拉框)
/** * 导入excel文件 * 2014-7-23 * @return */ @RequiresPermissions("plug:product:caiwu:upload") ...
- TODO: Java虚拟机 初始化过程
Java虚拟机 初始化过程: 参考: https://www.cnblogs.com/bhlsheji/p/4017816.html 参考:https://blog.csdn.net/boling_c ...
- leetcode 56区间合并
class Solution { public: static bool cmp(vector<int> a,vector<int> b){ ]<b[]; } vecto ...
- anaconda 安装pyspider出错
注释Lib\mimetypes.py里面的 try: mimetype = mimetype.encode(default_encoding) except UnicodeEncodeErr ...
- mingw下的msys显示与输入乱码
一直很喜欢gcc+vim这个貌似已经不用在强调了,好了,我只是想说明下我的问题是首先从gcc编译出错提示开始的 正如上面所说,安装完MinGW后使用gcc一编译,这程序没有错误还好,这一有错误发现输入 ...
- 代码实现:取一个整数a从右端开始的4~7位
import java.util.Scanner; //取一个整数a从右端开始的4-7位. public class Test { public static void main(String[] a ...
- redis cluster 集群 安装 配置 详解
redis cluster 集群 安装 配置 详解 张映 发表于 2015-05-01 分类目录: nosql 标签:cluster, redis, 安装, 配置, 集群 Redis 集群是一个提供在 ...