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 ...
随机推荐
- JavaScript中的栈内存和堆内存
首先JavaScript中的变量分为基本类型和引用类型.基本类型就是保存在栈内存中的简单数据段,而引用类型指的是那些保存在堆内存中的对象. 1.基本类型 基本类型有Undefined.Null.Boo ...
- Edusoho之LNMP环境搭建
1.更新 sudo apt-get update sudo apt-get upgrade 2.安装Nginx sudo apt-get install nginx 3.安装php sudo apt- ...
- Eclipse 设置保存代码时自动格式化
在码代码或者优化的时候,经常需要使用到ctrl+shift+F来格式化代码,但其实ecilpse已经自带自动格式化功能了,只是没有默认开启. 正确的打开方式:windows-->Preferen ...
- Jsoup+FastJson制作新闻数据接口-Demo
经常用到 编写出来直接拿来用 这个适合在服务端结合servlet来做接口:需要下载jsoup+fastjson两个包 Jsoup使用手册:http://www.open-open.com/jsoup/ ...
- React-菜鸟学习笔记(一)
新公司的项目前端架构用的是react.js 之前孤陋寡闻并没听说过,想着后期开发和维护多少要会点前端的东西,就简单研究一下.个人的学习习惯能写代码的就不写文字,必要的地方加两行注释,代码一行行敲下去, ...
- RNG牛掰!
2018-05-21 RNG牛掰!Uzi圆梦! 不说了,先去哭了! 2018-07-08 洲际赛后更新,RNG依然牛逼! 2018-08-30 亚运后后更新,UZI加油! 2018-10-22 继续加 ...
- Spring集成Quarz开发环境搭建
第一步,搭建Spring相关的环境,参照:http://www.cnblogs.com/dyh004/p/4645572.html 第二步,下载Quartz相关的压缩文件,解压,下载地址:http:/ ...
- Python_%---format_43
fat39 博客园 首页 新随笔 联系 订阅 管理 随笔 - 142 文章 - 0 评论 - 0 python基础_格式化输出(%用法和format用法) 目录 %用法 format用法 %用 ...
- 小L记单词
题目描述 小L最近在努力学习英语,但是对一些词组总是记不住,小L小把这些词组中每一个单词的首字母都记一下,这样形成词组的缩写,通过这种方式小L的学习效率明显提高. 输入 输入有多行,每组测试数据占一行 ...
- new、getInstance()、newInstance()、Class.forName()
1.对象使用之前通过getinstance()得到而不需要自己定义,用完之后不需要delete: 2.new 一定要生成一个新对象,分配内存:getInstance() 则不一定要再次创建,它可以把一 ...