Codeforces Round #325 (Div. 2) 586ABC题解

开发者福利!热门AI工具限时免费用 购周边即赠Coding Plan Lite,Claude Code、Cursor等20+工具畅享,效率翻倍! 阅读详情

题目链接:点击打开链接


A: 给出Alena的课表, 1代表有课, 0代表没课, 2个连续0以上可以回家休息, 问你一天在学校待多久.

直接模拟即可, 可以直接计算1, 101的数目. 我记录了开头的1和结尾的1, 然后减去2个连续0以上的个数就是答案.

AC代码:

#include "iostream"
#include "cstdio"
#include "cstring"
#include "algorithm"
using namespace std;
const int MAXN = 105;
int n, a[MAXN];
int main(int argc, char const *argv[])
{
    scanf("%d", &n);
    for(int i = 0; i < n; ++i)
        scanf("%d", &a[i]);
    int st = -1, ed = -1;
    for(int i = 0; i < n; ++i) {
        if(a[i] && st == -1) st = i;
        if(a[i]) ed = i;
    }
    if(st == -1) {
        printf("0\n");
        return 0;
    }
    if(ed == -1) {
        printf("1\n");
        return 0;
    }
    int num = 0;
    for(int i = st + 1; i < ed; ++i) {
        if(!a[i]) {
            int x = 1;
            for(int j = i + 1; j < ed; ++j)
                if(!a[j]) x++;
                else break;
            if(x == 1) continue;
            else {
                num += x;
                i += x;
            }
        }
    }
    printf("%d\n", ed - st + 1 - num);
    return 0;
}


B: 给你一个地图, 给出两点之间的距离, 问你从左上角到右下角再回左上角的最短路径(不能相同)是多少.

小小的脑洞, 记录n条路径的总长, 然后排序输出最短的两条和即可.

AC代码:

#include "iostream"
#include "cstdio"
#include "cstring"
#include "algorithm"
using namespace std;
const int MAXN = 60;
int a1[MAXN], a2[MAXN], b[MAXN], n, ans, dis[MAXN];
int main(int argc, char const *argv[])
{
    scanf("%d", &n);
    for(int i = 1; i < n; ++i)
        scanf("%d", &a1[i]);
    for(int i = 1; i < n; ++i)
        scanf("%d", &a2[i]);
    for(int i = 1; i <= n; ++i)
        scanf("%d", &b[i]);
    for(int i = 1; i <= n; ++i) {
        for(int j = 1; j < i; ++j)
            dis[i] += a1[j];
        for(int j = i; j <= n - 1; ++j)
            dis[i] += a2[j];
        dis[i] += b[i];
    }
    sort(dis + 1, dis + n + 1);
    printf("%d\n", dis[1] + dis[2]);
    return 0;
}


C: n个孩子去看牙医, 每个孩子有三个数据描述, 分别是诊断时发出的声音v, 无法承受他人声音时发出的声音d, 以及承受他人声音的

能力p. 当孩子诊断时, 后面一个人听到v - 1的声音, 再后面一个v - 2.. 如果超过自己的承受能力d, 就会向队尾跑去, 伴随着声音p, 同时

也可能会超过其他排队孩子的承受能力, 导致其他孩子跑去队尾.

还是模拟, 要注意用long long, 并且每个孩子听到声音后, 承受能力会减少听到的响应音量.

AC代码:

#include "iostream"
#include "cstdio"
#include "cstring"
#include "algorithm"
using namespace std;
const int MAXN = 4005;
typedef long long ll;
int n, ans;
struct node
{
    /* data */
    ll v, d, p;
}a[MAXN];
int main(int argc, char const *argv[])
{
    scanf("%d", &n);
    for(int i = 1; i <= n; ++i) 
        scanf("%lld%lld%lld", &a[i].v, &a[i].d, &a[i].p);
    for(int i = 1; i <= n; ++i) {
        if(a[i].p >= 0) {
            ll e = 0;
            for(int j = i + 1; j <= n; ++j)
                if(a[j].p >= 0) {
                    a[j].p -= a[i].v + e;
                    if(a[j].p < 0) e += a[j].d;
                    if(a[i].v) a[i].v--;
                }
            ans++;
        }
    }
    printf("%d\n", ans);
    for(int i = 1; i <= n; ++i)
        if(a[i].p >= 0) printf("%d ", i);
    return 0;
}


(一篇即成功)Ubuntu下搭建qt环境和安装Qt Creator 只需一篇就成功搭建Ubuntu下的QT环境 你还在等什么 阅读详情

相关推荐

BurpSuite+安卓模拟器双保险:避开真机抓包限制的完整配置指南

本文详细介绍了如何通过BurpSuite与安卓模拟器(如雷电、夜神)协同工作,绕过真机抓包限制的完整配置指南。从环境准备、网络拓扑配置到证书部署和流量分析,提供了一套高效的解决方案,帮助安全测试人员稳定捕获手机数据包,提升测试效率。

Apple的专栏 418

互联网软件架构 (ABC/S)

互联网软件架构 在前一部分里面提到的应用软件的基本架构,虽然是在 “C/S” 时代提出来的,但是后面却一直延续到现在 。直到今天最普遍的 “ABC/S” 模式: App/ServerBrowser/ServerClient/Server

wuxiaobingandbob的专栏 2027

opencv基础57-模板匹配cv2.matchTemplate()->(目标检测、图像识别、特征提取)

