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 ... 
随机推荐
- 在Ubuntu上安装Jenkins
			先决条件 安装Java SDK sudo apt-get install openjdk-8-jdk # sudo apt-get install openjdk-7-jdk 早些系统可以安装 第1步 ... 
- 有时间研究一下Maven打包插件细节
			Maven工作分为多个阶段,具体阶段参考:https://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html ... 
- D. Zero Quantity Maximization(hash+map)
			题意:就是让c=a*x+b,给你一个a[],b[],让你尽可能多的让c[]=0,输出有多少. 思路:直接令c=0,则x=-b/a, 也就是一条直线,通过这样就用hash值使相同的k值映射到一起,使用了 ... 
- 【转】dos下 和 批处理中的 for 语句的基本用法
			for 语句的基本用法 : 最复杂的for 语句,也有其基本形态,它的模样是这样的: 在cmd 窗口中:for %I in (command1) do command2 在批处理文件中:for % ... 
- VM虚拟机ubantu自适应屏幕大小
			1.菜单栏安装VMware-Tool sudo ./wmware-install.pl 2.sudo apt-get install open-vm-tools装完这两个就可以,有些人只安装了第一个, ... 
- 【转载】理解本真的REST架构风格
			本文将带您领略REST架构的起源.与Web的关系.REST架构的本质及特性,以及REST架构与其他架构风格之间的比较. 引子 在移动互联网.云计算迅猛发展的今天,作为一名Web开发者,如果您还没听说过 ... 
- 用 Django 管理现有数据库
			在多数项目中,总有一些几乎一成不变的 CRUD 操作,编写这些代码很无聊,但又是整个系统必不可少的功能之一.我们在上一个项目中也面临类似的问题,虽然已经实现了一个功能相对完整的管理后台,也尽量做到了代 ... 
- Spring整合ActiveMQ及多个Queue消息监听的配置
			消息队列(MQ)越来越火,在java开发的项目也属于比较常见的技术,MQ的相关使用也成java开发人员必备的技能.笔者公司采用的MQ是ActiveMQ,且消息都是用的点对点的模式.本文记录了实 ... 
- 【Java并发.3】对象的共享
			本章将介绍如何共享和发布对象,从而使他们能够安全地由多个线程同时访问.这两章合在一起就形成了构建线程安全类以及通过 java.util.concurrent 类库来构建开发并发应用程序的重要基础. 3 ... 
- ThinkPHP+JQuery实现文件的异步上传
			前端代码 <!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF- ... 
