codeforces 698A(暴力)
题意描述
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:
on this day the gym is closed and the contest is not carried out; on this day the gym is closed and the contest is carried out; on this day the gym is open and the contest is not carried out; 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.
给你n个数字,为0的时候表示可以休息,为1的时候表示比赛,为2的时候表示可以健身,为3的时候比赛和健身都可以。不能连续两天比赛或者健身,求能够休息的最少天数
思路
这道题的tag是dp,但被我一顿瞎搞搞过了。需要注意的地方就是为3的时候,如果连续出现了奇数个3,那么第一个3应该是与下一个不为3的相反。例如3 3 3 1,此时的序列应该为2 1 2 1.如果连续出现了偶数个3,那么第一个3应该是与下一个不为3的相同。例如3 3 3 3 1,此时的序列应该为1 2 1 2 1。
AC代码
#include<bits/stdc++.h>
#define x first
#define y second
#define pb push_back
#define IOS ios::sync_with_stdio(false);cin.tie(0);
using namespace std;
typedef unsigned long long ULL;
typedef pair<int,int> PII;
typedef pair<long,long> PLL;
typedef pair<char,char> PCC;
typedef long long LL;
const int N=1005;
const int M=150;
const int INF=0x3f3f3f3f;
const int MOD=1e9+7;
int a[N];
bool st[2];
void solve(){
int n;cin>>n;
for(int i=0;i<n;i++) cin>>a[i];
int ans=0;
for(int i=0;i<n;i++){
if(a[i]==0) ans++,st[0]=false,st[1]=false;
if(a[i]==1 && st[0]) ans++,st[0]=false;
else if(a[i]==1 && !st[0]) st[0]=true,st[1]=false;
if(a[i]==2 && st[1]) ans++,st[1]=false;
else if(a[i]==2 && !st[1]) st[1]=true,st[0]=false;
if(a[i]==3){
if(st[0]) st[1]=true,st[0]=false;
else if(st[1]) st[0]=true,st[1]=false;
else if(!st[0] && !st[1]){
int j=i;
while(j<n && a[j]==3) j++;
if((j-i)&1){
if(a[j]==1 || a[j]==0) st[1]=true;
if(a[j]==2) st[0]=true;
}else{
if(a[j]==1 || a[j]==0) st[0]=true;
if(a[j]==2) st[1]=true;
}
}
}
}
cout<<ans<<endl;
}
int main(){
IOS;
solve();
return 0;
}
- Java 机器学习库Smile实战(一)SVM
- 交易Transaction【区块链生存训练】
- 马尔可夫链文本生成的简单应用:不足20行的Python代码生成鸡汤文
- 最长递增子序列
- dedecms批量删除文档关键词可以吗
- 【学术】在C ++中使用TensorFlow训练深度神经网络
- 一个canonical标签解决site不在首页的问题
- 由一道面试题来了解进程间的通信
- 【教程】简单教程:用Python解决简单的水果分类问题
- 通过html<map>标签给图片加链接
- Windows下安装Scikit-Learn
- 解决后台无法进入提示DedeCMS Error: (PHP 5.3 and above) Please set 'request_order' ini value
- 一文教你实现skip-gram模型,训练并可视化词向量
- 如何将文章列表用<li>分两列显示
- JavaScript 教程
- JavaScript 编辑工具
- JavaScript 与HTML
- JavaScript 与Java
- JavaScript 数据结构
- JavaScript 基本数据类型
- JavaScript 特殊数据类型
- JavaScript 运算符
- JavaScript typeof 运算符
- JavaScript 表达式
- JavaScript 类型转换
- JavaScript 基本语法
- JavaScript 注释
- Javascript 基本处理流程
- Javascript 选择结构
- Javascript if 语句
- Javascript if 语句的嵌套
- Javascript switch 语句
- Javascript 循环结构
- Javascript 循环结构实例
- Javascript 跳转语句
- Javascript 控制语句总结
- Javascript 函数介绍
- Javascript 函数的定义
- Javascript 函数调用
- Javascript 几种特殊的函数
- JavaScript 内置函数简介
- Javascript eval() 函数
- Javascript isFinite() 函数
- Javascript isNaN() 函数
- parseInt() 与 parseFloat()
- escape() 与 unescape()
- Javascript 字符串介绍
- Javascript length属性
- javascript 字符串函数
- Javascript 日期对象简介
- Javascript 日期对象用途
- Date 对象属性和方法
- Javascript 数组是什么
- Javascript 创建数组
- Javascript 数组赋值与取值
- Javascript 数组属性和方法
- RBAC模型与权限系统的梳理(附案例源码)
- Maven项目中常用jar包的坐标以及用法(个人总结)
- MyCat------基于java语言的数据库中间件
- Solr技术(附软件分享)
- VSFTPD技术
- Shiro——基于java的安全框架
- 电子圆二色谱(ECD)的理论计算
- 用 80 行 Javascript 代码构建自己的语音助手
- 手把手教你搭建分布式项目环境
- GraphQL两年实战避坑经验
- 基于Dubbo的服务提供者与消费者的发布(在虚拟机中)以及使用nginx对项目进行负载均衡优化
- 我们为什么不使用CSS框架
- java.lang.IllegalArgumentException: node to traverse cannot be null!
- Spring Data Jpa 异常:PropertyReferenceException: No property xxx found for type for type yyy
- Spring全家桶之SpringData——SpringData Redis(附相关jar包)