Codeforces Round #265 (Div. 2) B. Inbox (100500)
2014-09-17 14:36
447 查看
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
Output
Input
Output
Input
Output
[/code]
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
5 0 1 0 1 0
Output
3
Input
5 1 1 0 0 1
Output
4
Input
2 0 0
Output
0 题意:查看邮件,求需要操作的次数 思路:题意题,模拟 [code]#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> 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 && ans) ans--; else if (num ) ans++; printf("%d\n", ans); return 0; }
[/code]
相关文章推荐
- Codeforces Round #265 (div2) B. Inbox (100500)
- Codeforces Round #265 (Div. 2) B. Inbox (100500)(模拟)
- Codeforces Round #265 (Div. 2) B. Inbox (100500)
- Codeforces Round #265 (Div. 2) C. No to Palindromes! 构造不含回文子串的串
- Codeforces Round #265 (Div. 2)
- Codeforces Round #265 (Div. 2)
- Codeforces Round #265 (Div. 2) C - No to Palindromes!
- Codeforces Round #265 (Div. 2) C. No to Palindromes!(字符串+构造??)
- Codeforces Round #265 (Div. 2)
- Codeforces Round #265 (Div. 2) D. Restore Cube 立方体判断
- Codeforces Round #265 (Div. 2) C. No to Palindromes! 构建无回文串子
- Codeforces Round #265 (Div. 2) 解题报告
- Codeforces Round #265 (Div. 2) E
- Codeforces Round #265 (Div. 2) D. Restore Cube 立方体判断
- Codeforces Round #265 (div2) A. inc ARG
- Codeforces Round #265 (Div. 2) D. Restore Cube
- Codeforces Round #265 (Div. 2)D(判断立方体)
- Codeforces Round #265 (Div. 2)D. Restore Cube 暴力
- Codeforces Round #265 (Div. 2) E. Substitutes in Number
- Codeforces Round #265 (Div. 2) 题解