Codeforces698A Vacations

MPU6050 加速度计和陀螺仪传感器与 Arduino 的接口 虽然该模型并不能准确代表现实世界中加速度计传感器的构建方式,但它通常有助于理解为什么加速度计的输出信号通常以 ±g 为单位指定,或者为什么加速度计在静止时在 z 轴上的读数为 1g,或者在不同方向上您可以期望得到什么样的加速度计读数。该模块的核心是低功耗、低成本的 6 轴运动跟踪芯片 MPU6050,它将 3 轴陀螺仪、3 轴加速度计和数字运动处理器 (DMP) 集成到一个 4mm x 4mm 的微型芯片中。小时候,科学博览会上的陀螺仪总是让我们感到惊讶,因为它们以奇怪的方式移动,甚至似乎违背了重力。 阅读详情

Vasya has n days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this n days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the i-th day there are four options:

  1. on this day the gym is closed and the contest is not carried out;
  2. on this day the gym is closed and the contest is carried out;
  3. on this day the gym is open and the contest is not carried out;
  4. on this day the gym is open and the contest is carried out.

On each of days Vasya can either have a rest or write the contest (if it is carried out on this day), or do sport (if the gym is open on this day).

Find the minimum number of days on which Vasya will have a rest (it means, he will not do sport and write the contest at the same time). The only limitation that Vasya has — he does not want to do the same activity on two consecutive days: it means, he will not do sport on two consecutive days, and write the contest on two consecutive days.

Input

The first line contains a positive integer n (1 ≤ n ≤ 100) — the number of days of Vasya's vacations.

The second line contains the sequence of integers a1, a2, ..., an (0 ≤ ai ≤ 3) separated by space, where:

  • ai equals 0, if on the i-th day of vacations the gym is closed and the contest is not carried out;
  • ai equals 1, if on the i-th day of vacations the gym is closed, but the contest is carried out;
  • ai equals 2, if on the i-th day of vacations the gym is open and the contest is not carried out;
  • ai equals 3, if on the i-th day of vacations the gym is open and the contest is carried out.
Output

Print the minimum possible number of days on which Vasya will have a rest. Remember that Vasya refuses:

  • to do sport on any two consecutive days,
  • to write the contest on any two consecutive days.
Examples
input
4
1 3 2 0
output
2
input
7
1 3 3 2 1 2 3
output
0
input
2
2 2
output
1
Note

In the first test Vasya can write the contest on the day number 1 and do sport on the day number 3. Thus, he will have a rest for only 2 days.

In the second test Vasya should write contests on days number 1, 3, 5 and 7, in other days do sport. Thus, he will not have a rest for a single day.

In the third test Vasya can do sport either on a day number 1 or number 2. He can not do sport in two days, because it will be contrary to the his limitation. Thus, he will have a rest for only one day.


动态规划题,因为每一天的选择只与前一天所做的事有关,故用一个数 s 去表示上一天的状况,进行递推即可。


#include <iostream>
#include <cstdio>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <string>
using namespace std;
#define INF 0x3f3f3f3f
typedef long long LL;
int a[105],dp[105];
int main()
{
    int n;
    while(~scanf("%d",&n)){
        for(int i=1;i<=n;i++){
            scanf("%d",&a[i]);
        }
        dp[0]=0;
        int s=0;
        for(int i=1;i<=n;i++){
            if(a[i]==0){
                dp[i]=1+dp[i-1];
                s=0;
            }
            else if(a[i]==1||a[i]==2){
                if(a[i]==s){
                    dp[i]=dp[i-1]+1;
                    s=0;
                }else{
                    dp[i]=dp[i-1];
                    s=a[i];
                }
            }else{
                dp[i]=dp[i-1];
                s=3-s;
            }
        }
        printf("%d\n",dp[n]);
    }
    return 0;
}



LeRobot 入门教程(十一)π0(Pi0)π0.5(Pi0.5)训练、推理、部署 本文介绍了Physical Intelligence公司开发的π₀和π₀.₅系列通用机器人控制视觉-语言-动作模型。π₀作为首款基础模型,融合流匹配、跨实体训练等技术,支持50Hz高频控制。π₀.₅是其升级版,通过异构数据协同训练解决开放世界泛化问题,在Libero基准测试中表现优异。文章详细说明了两个模型的安装要求、使用方法、训练策略及关键参数配置,包括混合精度训练、梯度检查点等优化技术,为机器人在多样化场景中的语义理解和动作控制提供了完整解决方案。 阅读详情

相关推荐

微调BERT进行中文文本分类任务(Pytorch代码实现)

BERT(Bidirectional Encoder Representation from Transformers)是2018年10月由Google AI研究院提出的一种预训练模型。其模型结构由多层Transformer的Encoder堆叠而成,在大规模语料中进行预训练后,迁移到下游任务,仅进行参数微调训练,就能显著提升性能。本文聚焦于微调中文BERT进行新闻标题分类任务的代码实现。

