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个英雄,每个英雄有两种属性(分别为攻击力,和可攻击次数),当安排最好的情况下,最少的天数(每选择一个英雄出战就是一天) 思路:因为怪兽是不 ...
随机推荐
- 简单聊一聊JS中的循环引用及问题
本文主要从 JS 中为什么会出现循环引用,垃圾回收策略中引用计数为什么有很大的问题,以及循环引用时的对象在使用 JSON.stringify 时为什么会报错,怎样解决这个问题简单谈谈自己的一些理解. ...
- ArcGIS Server 动态图层发布调用图解
目录 1 前言 1.1 简介 1.2 适用场景 2 动态图层 2.1 共享地图服务 2.2 动态工作空间添加 2.2.1 企业级数据库 2.2.2 shapefile文件夹 2.2.3 栅格文件夹 2 ...
- vue中动态设置echarts画布大小
document.getElementById('news-shopPagechart').style.height = this.heightpx2+'px'; //heightpx2定义在data ...
- css样式及类型集合
图片不清楚的,可以尝试点击图片鼠标右键选择:在新标签页中打开 放大
- django.db.migrations.exceptions.MigrationSchemaMissing和raise ImproperlyConfigured('mysqlclient 1.3.13 or newer is required; you have %s.' % Database.__version__)
1.使用Python3.7 + Django2.2 + MySQL 5.5 在执行(python manage.py migrate)命令时出现错误django.db.migrations.excep ...
- 使用ABAP Data Validator验证数据有效性
在日常的开发过程中,我们常常要处理不同来源的数据.数据可能来自不可靠的外部系统.不可靠的用户输入和甚至设计有误的数据库表,因此,对数据有效性进行验证是必要的工作. 开源工具ABAP Data Vali ...
- redis 5种类型
redis可以不严谨的看成: redis: { name: value, name: value, } value的数据类型: 1.字典 2.列表 3.字符串 4.集合 5.有序集合 注意: redi ...
- 9.JavaSE之运算符
Java语言支持如下运算符operator:优先级() 算数运算符 :+ ,- ,* ,/ ,% ,++ ,-- 赋值运算符 := 关系运算符 :> ,< ,>= ,<= ,= ...
- 开发环境Vue访问后端接口教程(前后端分离开发,端口不同下跨域访问)
原理:开发环境下的跨域:在node.js上实现请求转发,vue前端通过axios请求到node.js上,node.js将请求转发到后端,反之.响应也是,先到node.js上,然后转发vue-cil项目 ...
- 【java面试】框架篇之Spring
1.你如何理解Spring? 具体来说Spring是一个轻量级的容器,用于管理业务相关对象的.核心功能主要为:IOC,AOP,MVC. IOD:控制反转,将对象的创建过程交给容器,让容器管理对象的生命 ...