OpenCV 提供了模板匹配(Template Matching)的功能,它允许你在图像中寻找特定模板(小图像)在目标图像中的匹配位置。模板匹配在计算机视觉中用于目标检测、图像识别、特征提取等领域。: 首先,加载目标图像和要匹配的模板图像。: 选择适当的匹配方法,例如 cv2.TM_CCOEFF、cv2.TM_CCOEFF_NORMED、cv2.TM_CCORR、cv2.TM_CCORR_NORMED、cv2.TM_SQDIFF 或 cv2.TM_SQDIFF_NORMED。每种方法对应不同的匹配计算方式。

小海聊智造 1万+

Codeforces Round #467 (Div. 2)T2题解

原题链接 http://codeforces.com/contest/937/problem/B 题目大意 给定两个数p和y,从2-p所有位置都有障碍,且这些障碍可以占领2-y中所有其的倍数 如p=3,y=6 2,3,一开始被占领 2的倍数4,6,被占领 3的倍数6,被占领 问在2-y中最大的未被占领的数是多少。如果全都被占领了,输出-1 题面 B. Vile Grasshop...

WD_louchenhao的博客 419

Codeforces Round #619 (Three Strings)

题目: You are given three strings a, b and c of the same length n. The strings consist of lowercase English letters only. The i-th letter of a is ai, the i-th letter of b is bi, the i-th letter of c is ...

小` pi孩 261

Codeforces Round #325 (Div. 2) C 模拟

链接:戳这里 C. Gennady the Dentist time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard output Gennady is one of the best child dentists in Berlan

Cross 394

Codeforces Round #321 (Div. 2) 580C Kefa and Park(dfs)

题目链接: 第一行给你n、m,接下来的一行有n个数,如果为1则代表这个点有cat,接下来的n-1行每行给出x、y,表示x、y相连。问你从1出发 能到达的叶子结点有几个,要求到达叶子结点的路上连续有cat的点不超过m。 a数组保存结点是否含有cat,从1这个点开始dfs,每次dfs对cat数组操作,记录连续的含有cat的点数,回溯时再判断当前结点是否满足 条件,要求结点为叶子

GKHack's Blog 2034

Codeforces Round #200 (Div. 2)344E Read Time(二分)

E. Read Time time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Mad scientist Mike does not use slow hard disks

GKHack's Blog 1748

Codeforces Round #308 (Div. 2)题解

第二天补的 并不都是自己写的 参考了别人的题解 感觉这次cf题意好懂 就是做起来嘛。。 毕竟我还太弱。。 只为落实 A. Vanya and Table time limit per test 2 seconds memory limit per test 256 megabytes input standard input

GKHack's Blog 1668

Codeforces Round #322 (Div. 2) 581A 581B 581C

581A链接:点击打开链接 给你a只红袜子,b只蓝袜子,问你可以组成多少对颜色不同的袜子以及剩下多少对单色袜子。 小小的脑洞,答案分别为a, b最小值以及a - b绝对值的一半。 AC代码: #include "iostream" #include "cstdio" #include "cstring" #include "algorithm" using na

GKHack's Blog 1660

Codeforces Round #250 (Div. 2) 437C The Child and Toy(脑洞贪心)

C. The Child and Toy time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output On Children's Day, the child got a toy

GKHack's Blog 1623

Codeforces Round #313 (Div. 2) 560D Equivalent Strings(dos)

D. Equivalent Strings time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Today on a lecture about strings Gera

GKHack's Blog 1614

Codeforces Round #315 (Div. 2)569C Primes or Palindromes?(预处理)

C. Primes or Palindromes? time limit per test 3 seconds memory limit per test 256 megabytes input standard input output standard output Rikhail Mubinchik believes that t

GKHack's Blog 1598

Codeforces Round #201 (Div. 2) 347C Alice and Bob(脑洞)

C. Alice and Bob time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output It is so boring in the summer holiday, isn

GKHack's Blog 1582

Manthan, Codefest 16 633C Spy Syndrome 2(dfs + stl)

C. Spy Syndrome 2 time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output After observing the results of Spy Syndro

GKHack's Blog 1571

Codeforces Round #337 (Div. 2) 610D Vika and Segments(线段树)

D. Vika and Segments time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Vika has an infinite sheet of squared

GKHack's Blog 1527

Codeforces Round #250 (Div. 2) 437A The Child and Homework(模拟)

A. The Child and Homework time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Once upon a time a child got a tes

GKHack's Blog 1502

Codeforces Round #315 (Div. 2)569D Symmetric and Transitive(dp)

D. Symmetric and Transitive time limit per test 1.5 seconds memory limit per test 256 megabytes input standard input output standard output Little Johnny has recently le

GKHack's Blog 1500

Codeforces Round #Pi (Div. 2)567A Lineland Mail(模拟)

A. Lineland Mail time limit per test 3 seconds memory limit per test 256 megabytes input standard input output standard output All cities of Lineland are located on the

GKHack's Blog 1478

Codeforces Round #332 (Div. 2) 599C Day at the Beach(脑洞)

C. Day at the Beach time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output One day Squidward, Spongebob and Patric

GKHack's Blog 1450
上一篇: POJ2250 Compromise(dp)
下一篇: Codeforces Round #326 (Div. 2) 588ABC题解
GKHack
博客等级 码龄11年 48粉丝 291原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值