博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Codeforces Round #265 (Div. 2) B. Inbox (100500)
阅读量:6448 次
发布时间:2019-06-23

本文共 1994 字,大约阅读时间需要 6 分钟。

Over time, Alexey's mail box got littered with too many letters. Some of them are read, while others are unread.

Alexey's mail program can either show a list of all letters or show the content of a single letter. As soon as the program shows the content of an unread letter, it becomes read letter (if the program shows the content of a read letter nothing happens). In one click he can do any of the following operations:

  • Move from the list of letters to the content of any single letter.
  • Return to the list of letters from single letter viewing mode.
  • In single letter viewing mode, move to the next or to the previous letter in the list. You cannot move from the first letter to the previous one or from the last letter to the next one.

The program cannot delete the letters from the list or rearrange them.

Alexey wants to read all the unread letters and go watch football. Now he is viewing the list of all letters and for each letter he can see if it is read or unread. What minimum number of operations does Alexey need to perform to read all unread letters?

Input

The first line contains a single integer n (1 ≤ n ≤ 1000) — the number of letters in the mailbox.

The second line contains n space-separated integers (zeros and ones) — the state of the letter list. The i-th number equals either 1, if the i-th number is unread, or 0, if the i-th letter is read.

Output

Print a single number — the minimum number of operations needed to make all the letters read.

Sample test(s)
Input
50 1 0 1 0
Output
3
Input
51 1 0 0 1
Output
4
Input
20 0
Output
0题意:查看邮件,求须要操作的次数思路:题意题,模拟
#include 
#include
#include
#include
using namespace std;int main() { int n, num[1010]; scanf("%d", &n); for (int i = 1; i <= n; i++) scanf("%d", &num[i]); int ans = 0; for (int i = 0; i < n; i++) if (num[i] && num[i+1]) ans++; else if (num[i] && !num[i+1]) ans += 2; if (!num[n] && ans) ans--; else if (num[n]) ans++; printf("%d\n", ans); return 0;}

转载地址:http://pklwo.baihongyu.com/

你可能感兴趣的文章
NetApp FAS2240-4存储删除文件数据恢复
查看>>
技术人在学习爱的路上
查看>>
LVS -NAT模式配置实例
查看>>
北航 2012 秋季 现代软件工程 团队项目要求
查看>>
获取通讯组属性Get-DistributionGroup
查看>>
"知识管理夏季论坛",免费,欢迎你来!
查看>>
常用DOS命令
查看>>
能上QQ上不了网的解决办法
查看>>
flask + Python3 实现的的API自动化测试平台---- IAPTest接口测试平台
查看>>
【翻译】将Ext JS Grid转换为Excel表格
查看>>
关于人工智能的几个问题
查看>>
个人阅读作业2
查看>>
解决百度上传WebUploader在IE浏览器下点击无反应的问题
查看>>
Oracle常用函数 - 字符函数
查看>>
Linux shell脚本的字符串截取
查看>>
Zendstudio导入项目报错:overlaps the location of another
查看>>
Shell 标准输入、输出和错误
查看>>
Cisco设备配置AAA认证!
查看>>
UDP怎么会返回Connection refused错误
查看>>
上海i虹桥机场点烟器与UNIX哲学
查看>>