Educational Codeforces Round 76 (Rated for Div. 2) E. The Contest(dp+线段树)

题目链接

题意:

给定3个人互不相同的多个数字,可以把数字移动给别人,问最少移动几次后可以使第一个人的数字为1m1,第二个人m1m2,第三个人m2~n(可以没有数字)

题解:

设c[1][i]为第一个人m1为i时需要移动的次数,c[3][i]为m2为i是第三个人需要操作的次数,当其他两个人数字合法时,第二个人的数字也会合法.枚举第一个人的每个i,查询m2为(i+1~n+1)的最小操作次数,ans = min{c[1][i]+min(c[3]k)} 查询操作可用线段树维护

代码:

#include <bits/stdc++.h>
using namespace std;
const int N = 250000;
int t[4*N],a[5][N],b[5][N],c[5][N];
void build(int x,int l,int r)
{
if (l == r)
{
t[x] = c[3][l];
return;
}
int mid = (l + r) >>1;
build(x<<1,l,mid);
build(x<<1|1,mid+1,r);
t[x] = min(t[x<<1] , t[x<<1|1]);
}
int query(int x,int l,int r,int ll,int rr)
{
if (ll <= l && r <= rr) return t[x];
int mid = (l + r) >> 1;
int ans = 1<<30;
if (ll <= mid) ans = min(ans,query(x<<1,l,mid,ll,rr));
if (rr > mid ) ans = min(ans,query(x<<1|1,mid+1,r,ll,rr));
return ans;
}
int main()
{
int k1,k2,k3;
cin >> k1 >> k2 >> k3;
int n = k1+k2+k3;
memset(b,0,sizeof(b));
memset(c,0,sizeof(c));
for (int i = 1; i <= k1; i++)
{
cin >> a[1][i];
b[1][a[1][i]] = 1;
}
for (int i = 1; i <= k2; i++) cin >> a[2][i];
for (int i = 1; i <= k3; i++)
{
cin >> a[3][i];
b[3][a[3][i]] = 1;
}
c[1][0] = k1;
for (int i = 1; i <= n; i++)
{
b[1][i] = b[1][i-1]+b[1][i]; //记录第一个人前i个数中拥有几个
c[1][i] = i - b[1][i] + k1 - b[1][i];//i-b[1][i]为需要移动到第一个人的操作数,k1-b[1][i]为第一个人把数移动出去的操作数
}
c[3][n+1] = k3;
for (int i = n; i; i--)
{
b[3][i] = b[3][i+1] + b[3][i];
c[3][i] = n-i+1-b[3][i] +k3 - b[3][i]-(k1-b[1][i-1]); //如果是第一个人可以移动到第三个人的数会重复需要减掉
}
for (int i = 1; i < n; i++)
c[1][i] -= k3-b[3][i+1];//第三个人可以移动到第一个人的数
build(1,0,n+1);
int ans = c[1][n];
for (int i = 0; i < n; i++)
{
ans = min(ans, c[1][i] + query(1,0,n,i+1,n+1));
}
cout << ans << endl;
}

