题:https://codeforces.com/contest/1257/problem/E

题意:给定3个数组,可行操作:每个数都可以跳到另外俩个数组中去,实行多步操作后使三个数组拼接起来形成升序。

   输出最小操作次数

dp:

#include<bits/stdc++.h>
using namespace std;
const int M=2e5+;
int dp[M][];
int a[M];
///dp[i][0]表示前i个数全属于第一个数组所要花费的最小代价
///dp[i][1]表示前i个数全属于第一、二个数组所要花费的最小代价
///!!dp[i][1]必须要保证前i个数是要连续的属于第一个数组,和连续的属于第一个数组前后分布
int main(){
int k1,k2,k3;
scanf("%d%d%d",&k1,&k2,&k3);
int n=k1+k2+k3;
for(int i=,x;i<=k1;i++){
cin>>x;
a[x]=;
}
for(int i=,x;i<=k2;i++){
cin>>x;
a[x]=;
}
for(int i=,x;i<=k3;i++){
cin>>x;
a[x]=;
}
for(int i=;i<=n;i++){
dp[i][]=dp[i-][]+(a[i]==?:);
dp[i][]=min(dp[i-][],dp[i-][])+(a[i]==?:);
dp[i][]=min(dp[i-][],min(dp[i-][],dp[i-][]))+(a[i]==?:);
}
cout<<min(dp[n][],min(dp[n][],dp[n][]));
return ;
}

贪心:

#include<bits/stdc++.h>
using namespace std;
const int M=2e5+;
int a[M],b[M];
int main(){
int n;
int k1,k2,k3;
scanf("%d%d%d",&k1,&k2,&k3);
n=k1+k2+k3;
for(int i=;i<n;i++)
scanf("%d",&a[i]);
sort(a,a+k1);
sort(a+k1,a+k1+k2);
sort(a+k1+k2,a+n);
int tot=;
for(int i=;i<n;i++){
if(b[tot]<a[i])
b[++tot]=a[i];
else{
int pos=upper_bound(b,b+tot,a[i])-b;
b[pos]=a[i];
} }
printf("%d\n",n-tot);return ;
}

题解:枚举R,R往后的给第三个选手,然后在R的左边部分确定一个L,使其价值最优,

   考虑对于确定的L,R,答案就是,不属于L,R分割出来的数组对应的位置。

   比如L前面的数组我们要挑出属于第二,三数组的数

   这个说的就是上面的东西,也就是当前L,R的答案cnt(L,2)+cnt(L,3)+cnt(m,1)+cnt(m,3)+cnt(r,1)+cnt(r,2)

   分析:第二、四、五、六项我们可以通过枚举的R的位置来求到

      记x为第一项和第三项的和,即x=cnt(L,2)+cnt(m,1);

      现在只要知道x我们就可以算这个位置的答案了

      记posval=cnt(L,1)-cnt(L,2),我们要操作数最小,肯定要posval最大,因为posval大说明在L前面有越多满足属于第一个选手的题目。

      这时我们发现,posval+x=cnt(L,1)+cnt(m,1),这个表示R前面1的个数,这个可以很轻易的求得;

      x=cnt(R,1)-posval

#include<bits/stdc++.h>
using namespace std;
const int M=2e5+;
int a[M];
int L[],R[];
int main(){
int k1,k2,k3;
scanf("%d%d%d",&k1,&k2,&k3);
int n=k1+k2+k3;
for(int x,i=;i<=k1;i++){
scanf("%d",&x);
a[x]=;
}
for(int x,i=;i<=k2;i++){
scanf("%d",&x);
a[x]=;
}
for(int x,i=;i<=k3;i++){
scanf("%d",&x);
a[x]=;
}
int ans=,posval=;
for(int i=;i<=n;i++)
if(a[i]!=)
ans++;
for(int i=;i<=n;i++)
R[a[i]]++;
for(int i=;i<=n;i++){
L[a[i]]++;
R[a[i]]--;
posval=max(posval,L[]-L[]);///最佳的位置
int sum=R[]+R[]+L[]+L[]-posval;
ans=min(ans,sum);
}
cout<<ans<<endl;
return ;
}

Educational Codeforces Round 76 (Rated for Div. 2)E(dp||贪心||题解写法)的更多相关文章

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

    Educational Codeforces Round 76 (Rated for Div. 2) E. The Contest(dp+线段树) 题目链接 题意: 给定3个人互不相同的多个数字,可以 ...

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

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

  3. 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

  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. RMAN > BACKUP VALIDATE DATABASE ARCHIVELOG ALL

    使用BACKUP ... VALIDATE 命令: You can use the BACKUP VALIDATE command to do the following:        (1)Che ...

  2. 自定义checkbox,redio等

    直接上代码: 看的懂看,看不懂拉到. .messageState li {list-style: none;float: left;padding-right:30px;font-size: 16px ...

  3. bzoj 1832: [AHOI2008]聚会

    良心题2333 三个点两两求一遍就行,最小肯定是在某2个点的lca处,(肯定让第三个人去找2个人,不能让2个人一起去找第三个人233) #include<bits/stdc++.h> #d ...

  4. 04-String——课后作业1:字串加密

    题目:请编写一个程序,加密或解密用户输入的英文字串要求设计思想.程序流程图.源代码.结果截图. 程序设计思想:首先由用户选择是加密还是解密,利用String类中的charAt函数依次取出字串中的字符, ...

  5. EBGP的多跳与验证命令

    EBGP的多跳与验证命令: ①:neighbor router-id ebgp-multihop “int”——设置多跳. ②:neighbor router-id password “str”——设 ...

  6. rdlc报表带参数打印

    1.新建rdlc文件报表 2.选中rdlc文件=>视图=>报表资料 添加几个参数,如图 设计报表页面 int WaitNum = this.queueDTOs.Where(m=>m. ...

  7. C语言:大数求和

    点击获取题目 1410: [蓝桥杯]高精度加法 时间限制: 1 Sec  内存限制: 256 MB提交: 28  解决: 20[状态] [提交] [命题人:外部导入] 题目描述 输入两个整数a和b,输 ...

  8. SpringBoot之Order注解启动顺序

    order的规则: order的值越小,优先级越高order如果不标注数字,默认最低优先级,因为其默认值是int最大值该注解等同于实现Ordered接口getOrder方法,并返回数字. @Reten ...

  9. 归并排序(包含逆序数对的个数51Nod1019)

    归并排序是效率很好的排序方式,和快排效率一样高,但在稳定性上优于快排,下面我们来介绍归并排序. 归并排序运用递归将序列不断二分(其原理就是分治),就像一棵树不断向下分支,最后分到只剩一个元素,这样这个 ...

  10. 吴裕雄--天生自然 PHP开发学习:echo 和 print 语句

    <?php echo "<h2>PHP 很有趣!</h2>"; echo "Hello world!<br>"; ec ...