Codeforces 1154E Two Teams
题目链接:http://codeforces.com/problemset/problem/1154/E
题目大意:
有n个队员,编号1~n,每个人的能力各自对应1~n中的一个数,每个人的能力都不相同。有1号教练和2号教练,他们轮流从剩余队伍里选人,轮到某位教练选时,它总是选剩余队员中能力最强的人和他左右各k个人。问选完的时候每个人的组号。
分析:
什么结构能快速查找到队员呢?当然是数组啦!什么结构能频繁删改呢?当然是链表啦!所以就用承载在数组上的链表来做啦!
代码如下:
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define INIT() std::ios::sync_with_stdio(false);std::cin.tie(0);
#define Rep(i,n) for (int i = 0; i < (n); ++i)
#define For(i,s,t) for (int i = (s); i <= (t); ++i)
#define rFor(i,t,s) for (int i = (t); i >= (s); --i)
#define ForLL(i, s, t) for (LL i = LL(s); i <= LL(t); ++i)
#define rForLL(i, t, s) for (LL i = LL(t); i >= LL(s); --i)
#define foreach(i,c) for (__typeof(c.begin()) i = c.begin(); i != c.end(); ++i)
#define rforeach(i,c) for (__typeof(c.rbegin()) i = c.rbegin(); i != c.rend(); ++i)
#define pr(x) cout << #x << " = " << x << " "
#define prln(x) cout << #x << " = " << x << endl
#define LOWBIT(x) ((x)&(-x))
#define ALL(x) x.begin(),x.end()
#define INS(x) inserter(x,x.begin())
#define ms0(a) memset(a,0,sizeof(a))
#define msI(a) memset(a,inf,sizeof(a))
#define msM(a) memset(a,-1,sizeof(a))
#define MP make_pair
#define PB push_back
#define ft first
#define sd second
template<typename T1, typename T2>
istream &operator>>(istream &in, pair<T1, T2> &p) {
in >> p.first >> p.second;
return in;
}
template<typename T>
istream &operator>>(istream &in, vector<T> &v) {
for (auto &x: v)
in >> x;
return in;
}
template<typename T1, typename T2>
ostream &operator<<(ostream &out, const std::pair<T1, T2> &p) {
out << "[" << p.first << ", " << p.second << "]" << "\n";
return out;
}
typedef long long LL;
typedef unsigned long long uLL;
typedef pair< double, double > PDD;
typedef set< int > SI;
typedef vector< int > VI;
const double EPS = 1e-;
const int inf = 1e9 + ;
const LL mod = 1e9 + ;
const int maxN = 2e5 + ;
const LL ONE = ;
struct Node{
int value, pos;
Node* prev = NULL;
Node* next = NULL;
};
int n, k, ans[maxN];
Node nodes[maxN];
int to[maxN];
int f = ;
int main(){
scanf("%d%d\n", &n, &k);
For(i, , n) {
scanf("%d", &nodes[i].value);
nodes[i].pos = i;
to[nodes[i].value] = i;
}
Rep(i, n + ) nodes[i].next = &nodes[i + ];
Rep(i, n + ) nodes[i + ].prev = &nodes[i];
int i = n;
while(i >= ) {
if(ans[to[i]] != ) {
--i;
continue;
}
ans[to[i]] = f;
// 处理左边k个
int cnt = ;
Node *p = nodes[to[i]].prev;
while(p->prev != NULL && cnt < k) {
ans[p->pos] = f;
p = p->prev;
++cnt;
}
// 处理右边k个
cnt = ;
Node *q = nodes[to[i]].next;
while(q->next != NULL && cnt < k) {
ans[q->pos] = f;
q = q->next;
++cnt;
}
// 删掉选走的
p->next = q;
q->prev = p;
f = f == ? : ;
}
For(i, , n) printf("%d", ans[i]);
printf("\n");
return ;
}
Codeforces 1154E Two Teams的更多相关文章
- Codeforces 1154E - Two Teams - [线段树+链表]
题目链接:https://codeforces.com/contest/1154/problem/E 题意: $n$ 个人排成一排,第 $i$ 个人的能力值为 $a[i]$,$a[1 \sim n]$ ...
- codeforces 478B Random Teams
codeforces 478B Random Teams 解题报告 题目链接:cm.hust.edu.cn/vjudge/contest/view.action?cid=88890#probl ...
- codeforces 478B Random Teams 解题报告
题目链接:http://codeforces.com/problemset/problem/478/B 题目意思:有 n 个人,需要将这班人分成 m 个 组,每个组至少含有一个人,同一个组里的人两两可 ...
- Codeforces Round #527-B. Teams Forming(贪心)
time limit per test 1 second memory limit per test 256 megabytes input standard input output standar ...
- codeforces 879 D. Teams Formation(思维)
题目链接:http://codeforces.com/contest/879/problem/D 题意:这题题意我反正是看了很久,可能是我的理解能力有点差,就是将一个数组倍增m倍然后将连续的相同的k个 ...
- 【Codeforces】879D. Teams Formation 思维+模拟
题意 给定$n$个数,重复拼接$m$次,相邻$k$个重复的可消除,问最后序列中有多少个数 首先可以发现当$k>=n$时,如果要使$n$个数可以被消除,那么$n$个数必须一样,否则$n$个数不能被 ...
- Codeforces Round #443 (Div. 2) 【A、B、C、D】
Codeforces Round #443 (Div. 2) codeforces 879 A. Borya's Diagnosis[水题] #include<cstdio> #inclu ...
- Codeforces Round #443 (Div. 1) B. Teams Formation
B. Teams Formation link http://codeforces.com/contest/878/problem/B describe This time the Berland T ...
- Codeforces 552 E. Two Teams
E. Two Teams time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...
随机推荐
- 5.03-requests_ssl
import requests url = 'https://www.12306.cn/mormhweb/' headers = { 'User-Agent': 'Mozilla/5.0 (Macin ...
- Linux:Day4(下) 用户及组管理
Linux用户:Username/UID 管理员:root,0 普通用户: 1-65535 系统用户:1-499 对守护进程获取资源进行权限分配: 登陆用户:500+ 交互式登录: Linux组:Gr ...
- 15.io流,递归
一.file的常用api 二.算法:递归1.定义:递归算法是把问题转化为规模缩小了的同类问题的子问题.然后递归调用函数(或过程)来表示问题的解.一个过程(或函数)直接或间接调用自己本身,这种过程(或函 ...
- 多个jdk 变更 引起 tomcat插件 启动不了 The JRE could not be found.Edit the server and change the JRE location.
The JRE could not be found.Edit the server and change the JRE location. 在Windows->Preferences-> ...
- 欢迎加入.NET Core 技术QQ群一起讨论交流学习
群号:4656606 介绍:本群主要讨论.NET Core及其相关技术,如:IdentityServer4.ABP.Dcoker.Linux.Devops.微服务等,如果你正在使用或者准备使用.NET ...
- 海纳百川而来的一篇相当全面的Java NIO教程
目录 零.NIO包 一.Java NIO Channel通道 Channel的实现(Channel Implementations) Channel的基础示例(Basic Channel Exampl ...
- JMX,Jstatd做好JVM应用上线的最后一层保障
目录 我理解的监控 代码异常监控 远程主机配置jmx 修改要启动的java程序启动参数(JVM_OPTS). 修改文件权限 启动jvisualvm 监控服务器上的java程序 jstatd 连接到远程 ...
- Python全栈开发之路 【第七篇】:面向对象编程设计与开发(1)
本节内容 一.编程范式 编程指的是写程序.敲代码,就是指程序员用特定的语法.数据结构和算法编写的代码,目的是来告诉计算机如何执行任务的. 在编程的世界里最常见的两大流派是:面向过程与面向对象.“功夫的 ...
- Python-SMTP发送邮件(HTML、图片、附件)
前言: SMTP(Simple Mail Transfer Protocol)即简单邮件传输协议,它是一组用于由源地址到目的地址传送邮件的规则,由它来控制信件的中转方式. 一.Python发送HTML ...
- BFC 原理
BFC:Block-level box + Forating + Context; ------->块元素 决定其子元素如何定位, ...