Educational Codeforces Round 76 (Rated for Div. 2) E. The Contest
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的更多相关文章
- 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
- Educational Codeforces Round 76 (Rated for Div. 2)E(dp||贪心||题解写法)
题:https://codeforces.com/contest/1257/problem/E 题意:给定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 ...
- 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
- Educational Codeforces Round 76 (Rated for Div. 2) C. Dominated Subarray 水题
C. Dominated Subarray Let's call an array
- 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 ...
- Educational Codeforces Round 76 (Rated for Div. 2) A. Two Rival Students 水题
A. Two Rival Students There are
- Educational Codeforces Round 76 (Rated for Div. 2) D题
题意: 给你n个关卡,每个关卡有一个怪物,怪物的攻击力为a[i],你有n个英雄,每个英雄有一个攻击力,和疲劳值,只要英雄的攻击力比怪物的高就算打过了,同时疲劳减一,一天只能出战一个英雄,一个英雄可以打 ...
- Educational Codeforces Round 76 (Rated for Div. 2) D
D题 原题链接 题意:就是给你n个怪兽有一个属性(攻击力),m个英雄,每个英雄有两种属性(分别为攻击力,和可攻击次数),当安排最好的情况下,最少的天数(每选择一个英雄出战就是一天) 思路:因为怪兽是不 ...
随机推荐
- Ncverilog 仿真quartus generate IP的要点
Ncverilog 仿真quartus generate IP的要点 最近利用quartus II 生成plll 的IP,利用nclaunch 仿真的时候老是报错, 提示unresolved in w ...
- deepin idea2019注册码
找了好久终于找到能用的注册码了https://blog.csdn.net/zixiao217/article/details/82942476第一个好像是已经过期了,然后试了下第二个发现可以直接官网下 ...
- java反射-- Field 用法实践
java 反射是一种常用的技术手段, 通过加载类的字节码的方式来获取相关类的一些信息 比如成员变量, 成员方法等. Field 是什么呢? field 是一个类, 位于java.lang.reflec ...
- ENS 域名注册表智能合约(ENSRegistry.sol)解析
ENS 注册表合约是 ENS 系统中的核心合约,了解这个合约可以敲开我们理解 ENS 域名系统的大门. 打开下面的折叠区域可以查看用 Solidity 语言编写的详细代码.当前部署在以太坊中的 ENS ...
- python条件判断语句
# 条件判断(if)语句: # 语法1: if 条件表达式 : 单行语句 # 语法2: if 条件表达式 : # 代码块(多行语句) # 执行的流程:if语句在执行时,会先对条件表达式进行求值判断, ...
- 世界上最流行的版本控制系统——Git
版本控制系统,也就是VCS(Version Control System),可以说是程序员必备的工具.那么它到底是什么,有什么作用呢? 举个例子,如果你想查看你所开发的软件在一个月之前的模样,同时还想 ...
- ubuntu 18.04.1安装hadoop3.1.2
前提,虚拟机安装 见https://www.cnblogs.com/cxl-blog/p/11363183.html 一.按照https://blog.csdn.net/MastetHuang/art ...
- Frameworks.Entity.Core 1
CommonEnums 1系统模块BlockType 2证件类型IDType 3在线支付类型OnLineType 4操作权限,支持位移运算OperatorAuthority 5订单状态: 1000-待 ...
- 创建dynamics CRM client-side (十三) - 在HTML Web Resource中获取form elements & 获取外部js文件
上一节我们讨论到创建HTML Web Resource. 但是纯HTML的页面不能满足我们的需求, 所以今天我们来做在HTML Web Resource中获取form elements Please ...
- python从excel中读取数据传给其他函数使用
首先安装xlrd库 pip install xlrd 方法1: 表格内容如下: 场景描述,读取该表格A列数据,然后打印出数据 代码何解析如下: import xlrd #引入xlrd库 def exc ...