Codeforces Round #325 (Div. 2) A. Alena's Schedule 水题
A. Alena's Schedule
Time Limit: 1 Sec
Memory Limit: 256 MB
题目连接
http://codeforces.com/contest/586/problem/A
Description
Alena has successfully passed the entrance exams to the university and is now looking forward to start studying.
One two-hour lesson at the Russian university is traditionally called a pair, it lasts for two academic hours (an academic hour is equal to 45 minutes).
The University works in such a way that every day it holds exactly n lessons. Depending on the schedule of a particular group of students, on a given day, some pairs may actually contain classes, but some may be empty (such pairs are called breaks).
The official website of the university has already published the schedule for tomorrow for Alena's group. Thus, for each of the n pairs she knows if there will be a class at that time or not.
Alena's House is far from the university, so if there are breaks, she doesn't always go home. Alena has time to go home only if the break consists of at least two free pairs in a row, otherwise she waits for the next pair at the university.
Of course, Alena does not want to be sleepy during pairs, so she will sleep as long as possible, and will only come to the first pair that is presented in her schedule. Similarly, if there are no more pairs, then Alena immediately goes home.
Alena appreciates the time spent at home, so she always goes home when it is possible, and returns to the university only at the beginning of the next pair. Help Alena determine for how many pairs she will stay at the university. Note that during some pairs Alena may be at the university waiting for the upcoming pair.
Input
The first line of the input contains a positive integer n (1 ≤ n ≤ 100) — the number of lessons at the university.
The second line contains n numbers ai (0 ≤ ai ≤ 1). Number ai equals 0, if Alena doesn't have the i-th pairs, otherwise it is equal to 1. Numbers a1, a2, ..., an are separated by spaces.
i,Ci,即此题的初始分值、每分钟减少的分值、dxy做这道题需要花费的时间。
Output
Print a single number — the number of pairs during which Alena stays at the university.
Sample Input
5
0 1 0 1 1
Sample Output
4
HINT
题意
有人要去上课,1代表有课,0代表没课
这个人在有两个及以上连续的没课的时候,才会回家
然后问你这个人得在学校呆多久
题解:
直接暴力扫一遍就好了
有课会呆在学校,没课但是,上下都是课的,也会呆在学校
代码:
#include<stdio.h>
#include<iostream>
#include<math.h>
#include<iostream>
using namespace std; int a[];
int main()
{
int n;
scanf("%d",&n);
for(int i=;i<=n;i++)
scanf("%d",&a[i]);
int ans = ;
for(int i=;i<=n;i++)
{
if(a[i]==)
ans++;
if(a[i]==&&a[i-]==&&a[i+]==)
ans++;
}
cout<<ans<<endl;
}
Codeforces Round #325 (Div. 2) A. Alena's Schedule 水题的更多相关文章
- Codeforces Round #325 (Div. 2) A. Alena's Schedule 暴力枚举 字符串
A. Alena's Schedule time limit per test 1 second memory limit per test 256 megabytes input standard ...
- Codeforces Round #297 (Div. 2)A. Vitaliy and Pie 水题
Codeforces Round #297 (Div. 2)A. Vitaliy and Pie Time Limit: 2 Sec Memory Limit: 256 MBSubmit: xxx ...
- Codeforces Round #290 (Div. 2) A. Fox And Snake 水题
A. Fox And Snake 题目连接: http://codeforces.com/contest/510/problem/A Description Fox Ciel starts to le ...
- Codeforces Round #322 (Div. 2) A. Vasya the Hipster 水题
A. Vasya the Hipster Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/581/p ...
- Codeforces Round #373 (Div. 2) B. Anatoly and Cockroaches 水题
B. Anatoly and Cockroaches 题目连接: http://codeforces.com/contest/719/problem/B Description Anatoly liv ...
- Codeforces Round #368 (Div. 2) A. Brain's Photos 水题
A. Brain's Photos 题目连接: http://www.codeforces.com/contest/707/problem/A Description Small, but very ...
- Codeforces Round #359 (Div. 2) A. Free Ice Cream 水题
A. Free Ice Cream 题目连接: http://www.codeforces.com/contest/686/problem/A Description After their adve ...
- Codeforces Round #355 (Div. 2) A. Vanya and Fence 水题
A. Vanya and Fence 题目连接: http://www.codeforces.com/contest/677/problem/A Description Vanya and his f ...
- Codeforces Round #384 (Div. 2) A. Vladik and flights 水题
A. Vladik and flights 题目链接 http://codeforces.com/contest/743/problem/A 题面 Vladik is a competitive pr ...
随机推荐
- Eclipse下Preferences解析
General列表下: Keys设置快捷键 Appearance->Colors and Fonts->Text-Font设置字体和大小 Appearance->Startup an ...
- jquery serialize()方法的扩展
Jquery提供的序列化表单方法serialize方法确实方便,但是我在使用的时候发现了一个弊端:当我使用type:“post”进行ajax请求的时候, 这个时候参数data:$("#myf ...
- P2P编程(十)
此为网络编程的一个系列,后续会把内容补上....
- OK335xS davinci mdio driver hacking
/******************************************************************************* * OK335xS davinci m ...
- Linux中的文件特殊权限
linux中除了常见的读(r).写(w).执行(x)权限以外,还有3个特殊的权限,分别是setuid.setgid和stick bit 1.setuid.setgid 先看个实例,查看你的/usr/b ...
- JDBC 与ODBC的区别
一.ODBC(Open DataBase Connectivity : 开放数据库连接) ODBC 总体结构 应用程序 执行处理并调用odbc函数,提交sql语 ...
- Android ViewTreeObserver简介
Android ViewTreeObserver简介 一.结构 public final class ViewTreeObserver extends Object java.lang.Objec ...
- NGINX(六)扩展
前言 nginx模块化设计, 添加扩展模块变得容易, 下面开发一个非常简单的扩展模块, 实现返回http请求的头部内容, 配置标记是ping_pong, 配置在NGX_HTTP_LOC_CONF中. ...
- Ofbiz 10.04 + eclipse 安装与配置
1.下载 ofbiz 10.04:http://ofbiz.apache.org/download.html: 2.下载 freemarker-2.3.15 eclipse 插件(FreeMarker ...
- 设计模式_Strategy_策略模式
形象例子: 跟不同类型的MM约会,要用不同的策略,有的请电影比较好,有的则去吃小吃效果不错,有的去海边浪漫最合适,单目的都是为了得到MM的芳心,我的追MM锦囊中有好多Strategy哦.策略模式: 策 ...