CF Educational Round 78 (Div2)题解报告A~E

A:Two Rival Students​

  • 依题意模拟即可

  • #include<bits/stdc++.h>
    using namespace std;
    int T;
    int n, x, a, b;
    int main()
    {
    cin >> T;
    while(T--)
    {
    cin >> n >> x >> a >> b;
    if(a > b) swap(a, b);
    while(x != 0)
    {
    if(a > 1) x--, a--;
    else if(a == 1) break;
    }
    while(x != 0)
    {
    if(b < n) x--, b++;
    else if(b == n) break;
    }
    cout << b - a << endl;
    }
    return 0;
    }

B: Magic Stick ​

  • 1,2,3会跑成循环,其他的只要不断扩大后减小就行,特判。

  • #include<bits/stdc++.h>
    using namespace std;
    int main()
    {
    int T;
    cin >> T;
    while(T--)
    {
    int x, y; cin >>x >> y;
    if(x >= y) {
    puts("YES"); continue;
    }
    else
    {
    if(x == 2 && y != 3) {
    puts("NO");
    continue;
    }
    if(x == 3 && y != 3)
    {
    puts("NO");
    continue;
    }
    if(x == 1 && y != 1)
    {
    puts("NO");
    continue;
    }
    }
    puts("YES");
    }
    return 0;
    }

C: Dominated Subarray

  • 线性扫一遍就好了,其实是查询相同的两个元素的距离最小是多少

  • #include<bits/stdc++.h>
    using namespace std;
    const int maxn = 2e5 + 10;
    int a[maxn], T, n, vis[maxn]; int main()
    {
    scanf("%d", &T);
    while(T--)
    {
    scanf("%d", &n);
    int ans = 0x3f3f3f3f;
    for(int i = 1; i <= n; i++)
    {
    scanf("%d", &a[i]);
    vis[i] = 0;
    } for(int i = 1; i <= n; i++)
    {
    int x = a[i];
    if(vis[x]) ans = min(i-vis[x], ans);
    vis[x] = i;
    } if(ans == 0x3f3f3f3f) puts("-1");
    else cout << ans + 1<< endl;
    }
    return 0;
    }

D: Yet Another Monster Killing Problem

  • 二分+贪心

  • 首先特判英雄最高的攻击力和怪兽最大的生命值,不够就肯定打不完。

  • 对于英雄而言,如果两个英雄\((i,j)\)攻击力相同,但是\(i.s>j.s\),那么我们肯定不选择\(j\)而选择\(i\)。

  • 所以我们按照\(p\)进行排序,之后进行后缀操作\(b(i).s\)表示\(i\)~\(n\)最大耐力值。

  • 对于某个怪物而言,我们可以找到一个英雄他的攻击力恰好大于这个怪物,因为\(b\)已经针对\(p\)排好序了,所以我们可以二分找这个英雄。

  • 我们从第一天开始,枚举每个怪物,如果当前能杀死最多怪物的英雄,对于某个怪物而言,如果英雄的耐力不足以支持当前的操作,则开启新的一天,循环杀死所有怪物。

  • #include<bits/stdc++.h>
    using namespace std;
    const int maxn = 2e5 + 10;
    int T, n, m;
    int a[maxn]; struct Node{
    int p, s;
    }b[maxn]; bool cmp(Node a, Node b) {return a.p < b.p;}
    bool cmpp(Node x, int y) {return x.p < y;} int main()
    {
    cin >> T;
    while(T--)
    {
    int mx = 0;
    scanf("%d", &n);
    for(int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    mx = max(mx, a[i]);
    }
    scanf("%d", &m);
    for(int i = 1, x, y; i <= m; i++)
    {
    scanf("%d%d", &x, &y);
    b[i] = {x, y};
    }
    sort(b+1, b+1+m, cmp);
    if(b[m].p < mx)
    {
    puts("-1");
    continue;
    } for(int i = m - 1; i >= 1; i--)
    b[i].s = max(b[i].s, b[i+1].s);
    int days = 1;
    int las = 0; //上一个怪物
    int cnt = 0x3f3f3f3f; //从上一个怪物杀到现在的英雄的最小耐力 for(int i = 1; i <= n; i++)
    {
    int t = lower_bound(b+1, b+m+1, a[i], cmpp) - b;
    cnt = min(b[t].s, cnt);
    if(cnt + las < i) //当前这只怪物杀不掉了
    {
    cnt = b[t].s;
    days += 1;
    las = i - 1;
    }
    }
    cout << days << endl;
    }
    return 0;
    }

E:The Contest

  • \(dp\)
  • \(f(i,1/2/3)\)表示第\(i\)个数放在第\(1,2,3\)个同学手上的最小操作数。
  • 对于初始状态\(x\)在第\(i\)个同学手上,有\(a(x)=i\)。
  • 有状态转移方程\(f(i,k) = min(f(i,k), f(i,j)+(k!=a(i+1)))\),其中\((1\leq j \leq3,j\leq k \leq 3)\)
    • 解释:因为\(1,2,3\)同学手上的序列数要单调,所以\(j\leq k\)。
#include<bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
int a[maxn], n;
int f[maxn][5]; int main()
{
int n1, n2, n3;
cin >> n1 >> n2 >> n3; n = n1 + n2 + n3;
for(int i = 1, x; i <= n1; i++)
scanf("%d", &x), a[x] = 1;
for(int i = 1, x; i <= n2; i++)
scanf("%d", &x), a[x] = 2;
for(int i = 1, x; i <= n3; i++)
scanf("%d", &x), a[x] = 3; memset(f, 0x3f, sizeof(f));
f[0][1] = f[0][2] = f[0][3] = 0; for(int i = 0; i <= n - 1; i++)
for(int j = 1; j <= 3; j++)
for(int k = j; k <= 3; k++)
f[i+1][k] = min(f[i+1][k], f[i][j] + (k != a[i+1])); cout << min(min(f[n][1], f[n][2]), f[n][3]) << endl; return 0;
}

