Codeforces 699 C. Vacations ( 贪心

Codeforces Round #363 (Div. 2) [C] Vacations C. Vacations time limit per test 1 second memory limit per test 256 megabytes input standard input output standard outputVasya has n days of vacations! So he decided to improve his IT skills an 阅读详情
C. 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 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.

题意::
一个人在一天内有四种选择

  • 休息,运动||休息,工作||休息,运动||工作
  • 工作或者运动不能连续超过两天,求最短的休息时间

    重点就是不要连续超过两天就可以
    数据比较小,暴力就可以AC了
  • #include<stdio.h>
    int arr[105];
    int main()
    {
        int n;
        while(~scanf("%d",&n)) {
            for(int i = 0;i < n; i++) 
                scanf("%d",&arr[i]);
                int k = 0, flag = 0;
            for(int i = 0;i < n; i++) {
                if(arr[i] == 0) {
                    k++;
                    flag = 0;
                }
                else if(arr[i]==1 || arr[i]==2) {
                    if(flag == arr[i]) {
                        k++;
                        flag = 0;
                    }
                    else 
                        flag =arr[i];
                }
                else {
                    if(flag == 1) {
                        flag = 2;
                    }
                    else if(flag == 2) {
                        flag = 1;
                    }
                }
            }
            printf("%d\n",k); 
        }
    return 0;
    }
将3DMax编辑的动画,导入给已经绑定蒙皮好的模型给Unity使用 现在程序猿想做独立游戏,即容易,也难。 说容易,引擎越来越傻瓜化。 说难,到哪去找靠谱的美术? 好在伟大的AssetStore(还有淘宝上)有大批不赖的资源可以用。 现成的模型,是好,但是,没有配套的动作,却是一件让人头疼的事情,即使用IK动画,也不能完美的弥补这一缺陷。 虽然Unity具备 retargeting 功能,但是,也不是万能的,很多情况下,非标准的骨骼会导致 阅读详情

相关推荐

Docker版OnlyOffice中文字体配置全攻略:从字号调整到字体添加

本文详细介绍了在Docker版OnlyOffice中配置中文字体和调整字号的完整方案。通过容器内操作和配置文件修改,实现中文标准字号映射及思源、阿里巴巴等优质字体的集成,提升文档排版的规范性和专业性。特别针对企业级部署提供了性能优化建议和常见问题解决方案。

weixin_28309571的博客 139

Vacation题解及其延申---线性dp

上一瓶插哪朵花,这样我们可以顺着pre数组逆推回去,同时还要注意的一点在于再遍历第j种花时由于当前一个花与花瓶的序号小于等于后一个花与花瓶的序号,即说明在遍历时后一个状态只能在区间。表示前i天且第i天进行第j个活动的最大值,由于连续两天不相同,我们可以枚举今天与前一天进行了哪些活动进行状态转移,最后记录这些状态的最大值,时间复杂度。这里我简要只讲我的思路,详情可以做一做,这题目首先我们可以发现这题的状态转移方程并没有发生改变,进行(要留下足够的花瓶),遍历一边即可,时间复杂度。

2401_82728478的博客 582

【小程序】支付宝直付通解决方案

支付宝直付通是支付宝为小程序提供的一种支付解决方案,可以实现小程序中直接使用支付宝进行支付。以上是一个简单的支付宝直付通解决方案及相关代码示例。具体的使用还需要根据自己的业务需求进行定制化开发和调整。

qq_31532979的贺公子之数据科学与艺术博客,致力于科技向善,拥抱开源,要用技术的影响力来领导团队,而不是威权和职位! 1287

UVA 10192 Vacation(dp + LCS)

Problem E: Vacation  The Problem You are planning to take some rest and to go out on vacation, but you really don't know which cities you should visit. So, you ask your parents for hel

Remilia's 1089

智能排班考勤系统原型

可实现从业务预测,到工时预估,再到人员分配全流程自动智能排班。可应用于客服行业或工厂的智能排班系统。

gywm15111336483的专栏 999

AI驱动视频剪辑自动化:cutcli命令行工具重塑工作流

视频剪辑自动化是提升内容生产效率的关键技术,其核心原理在于通过程序化指令替代手动操作,将创意执行过程代码化。这项技术的价值在于能够将创作者从重复性劳动中解放,实现批量化、标准化的视频内容生产,尤其适用于社交媒体运营、产品宣传等高频产出场景。通过封装专业软件(如剪映/CapCut)的底层草稿格式,自动化工具在保证工业级渲染质量的同时,提供了可编辑的中间态,为AI智能体(Agent)与生产工具的结合提供了清晰接口。本文以cutcli为例,深入探讨了如何通过命令行工具和AI助手,构建从自然语言指令到可编辑视频草稿

weixin_27210125的博客 1083

UVA - 10192 Vacation(dp+最大公共子序列)

解析:求两个字符串的最大公共子序列的个数

小G的ACM之路 710

Python量化入门:用pytdx获取800个交易日K线数据的完整指南(附代码)

本文为Python量化交易初学者提供了使用pytdx库免费获取股票日线级别K线数据的完整指南。文章详细介绍了从环境搭建、单只股票数据获取,到构建健壮的批量下载器、数据清洗与验证,再到基础分析与可视化的全流程,并附有可直接运行的代码示例,帮助读者快速建立本地股票数据库。

weixin_29050513的博客 1494

CF698A. Vacations【DP】

题目链接http://codeforces.com/problemset/problem/698/A思路设dp[i][j]表示在第i天干第j种事情,前i天的最小休息天数。 j=0表示休息,1打代码,2运动。不可能的状态置为INF,转移方程就很简单了,具体见代码。 比赛时愣是没想到用dp,早上瞄一眼题解才发现这么简单,总归还是太弱了。AC代码#include <iostream> #include

初涉_代码世界 1044

PSINS工具箱学习(四)捷联惯导更新算法

原始 Markdown文档、Visio流程图、XMind思维导图见:https://github.com/LiZhengXiao99/Navigation-Learning。

实践出真理,接毕设/课设项目开发指导 610

华为OD面试手撕真题 【合并相邻且相等的元素】多语言题解

华为OD面试高频手撕真题【合并相邻且相等的元素】,提供C语言、Java、C++、Python、Go、JavaScript源码实现,并提供完整思路讲解。

qq_45776114的博客 569

2016 北邮暑期训练3-D题(Codeforces 698A Vacations)DP,水题

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 c

1202

github中文汉化插件安装教程

本章教程,主要介绍如何汉化github网页,有部分小伙伴阅读英文版的网页可能比较吃力,想汉化一下页面,在网上收集了一些资料,总结了一下当前可用的汉化教程。

猿小白的博客 3529

CodeForces 699C Vacations 贪心

CF传送门 题意:   1. Vasya放假了,然后他的假期的每一天有四种情况         0代表:体育馆关门,并且没有比赛(什么都没有,只能休息了)         1代表:体育馆关门,但有比赛(可以打比赛,也可以休息)         2代表:体育馆开门,但没有比赛(可以体育活动,也可以休息)         3代表:体育馆开门,并且有比赛(可以体育活动,可以比赛,可以休息

三生锁链 1108

怀旧版电脑GBC模拟器

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

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

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

CodeForces 699C Vacations (贪心)

题目: 传送门 思路: 不能连续两天干同一件事,从贪心的角度我们每次可以让连续的第二天休息,因为如果选择第二天对后面的选择只有两种可能,影响 (即第三天跟第二天相同) 或者不影响(即第三天跟第二天不相同),如果不影响,我们选择 第一天休息和第二天休息的结果不影响,如果影响,我们当然选择第二天休息更优,综上所述,我们每次都选则第二天休息就可以了. 对于两件事都能干的那天,我们尽量保证这天不休息,我们...

JingluoZZZ 244

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

codeforces 699C Vacations (贪心)

解题思路:直接判断每一天的情况,能不休息尽量不让他休息,分情况讨论一下~ #include // using namespace std; int a[105]; int ans; int main() { int n,i; cin>>n; for(i=1;i<=n;i++) cin>>a[i]; for(i=1;i<n;i++) {

wchhlbt的博客 1344

全球国家地区城市数据

MySQL全球国家地区城市数据报。。。。。。。。。。。。

【CodeForces】699C - Vacations(贪心)

点击打开题目 C. 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

wyg1997 752

F - vacations CodeForces - 699C 【贪心】

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

HPUZJH 235

Codeforces698A 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

Megumin的博客 746

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

Vacations(dp)

题目链接: Vacations 大致题意: 有三种状态:0表示休息,1表示学习,2表示运动,三表示学习运动二选一 给出n种状态,问最少可以休息几天(连续两天不能做同一件事) 解题思路: dp[i][j]来表示第i天做j事的最小休息天数 AC代码: #include <bits/stdc++.h> using namespace std; const int N = 200, INF = 0x3f3f; int n; int a[N]; int f[N][4]; int main() {

qq_49494204的博客 236

Vacations

Vacations Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submit Status Practice CodeForces 698A Description Vasya has n days of vacations! So he deci

wjhuihuii的博客 442

Vacations(动态规划加贪心)

Vacations Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submit Status Description Vasya has n days of vacations! So he decided to improve his IT skills

昨日明眸 1156

B - 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

galesaur_wcy 295

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

开始的地方 276
上一篇: codeforces 753 A. Dasha and Stairs
下一篇: 51Nod 1009 数字1的数量 (数学
Yishui_Blog
博客等级 码龄10年 96粉丝 524原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值