• 题意:有\(n\)个队员站成一排,有两个教练分别选人,每次选当前剩余人中的能力值最大的那个以及他两边相邻的\(k\)个人,问最后每个人所在队伍情况.

  • 题解:优先队列模拟,以及双向链表,先用结构体存入每个人的状态,然后全部push到优先队列中,每次将已经分好队的人弹出,然后找当前能力值最大的人分组,至于两边的\(k\)个人,因为我们会对他们也进行分组,所以之后肯定不会再选他们了,所以可以模拟链表,直接让当前能力值最大的人的左边指向\(i-k-1\)即可,右边也是如此,其实也就是链表删除节点的过程,但是要记得在这个过程中对这些点进行分组.还有!!!最最重要的是,不要直接对队列中取出的元素进行修改,没用的,我们可以找到id后对结构体全局变量\(e\)进行修改.

  • 代码:

    struct misaka{
    int id,val,l,r,t;
    bool operator < (const misaka & mikoto) const {
    return val<mikoto.val;
    }
    }e[N]; int n,k;
    int a[N];
    priority_queue<misaka> h; int main() {
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    cin>>n>>k; rep(i,1,n){
    e[i].id=i;
    cin>>e[i].val;
    e[i].l=i-1;
    e[i].r=i+1;
    e[i].t=0;
    h.push(e[i]);
    } int cur=1;
    e[n].r=0; while(!h.empty()){ while(!h.empty() && e[h.top().id].t!=0) h.pop();
    if(h.empty()) break; misaka tmp=h.top(); e[tmp.id].t=cur;
    int pos1;
    int pos2;
    int now=k;
    for(pos1=e[tmp.id].l;now-- && pos1;pos1=e[pos1].l) e[pos1].t=cur;
    now=k;
    for(pos2=e[tmp.id].r;now-- && pos2;pos2=e[pos2].r) e[pos2].t=cur; e[pos2].l=pos1;
    e[pos1].r=pos2; cur=3-cur;
    } rep(i,1,n) cout<<e[i].t; return 0;
    }

Codeforces Round #552 (Div. 3) E. Two Teams (模拟,优先队列,双向链表)的更多相关文章

  1. Codeforces Round #552 (Div. 3) 题解

    Codeforces Round #552 (Div. 3) 题目链接 A. Restoring Three Numbers 给出 \(a+b\),\(b+c\),\(a+c\) 以及 \(a+b+c ...

  2. Codeforces Round #552 (Div. 3) A题

    题目网址:http://codeforces.com/contest/1154/problem/ 题目意思:就是给你四个数,这四个数是a+b,a+c,b+c,a+b+c,次序未知要反求出a,b,c,d ...

  3. Codeforces Round #368 (Div. 2) B. Bakery (模拟)

    Bakery 题目链接: http://codeforces.com/contest/707/problem/B Description Masha wants to open her own bak ...

  4. Codeforces Round #284 (Div. 2)A B C 模拟 数学

    A. Watching a movie time limit per test 1 second memory limit per test 256 megabytes input standard ...

  5. Codeforces Round #285 (Div. 2) A B C 模拟 stl 拓扑排序

    A. Contest time limit per test 1 second memory limit per test 256 megabytes input standard input out ...

  6. Codeforces Round #273 (Div. 2)-B. Random Teams

    http://codeforces.com/contest/478/problem/B B. Random Teams time limit per test 1 second memory limi ...

  7. Codeforces Round #552 (Div. 3) F. Shovels Shop (前缀和预处理+贪心+dp)

    题目:http://codeforces.com/contest/1154/problem/F 题意:给你n个商品,然后还有m个特价活动,你买满x件就把你当前的x件中最便宜的y件价格免费,问你买k件花 ...

  8. Codeforces Round #552 (Div. 3) F题

    题目网址:http://codeforces.com/contest/1154/problem/F 题目大意:给出n,m,k,n是物体的个数,m是优惠方式的种数,k是需要购买的物体个数, 然后给出n个 ...

  9. Codeforces Round #552 (Div. 3) D题

    题目网站:http://codeforces.com/contest/1154/problem/D 题目大意:给出n个数(0或1),还有a , b, a是蓄电池容量,b是电池容量,数为1时蓄电池可以充 ...

随机推荐

  1. python作业完成简单的文件操作

    题目 请创建以学号命名的目录,在该目录中创建名称为file1.txt的文件,并将自己的个人信息(序号.姓名以及班级)等写入该文件:然后并读取文件中的内容到屏幕上:接着重新命名该文件为file2.txt ...

  2. 面试官:Netty的线程模型可不只是主从多Reactor这么简单

    笔者看来Netty的内核主要包括如下图三个部分: 其各个核心模块主要的职责如下: 内存管理 主要提高高效的内存管理,包含内存分配,内存回收. 网通通道 复制网络通信,例如实现对NIO.OIO等底层JA ...

  3. rename 表名

    rename table 旧表名1 to 新表名1,旧表名2 to 新表名2;

  4. P2986 [USACO10MAR]伟大的奶牛聚集(思维,dp)

    题目描述 Bessie is planning the annual Great Cow Gathering for cows all across the country and, of cours ...

  5. ctfhub技能树—sql注入—Cookie注入

    手注 打开靶机 查看页面信息 查找cookie 测试是否为cookie注入 抓包 尝试注入 成功查询到数据库名 查询表名 查询字段名 查询字段信息 成功拿到flag sqlmap 查询数据库名 pyt ...

  6. migo的BAPI示例BAPI_GOODSMVT_CREATE

    1 *&---------------------------------------------------------------------* 2 *& Report Z_BAP ...

  7. allator 对springBoot进行加密

    1.对springboot项目添加jar包和xml文件 allatori.xml: <config> <input> <jar in="target/sprin ...

  8. SQL函数知识点

    SQL函数知识点 SQL题目(一) 1.查询部门编号为10的员工信息 select*from emp where empno=10; 2.查询年薪大于3万的人员的姓名与部门编号 select enam ...

  9. mybatis框架整合及逆向工程

    mybatis框架整合及逆向工程 一.三大框架整合 ​ 整合SSM框架 1.导入pom文件 1.导入spring的pom依赖 <?xml version="1.0" enco ...

  10. Oracle 0至6级锁的通俗解释及实验案例_ITPUB博客 http://blog.itpub.net/30126024/viewspace-2156232/

    Oracle 0至6级锁的通俗解释及实验案例_ITPUB博客 http://blog.itpub.net/30126024/viewspace-2156232/