Educational Codeforces Round 76 (Rated for Div. 2) E. The Contest的更多相关文章

  1. Educational Codeforces Round 76 (Rated for Div. 2) E. The Contest dp

    E. The Contest A team of three programmers is going to play a contest. The contest consists of

  2. Educational Codeforces Round 76 (Rated for Div. 2)E(dp||贪心||题解写法)

    题:https://codeforces.com/contest/1257/problem/E 题意:给定3个数组,可行操作:每个数都可以跳到另外俩个数组中去,实行多步操作后使三个数组拼接起来形成升序 ...

  3. Educational Codeforces Round 76 (Rated for Div. 2)

    传送门 A. Two Rival Students 签到. Code /* * Author: heyuhhh * Created Time: 2019/11/13 22:37:26 */ #incl ...

  4. Educational Codeforces Round 76 (Rated for Div. 2) D. Yet Another Monster Killing Problem 贪心

    D. Yet Another Monster Killing Problem You play a computer game. In this game, you lead a party of

  5. Educational Codeforces Round 76 (Rated for Div. 2) C. Dominated Subarray 水题

    C. Dominated Subarray Let's call an array

  6. Educational Codeforces Round 76 (Rated for Div. 2) B. Magic Stick 水题

    B. Magic Stick Recently Petya walked in the forest and found a magic stick. Since Petya really likes ...

  7. Educational Codeforces Round 76 (Rated for Div. 2) A. Two Rival Students 水题

    A. Two Rival Students There are

  8. Educational Codeforces Round 76 (Rated for Div. 2) D题

    题意: 给你n个关卡,每个关卡有一个怪物,怪物的攻击力为a[i],你有n个英雄,每个英雄有一个攻击力,和疲劳值,只要英雄的攻击力比怪物的高就算打过了,同时疲劳减一,一天只能出战一个英雄,一个英雄可以打 ...

  9. Educational Codeforces Round 76 (Rated for Div. 2) D

    D题 原题链接 题意:就是给你n个怪兽有一个属性(攻击力),m个英雄,每个英雄有两种属性(分别为攻击力,和可攻击次数),当安排最好的情况下,最少的天数(每选择一个英雄出战就是一天) 思路:因为怪兽是不 ...

随机推荐

  1. webpack实践——DLLPlugin 和 DLLReferencePlugin的使用

    DLLPlugin 和 DLLReferencePlugin的使用 DLLPlugin 和 DLLReferencePlugin 用某种方法实现了拆分 bundles,同时还大大提升了构建的速度. 1 ...

  2. 2019年面试官最喜欢问的28道ZooKeeper面试题

    前言 ZooKeeper 是一个分布式的,开放源码的分布式应用程序协调服务.它是一个为分布式应用提供一致性服务的软件,提供的功能包括:配置维护.域名服务.分布式同步.组服务等. ZooKeeper 的 ...

  3. Some collections were archived because you’ve reached the shared requests limits.错误解决

    今天打开我的postman 发现我的一个collection不见了,左下角出现一个提示, Some collections were archived because you’ve reached t ...

  4. 关于yarn安装,这里做一个备份

    安装的是window版本,官网上有三种安装方式. 第一种下载一个.msi的安装包,然后当它运行时会指引你将 Yarn 安装到 Windows 上,因为点开以后页面是404,所以没有用这种方法. 第二种 ...

  5. Tarjan求割点和桥

    by szTom 前置知识 邻接表存储及遍历图 tarjan求强连通分量 割点 割点的定义 在一个无向图中,如果有一个顶点集合,删除这个顶点集合以及这个集合中所有顶点相关联的边以后,图的连通分量增多, ...

  6. 《【面试突击】— Redis篇》-- Redis哨兵原理及持久化机制

    能坚持别人不能坚持的,才能拥有别人未曾拥有的.关注编程大道公众号,让我们一同坚持心中所想,一起成长!! <[面试突击]— Redis篇>-- Redis哨兵原理及持久化机制 在这个系列里, ...

  7. Python工具类(一)—— 操作Mysql数据库

    如何调用直接看__main__函数里如何调用此工具类就阔以啦! # encoding=utf-8 import pymysql # 导入所有Mysql配置常量,请自行指定文件 from conf.se ...

  8. iOS使用fastlane自动化打包到fir(最全最详细流程)

    # iOS使用fastlane自动化打包到fir(最全最详细流程)1. **首先确认是否安装了ruby,终端查看下ruby版本**> ruby -v终端输出:ruby 2.4.1p111 (20 ...

  9. 最新中级java面试总结

    最近面试了不少家公司,从一家非外包跳到了外包(委屈脸Ծ‸Ծ),下面总结一下最近的一些心得体会 1.如果在做技术只是为了过日子,而没多大兴趣,那你必须需要考虑一下行业发展方向了.选定一个行业,深入某个行 ...

  10. 【java面试】集合类篇

    java中主要的类集合接口如下 Collection ├List │├LinkedList │├ArrayList │└Vector │ └Stack └Set Map ├Hashtable ├Has ...