题目链接: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的更多相关文章

  1. Codeforces 1154E - Two Teams - [线段树+链表]

    题目链接:https://codeforces.com/contest/1154/problem/E 题意: $n$ 个人排成一排,第 $i$ 个人的能力值为 $a[i]$,$a[1 \sim n]$ ...

  2. codeforces 478B Random Teams

    codeforces   478B  Random Teams  解题报告 题目链接:cm.hust.edu.cn/vjudge/contest/view.action?cid=88890#probl ...

  3. codeforces 478B Random Teams 解题报告

    题目链接:http://codeforces.com/problemset/problem/478/B 题目意思:有 n 个人,需要将这班人分成 m 个 组,每个组至少含有一个人,同一个组里的人两两可 ...

  4. Codeforces Round #527-B. Teams Forming(贪心)

    time limit per test 1 second memory limit per test 256 megabytes input standard input output standar ...

  5. codeforces 879 D. Teams Formation(思维)

    题目链接:http://codeforces.com/contest/879/problem/D 题意:这题题意我反正是看了很久,可能是我的理解能力有点差,就是将一个数组倍增m倍然后将连续的相同的k个 ...

  6. 【Codeforces】879D. Teams Formation 思维+模拟

    题意 给定$n$个数,重复拼接$m$次,相邻$k$个重复的可消除,问最后序列中有多少个数 首先可以发现当$k>=n$时,如果要使$n$个数可以被消除,那么$n$个数必须一样,否则$n$个数不能被 ...

  7. Codeforces Round #443 (Div. 2) 【A、B、C、D】

    Codeforces Round #443 (Div. 2) codeforces 879 A. Borya's Diagnosis[水题] #include<cstdio> #inclu ...

  8. 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 ...

  9. Codeforces 552 E. Two Teams

    E. Two Teams time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...

随机推荐

  1. centos7下安装docker(15.6docker跨主机网络---Weave)

    Weave是weaveworks开发的容器网络解决方案.weave创建的虚拟网络可以将部署在多个主机上的容器连接起来.对于容器来说,weave就像一个巨大的网络交换机,容器可以直接通信,无需NAT和端 ...

  2. AlexeyAB大神版yolo 待完善

    目录 darknet优化经验 1. AlexeyAB改进项 2. Linux下编译选项 3. 训练经验 4. 提升检测效果 5. 总结 6. AlexeyAB大神改进 darknet优化经验 主要来自 ...

  3. linux中启动 java -jar 运行程序

    每天学习一点点 编程PDF电子书.视频教程免费下载:http://www.shitanlife.com/code 直接用java -jar xxx.jar,当退出或关闭shell时,程序就会停止掉.以 ...

  4. python的格式化输出

    Python的格式化输出有两种: 一.类似于C语言的printf的方法 二.类似于C#的方法

  5. 阿里云配置tomcat https

    阿里云申请免费的SSL证书和配置https,可参考该篇博文:https://blog.csdn.net/baidu_19473529/article/details/70037976 虽然有现成的,不 ...

  6. /dev/mem可没那么简单

    这几天研究了下/dev/mem.发现功能非常奇妙,通过mmap能够将物理地址映射到用户空间的虚拟地址上.在用户空间完毕对设备寄存器的操作,于是上网搜了一些/dev/mem的资料. 网上的说法也非常统一 ...

  7. keystone系列三:网关协议

    一 静态页面和动态页面 在了解了http协议后,我们知晓,一个web server的本质就是 浏览器发送一个HTTP请求: 服务器收到请求,生成一个HTML文档: 服务器把HTML文档作为HTTP响应 ...

  8. CIFAR-10数据集图像分类【PCA+基于最小错误率的贝叶斯决策】

    CIFAR-10和CIFAR-100均是带有标签的数据集,都出自于规模更大的一个数据集,他有八千万张小图片.而本次实验采用CIFAR-10数据集,该数据集共有60000张彩色图像,这些图像是32*32 ...

  9. Vue-插槽学习

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  10. vue 项目中添加阿里巴巴矢量图

    1. 选择需要的图标,添加到购物车 2. 打开购物车,添加至我的项目 3. 打开项目列表 - 更多操作 - 编辑项目 修改FontClass/Symbol前缀,自定义一个名称,例如:v-icon-cu ...