B. Vasya's Calendar
来源:互联网 发布:it 工作 编辑:程序博客网 时间:2024/05/09 12:18
Vasya lives in a strange world. The year has n months and the i-th month has ai days. Vasya got a New Year present — the clock that shows not only the time, but also the date.
The clock's face can display any number from 1 to d. It is guaranteed that ai ≤ d for all i from 1 to n. The clock does not keep information about the current month, so when a new day comes, it simply increases the current day number by one. The clock cannot display number d + 1, so after day number d it shows day 1 (the current day counter resets). The mechanism of the clock allows you to increase the day number by one manually. When you execute this operation, day d is also followed by day 1.
Vasya begins each day checking the day number on the clock. If the day number on the clock does not match the actual day number in the current month, then Vasya manually increases it by one. Vasya is persistent and repeats this operation until the day number on the clock matches the actual number of the current day in the current month.
A year passed and Vasya wonders how many times he manually increased the day number by one, from the first day of the first month to the last day of the n-th month inclusive, considering that on the first day of the first month the clock display showed day 1.
The first line contains the single number d — the maximum number of the day that Vasya's clock can show (1 ≤ d ≤ 106).
The second line contains a single integer n — the number of months in the year (1 ≤ n ≤ 2000).
The third line contains n space-separated integers: ai (1 ≤ ai ≤ d) — the number of days in each month in the order in which they follow, starting from the first one.
Print a single number — the number of times Vasya manually increased the day number by one throughout the last year.
422 2
2
533 4 3
3
311231 28 31 30 31 30 31 31 30 31 30 31
7
In the first sample the situation is like this:
- Day 1. Month 1. The clock shows 1. Vasya changes nothing.
- Day 2. Month 1. The clock shows 2. Vasya changes nothing.
- Day 1. Month 2. The clock shows 3. Vasya manually increases the day number by 1. After that the clock shows 4. Vasya increases the day number by 1 manually. After that the clock shows 1.
- Day 2. Month 2. The clock shows 2. Vasya changes nothing.
解题说明:此题是判断如何调整钟表显示正确的日期,这里只要求显示每月中的日即可。在计算时,只需要统计钟表最大数与当前月份的日期数差值,累加就是手动调节的值。
#include <iostream>#include <cstdio>#include <cstdlib>#include <cmath>#include <cstring>#include <string>#include<set>#include <algorithm>using namespace std;int main(){int d,n,a,s=0,k;scanf("%d",&d);scanf("%d",&n);scanf("%d",&a);for(k=1;k<n;k++){s+=d-a;scanf("%d",&a);}printf("%d\n",s);return 0;}
- B. Vasya's Calendar
- B. Vasya and Wrestling
- B. Vasya and Wrestling
- Milliard Vasya's Function
- codeforces837E Vasya's Function
- CF837E-Vasya's Function
- B. Calendar
- B. Vasya and Public Transport
- B. Vasya and Public Transport
- URAL 1387 Vasya's Dad
- Milliard Vasya's Function(Ural_1353)
- Ural1353-Milliard Vasya's Function
- codeforces493 A. Vasya and Football B. Vasya and Wrestling C. Vasya and Basketball
- codeforces 355B Vasya and Public Transport
- CodeForces 493B Vasya and Wrestling 【模拟】
- Codeforces 493B Vasya and Wrestling(水)
- Timus 1353. Milliard Vasya's Function
- Ural 1353. Milliard Vasya's Function 暴搜
- <C++程序设计教程 钱能 著>例题 chapter1_9_2
- HDU/HDOJ2509 SG
- ADB server did't ACK
- 关于多线程学习总结(四) 锁
- 【C++】由指针常量和常量指针引发的问题
- B. Vasya's Calendar
- 网站漏洞处理(SQL注入、XSS脚本攻击、防外站提交)以及扩展思路
- poj2442-优先队列
- C++
- linux c 重命名文件和文件夹
- 中国剩余定理(互质与不互质模版)
- 矩阵连乘
- 2013718总结
- Android AP及BP