Iswayzw的博客 1万+

vacations 暴力求解

Vasya has n days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this n days: whether that gym opened and whether a contest was c...

君卿的博客 325

程序进入hardfault之后查找原因的方法

如果在MCU运行程序的时候,进入了hardfault,该怎么办?

smart_boy__的博客 766

Code Forces 698A Vacations

题目描述 Vasya hasnndays of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of thisnndays: whether that gym opened and whether a ...

dfssbqyrq96616258的博客 227

数字频率计设计中的常见误区:从VHDL代码到硬件实现的避坑指南

本文深入探讨了数字频率计从VHDL代码到FPGA硬件实现过程中的关键误区与解决方案。重点分析了闸门时间生成的精度与资源平衡、控制时序设计中的竞争冒险规避,以及如何利用EDA工具进行综合、时序约束与调试,确保设计稳定可靠。文章为开发者提供了从仿真成功到硬件可用的实战避坑指南。

spark7igniter的博客 217

网工最容易搞混的三个概念:防火墙、网闸、堡垒机,一文让你轻松搞明白。

网闸的作用可以简单概括为:在两个或多个不同安全级别的网络(如内网和外网、普通网与高安全网、受限网与互联网)之间建立一个严格隔离、信息流转的安全桥梁。它的核心任务是实现数据安全传输与隔离,避免网络之间的直接连接带来的安全隐患。数据传输安全:网闸保证数据从一个网络到另一个网络时,能够进行审查、过滤和转换,防止恶意数据或非法信息被传入内部网络或外部泄露。高安全性隔离:网闸常常用于企业的内外网隔离、军事网络、政府机关等对数据隔离要求极高的环境。

HWP18612324139的博客 3650

[编程题]假期

时间限制:C/C++ 2秒,其他语言4秒 空间限制:C/C++ 256M,其他语言512M 由于业绩优秀,公司给小Q放了 n(0<=n<=100000)天的假,身为工作狂的小Q打算在在假期中工作、锻炼或者休息。他有个奇怪的习惯:不会连续两天工作或锻炼。只有当公司营业时,小Q才能去工作,只有当健身房营业时,小Q才能去健身,小Q一天只能干一件事。给出假期中公司,健身房的营业情况,求小Q最少需要休息几天。 输入描述: 第一行一个整数表示放假天数 第二行 n 个数 每个数为0或1,第 i...

jinduo16的博客 469

【深度学习新浪潮】深度学习特别是大模型在图像配准方面的研发进展

深度学习,尤其是大模型的出现,彻底改变了图像配准的技术范式——从“手工设计特征+几何约束”走向“数据驱动+通用特征学习”。当前,大模型配准已在医学影像、遥感、工业检测等领域实现商业化落地,解决了传统方法难以应对的跨模态、少样本、复杂形变等问题。但大模型配准仍面临推理效率、可解释性、数据隐私等挑战,未来的研发核心将是“精度与效率的平衡”“泛化能力的提升”“场景化适配的简化”。对于开发者而言,从简化版大模型配准代码入手,逐步理解预训练+微调的核心逻辑,是衔接前沿技术的有效路径。

专注:太空算力、AI infra、异构调度、大模型成本工程 431

vacations

Vasya has n days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this n days: whether that gym opened and whether a contest was c...

WhileTrue 233

结构化数据特征构建神器openfe的实战代码

最近订阅专栏的几位同学一起参加了AI比赛,该比赛的数据形式是结构化的。随着特征和模型的不断迭代优化,达到了一个难以跨越的瓶颈。希望我能够给出一些有效的方法,帮助他们提高成绩。在个人的调研和体验后,向他们推荐了结构化数据特征构建神器openfe,最终也帮助他们提升了十来名的成绩,个人也感到十分的欣慰。特意写此博客,希望能够帮助更多的同学。 文章目录 1. 安装 2. 实战例子一 3. 实战例子二

herosunly的博客 3万+

ESP32-C3模组上实现蓝牙BLE配网功能(1)

ESP32-C3模组上实现蓝牙BLE配网功能(1)

phmatthaus的专栏 2284

贪心算法——Vacations

Vasya has n days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this n days: whether that gym opened and whether a contest was c...

xiang_hehe的博客 294

一个 ABAP 工具,能打印系统里某个用户对 BSP 应用的浏览历史记录

只要一个用户在 SAP ABAP 系统里浏览过 BSP 页面,会留下浏览历史记录。本工具会解析出这些记录,打印出该用户浏览的历史事件,和浏览过的页面名称。

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 551

【CodeForces】[698A]Vacations

