D. Leaving Auction 一题很好的思维题
http://codeforces.com/contest/749/problem/D
现在发现做题要把样例抄下来,然后画一画,这样才容易发现新大陆。嗯,以后做题就这样。
如果排除了被删除了的人,那么,剩下的人中,胜出的,就是剩下出价最高的那个,但是它有可能不需要出价那么高,所以只需要比现在剩下的人中,出价第二高的那个人的出价最大值大就可以了。
所以每次只需要找出两个人,即可。
这题学到了,对一个数组排序,还可以依赖其他数组来排。
比如我用per[i]表示排名第i的那个人的id。如果要按它出价最高来排序,只需要在cmp函数上修改下就好。
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <assert.h>
#define IOS ios::sync_with_stdio(false)
using namespace std;
#define inf (0x3f3f3f3f)
typedef long long int LL; #include <iostream>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
const int maxn = + ;
int mx[maxn];
vector<int>each[maxn];
int per[maxn];
int lef[maxn];
set<int>ss;
bool cmp(int a, int b) {
return mx[a] < mx[b]; //学到了,可以根据这样来排序
}
void work() {
int n;
cin >> n;
for (int i = ; i <= n; ++i) {
int id, val;
cin >> id >> val;
per[i] = i;
mx[id] = val;
each[id].push_back(val);
ss.insert(id);
}
sort(per + , per + + n, cmp);
// for (int i = 1; i <= n; ++i) {
// cout << per[i] << " ";
// }
// cout << endl;
int q;
int DFN = ;
cin >> q;
while (q--) {
++DFN;
int gg;
cin >> gg;
for (int i = ; i <= gg; ++i) {
int x;
cin >> x;
lef[x] = DFN;
}
int temp[] = {};
int lentemp = ;
for (int i = n; i >= n - ss.size() + ; --i) {
if (lef[per[i]] == DFN) continue;
temp[++lentemp] = per[i]; //存id
if (lentemp == ) break;
}
// cout << lentemp << endl;
if (lentemp == ) {
cout << << " " << << endl;
} else if (lentemp == ) {
cout << temp[] << " " << each[temp[]][] << endl;
} else {
int ans = upper_bound(each[temp[]].begin(), each[temp[]].end(), mx[temp[]]) - each[temp[]].begin();
cout << temp[] << " " << each[temp[]][ans] << endl;
}
}
} int main() {
#ifdef local
freopen("data.txt", "r", stdin);
// freopen("data.txt", "w", stdout);
#endif
IOS;
work();
return ;
}
D. Leaving Auction 一题很好的思维题的更多相关文章
- 1554: SG Value (巧妙的模拟题,也属于思维题)
1554: SG Value Submit Page Summary Time Limit: 5 Sec Memory Limit: 256 Mb Submitted: 4 ...
- 51nod 1563 坐标轴上的最大团(今日gg模拟第一题) | 线段覆盖 贪心 思维题
51nod 1563 坐标轴上的最大团 坐标轴上有n个点,每个点有一个权值.第i个点的坐标是 xi ,权值是 wi .现在对这些点建图.对于点对 (i,j) ,如果 |xi−xj|≥wi+wj ,那么 ...
- 2018宁夏邀请赛I题 bubble sort(思维题
https://vjudge.net/problem/Gym-102222I 居然补到个防ak,刚开始不知道啥是循环左移右移(只能移一次),不好想.. 题意:以冒泡排序为背景 给你n,k 问在1~n的 ...
- zoj 3778 Talented Chef(思维题)
题目 题意:一个人可以在一分钟同时进行m道菜的一个步骤,共有n道菜,每道菜各有xi个步骤,求做完的最短时间. 思路:一道很水的思维题, 根本不需要去 考虑模拟过程 以及先做那道菜(比赛的时候就是这么考 ...
- Leaving Auction
Leaving Auction 题目链接:http://codeforces.com/contest/749/problem/D 二分 本来以为是哪种神奇的数据结构,没想到sort+lower_bon ...
- CF749D Leaving Auction set排序查找
CodeForces 749D. Leaving Auction 传送门 There are n people taking part in auction today. The rules of a ...
- java 基础题 很基础, 很有趣
都是一些非常非常基础的题,是我最近参加各大IT公司笔试后靠记忆记下来的,经过整理献给与我一样参加各大IT校园招聘的同学们,纯考Java基础功底, 老手们就不用进来了,免得笑话我们这些未出校门的孩纸们, ...
- 一道很经典的 BFS 题
一道很经典的 BFS 题 想认真的写篇题解. 题目来自:https://www.luogu.org/problemnew/show/P1126 题目描述 机器人移动学会(RMI)现在正尝试用机器人搬运 ...
- Codeforces 749D. Leaving Auction set+二分
D. Leaving Auction time limit per test: 2 seconds memory limit per test:256 megabytes input:standard ...
随机推荐
- Coding Ninja 修炼笔记 (1)
大家好啊~我又回来了. 这次主要是给大家带来一些提升 Coding 效率的建议. 效率都是一点一滴优化出来的,虽然每一条建议给你带来的提升可能都不大,但是积累起来,仍然是一股不可忽视的力量. 第一条 ...
- The Pilots Brothers' refrigerator-DFS路径打印
I - The Pilots Brothers' refrigerator Time Limit:1000MS Memory Limit:65536KB 64bit IO Format ...
- PHP出现Warning: A non-numeric value encountered问题的原因及解决方法
本文介绍php出现Warning: A non-numeric value encountered问题,用实例分析出现这种错误的原因,并提供避免及解决问题的方法. <?php error_rep ...
- su: /bin/bash: Permission denied带来的疑惑
>客户一个oracle突然当机了,由于业务启动,客户下意识的重启了服务器,系统是起来了,准备切换到oracle用户下启动数据库,可以怎么都无法su切换,真是火上浇油呀,描述如下: 在root用户 ...
- SAP 常用增强记录文档
转自:http://blog.csdn.net/budaha 20170215需要一个PR 修改保存时候的增强,目的是同步PR的处理状态 EBAN-STATU 到一个自建表ZTPRTOPO,记得有个P ...
- 安装linux各种桌面环境
1.安装kde ①添加 KDE SC 4.11 库 打开一个终端窗口,在终端窗口中输入如下命令: sudo add-apt-repository ppa:kubuntu-ppa/backports 回 ...
- AngularJS 指令(Directives)实践指南
指令(Directives)是所有AngularJS应用最重要的部分.尽管AngularJS已经提供了非常丰富的指令,但还是经常需要创建应用特定的指令.这篇教程会为你讲述如何自定义指令,以及介绍如何在 ...
- ACTION 中 单表查询语句 SQL写法
JSP页面 <tr> <td class="STYLE1"> <div align="center"> // 单击事件 调用 ...
- android:json解析的两个工具:Gson和Jackson的使用小例子
1.简介 json是android与服务器通信过程中常用的数据格式,例如,如下是一个json格式的字符串: {"address":"Nanjing"," ...
- Resolve the error: an error occurred during local report processing
Issue: an error occurred during local report processing.the definition of the report'Main Report'is ...