F: Make Them Similar 待补。

CF Educational Round 78 (Div2)题解报告A~E的更多相关文章

  1. CF Round #580(div2)题解报告

    CF Round #580(div2)题解报告 T1 T2 水题,不管 T3 构造题,证明大约感性理解一下 我们想既然存在解 \(|a[n + i] - a[i]| = 1\) 这是必须要满足的 既然 ...

  2. Codeforces Educational Round 92 赛后解题报告(A-G)

    Codeforces Educational Round 92 赛后解题报告 惨 huayucaiji 惨 A. LCM Problem 赛前:A题嘛,总归简单的咯 赛后:A题这种**题居然想了20m ...

  3. CF1169(div2)题解报告

    CF1169(div2)题解报告 A 不管 B 首先可以证明,如果存在解 其中必定有一个数的出现次数大于等于\(\frac{m}{2}\) 暴力枚举所有出现次数大于等于$\frac{m}{2} $的数 ...

  4. Codeforces Round#320 Div2 解题报告

    Codeforces Round#320 Div2 先做个标题党,骗骗访问量,结束后再来写咯. codeforces 579A Raising Bacteria codeforces 579B Fin ...

  5. Codeforces Round#704 Div2 题解(A,B,C,D,E)

    FST ROUND !!1 A Three swimmers: 直接整除一下向上取整就好了: #include <bits/stdc++.h> using namespace std; t ...

  6. [CF]codeforces round 369(div2)

    *明早起来再贴代码 A [题意] 给定n*5的方格 将横向的相邻两个变成+输出 [题解] ... B [题意] 一个n*n的正整数矩阵,有且仅有一个数为0 ,在这个位置填上一个数,使得每一列的和 每一 ...

  7. [CF]codeforces round#366(div2)滚粗记

    开场心理活动:啊打完这场大概有1700了吧 中途心理活动:啊这个ABC看起来都随便做啊 死亡原因:欸怎么没网了 -75 .. A [题意]Hulk说完一句I hate会说that I love 然后是 ...

  8. CodeForces round 967 div2 题解(A~E)

    本来准备比完赛就写题解的, 但是一拖拖了一星期, 唉 最后一题没搞懂怎么做,恳请大神指教 欢迎大家在评论区提问. A Mind the Gap 稳定版题面 https://cn.vjudge.net/ ...

  9. Codeforces Round #407 div2 题解【ABCDE】

    Anastasia and pebbles 题意:你有两种框,每个框可以最多装k重量的物品,但是你每个框不能装不一样的物品.现在地面上有n个物品,问你最少多少次,可以把这n个物品全部装回去. 题解:其 ...

随机推荐

  1. CAP带你轻松玩转ASP.NETCore消息队列

    CAP是什么? CAP是由我们园子里的杨晓东大神开发出来的一套分布式事务的决绝方案,是.Net Core Community中的第一个千星项目(目前已经1656 Start),具有轻量级.易使用.高性 ...

  2. Python【每日一问】36

    问: 基础题: 809*x=800*x+9*x+1 其中 x 代表的两位数, 8*x 的结果为两位数, 9*x 的结果为 3 位数.求 x ,及计算 809*x 的结果. 提高题: 对文件" ...

  3. vertica创建新用户并授权

    1.创建用户,并设置密码: create user user1 identified by 'pwd1'; 2.把角色授权给用户(dbduser是普通角色): grant dbduser to use ...

  4. windows上redis的安装和配置

    windows上redis的安装和配置 进入到Redis的根目录D:\Programming\Redis\Redis6379\Redis-x64-3.2.100底下操作: 配置文件启动 redis-s ...

  5. 分布式文件系统fastdfs搭建

    https://blog.csdn.net/qq_33009107/article/details/90641940 #Tracker 端口号 22122 启动tracker /etc/init.d/ ...

  6. 好久没写原生的PHP调用数据库代码了分享个

    好久没写原生的PHP代码调用数据库了 eader("Content-type: text/html; charset=utf-8"); $time=$symptoms=$attr= ...

  7. Postman安装使用

    下载链接:https://www.getpostman.com/downloads/ 选择下载的版本 postman基础功能介绍 collection在postman里面相当于一个文件夹,可以把同一个 ...

  8. PIE SDK Alpha通道数据渲染

    1.  功能简介 在计算机图形学中,一个RGB颜色模型的真彩图形,用由红.绿.蓝三个色彩信息通道合成的,每个通道用了8位色彩深度,共计24位,包含了所有彩色信息.为实现图形的透明效果,采取在图形文件的 ...

  9. Java常用类StringBuffer详解

    内容多为最近学习的自我总结,可能有些地方写的不严谨,甚至会有错误的地方,仅供参考,如发现错误敬请指出,谢谢! 灰色字体为补充扩展内容,多为帮助自己理解. StringBuffer概述: 线程安全的可变 ...

  10. 基于Custom-metrics-apiserver实现Kubernetes的HPA(内含踩坑)

    前言 这里要说一下Prometheus的检控指标从哪里来,它有3个渠道: 主机监控,也就是部署了Node Exporter组件的主机,它以DaemonSet或者系统进程的形式运行,Prometheus ...