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 ...
随机推荐
- poj 1459 Power Network(增广路)
题目:http://poj.org/problem?id=1459 题意:有一些发电站,消耗用户和中间线路,求最大流.. 加一个源点,再加一个汇点.. 其实,过程还是不大理解.. #include & ...
- poj1948
很容易想到dp,f[i,j,k]表示到第i根木棒所组成三条边中两条边长为j,k是否存在 之后找所有满足三角形形成条件的三条边,然后找最大: 但: 如果你朴素的写,很有可能超时,事实上,只要加一些常数优 ...
- Xcode8安装不成功, 需要升级系统. The operation couldn't be completed. cpio read error
https://developer.apple.com/library/prerelease/content/documentation/DeveloperTools/Conceptual/Whats ...
- a标签中的label在IE下触发不了a标签的href链接(label标签——解析)
<a href="http://www.baidu.com/" target="_blank"> <span>百度</span&g ...
- 【转】Eclipse配置Struts2问题:ClassNotFoundException: org...dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
我的解决方案 一开始,我是依照某本教材,配置了User Libraries(名为struts-2.2.3, 可供多个项目多次使用), 然后直接把struts-2.2.3引入过来(这个包不会真正的放在项 ...
- CXF之二(CXF发布webService)
Apache CXF提供了用于方便地构建和开发WebService的可靠基础架构.它允许创建高性能和可扩展的服务,可以部署在Tomcat和基于spring的轻量级容器中,也可以部署在更高级的服务器上, ...
- dephi WaitForMultipleObjects 用法
在Delphi中WaitForMultipleObjects的使用 procedure ThreadTest;stdcall; var Handles:TWOHandleArray; //Hand ...
- 树莓PI安装jdk1.8,ant,maven【转】
http://the.taoofmac.com/space/hw/RaspberryPi/JDK%20Installation jdk--------------------------------- ...
- 怎么解决div覆盖内容却没覆盖的问题?
一.在上下结构的div布局中,可能出现div覆盖div,但是内容却没有出现覆盖的现象.看看一个示例 1: <!DOCTYPE html> 2: <html> 3: <he ...
- office在线预览方案
一.服务器先转换为PDF,再转换为SWF,最后通过网页加载Flash预览 微软方:利用Office2007以上版本的一个PDF插件SaveAsPDFandXPS.exe可以导出PDF文件,然后再利用免 ...