需要注意问的是至少休息多少天 所以要让a[i]==0的天数尽量少从前到后 如果a[i]==3 那么如果a[i-1]==1 那a[i]=2 如果a[i-1]==2 那a[i]=1如果在循环开始就有3的话则不用考虑 因为无论3有多少个都可以组合成有事天数 对结果没有影响如果a[i]==a[i-1] 那么把a[i]更新为0

BoilTask Talk Show 477

ET2012新版免狗免安装绿色软件

ET2012新版免狗免安祖昂绿色软件。,新界面,新视觉,

复分析 阿尔福斯(Ahlfors) 第三版答案 英文

答案分为十章,有部分习题没有答案,全英文复分析阿尔福斯(Ahlfors) 第三版答案

CodeForces 698A Vacations

2016暑期集训3-DCodeForces 698A多个状态同时DP 传送门:HustOJ 传送门:CodeForce 题意小崔同学很喜欢运动,也很喜欢打比赛,他每天只能选择一种活动。但是体育馆并不是每天都开,比赛也不是天天有。并且他不想连续两天做相同的事情(除了歇着。。。),输入 n 天,每天的状态(4种),求小崔休息的最少天数。思路 状态 f[i][j]表示前i天,第i天做了j事

P.H.S 353

怀旧版电脑GBC模拟器

再现原版GBC掌机的界面,电脑运行连游戏界面都一样大小,很怀旧,很真实,(英文版)强烈推荐,很小的文件,很难才找到的。

Codeforces 698A Vacations

题意: Vasya有n天可以安排,0表示一定要休息,1表示可以去比赛或者休息,2表示可以去健身或者休息,3表示可以去比赛或者健身或者休息,且不能连续的两天进行竞赛或者健身,问他最少需要休息几天。 思路: 枚举。若出现3,判断下前一个是1或者2,如果是则将3置为2或者1,如果不是不用管,若出现连续的两个1或者2将第二个置为0。 #include const int MAX=105; int

w446506278的博客 677

jdk-8u144-linux-x64.tar.gz.

该资源为搭建Linux系统Java环境用,资源的后缀为tar.gz格式的压缩包

codeforces 698A Vacations

A. Vacations time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Vasya has n days of vacations! So he decided to

shyoldman的博客 850

CodeForces - 698A Vacations 贪心 dp

Vasya has n days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this n days: whether that gym opened and whether a contest was

liluoyu_1016的博客 409

CodeForces-698A Vacations(水题)

题目链接:http://codeforces.com/problemset/problem/698/A点击打开链接 A. Vacations time limit per test 1 second memory limit per test 256 megabytes input standard input output sta

xuejye的博客 573

CodeForces 698A Vacations(贪心)

Description Vasya has n days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this n days: whether that gym opened and whether a

菜鸟的自我修养 510

Codeforces 698A:Vacations(DP)

题目链接:http://codeforces.com/problemset/problem/698/A 题意 Vasya在n天中,有三件事情可以做,健身、比赛或者休息,但是不能连续两天都是比赛或都是但是健身,但是连续休息两天是允许的,问题是在这n天中,Vasya最少可以休息几天? 0代表休息,1代表比赛,2代表健身,3可以代表比赛也可以代表健身 思路 用数组dp[i][j]表示第i天...

执念 310

【动态规划】Codeforces 698A & 699C Vacations

题目链接:   http://codeforces.com/problemset/problem/699/C 题目大意:   N天,A健身或B做比赛或休息,每天都有4种情况,A可行B可行,A可行B不行,A不行B可行,AB都不行。   每天选择一种,不能连续两天选择同一种活动(可以连续休息),问最少休息几天。 题目思路:   【动态规划】   f[i][

Coolxxx的博客 464

CodeForces - 698A ——Vacations(dp)

Vasya hasndays of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of thisndays: whether that gym opened and whether a contest was c...

red_red_red的博客 173

codeforces 698A. Vacations

传送门儿 题目大意:给一个序列限制条件(体育馆开放与否、考试与否),问你这n天最少有几天闲着。 方法:dp。 分析:每天对应三种状态:闲着、锻炼、考试。 定义状态:dp[i][0]闲着 dp[i][1]锻炼 dp[i][2]考试 dp表示i天前最多能有几天不闲着(最后用n-不闲着的天数就ok) 每个状态的转移有条件限制: 0休息:无条件 (易错,休息的条件并不是0,因为哪天都能休息) 1锻炼:2 || 3 2考试:1 || 3 补充:codeforces1195C这道题每个i也是三种状态,不一样的

czyhbo的博客 251
上一篇: Codeforces699B One Bomb 暴力
下一篇: OpenJudge 海贼王之伟大航路 DFS+状态压缩
Megumin
博客等级 码龄10年 3粉丝 89原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值