Sanatorium
1 second
256 megabytes
standard input
standard output
Vasiliy spent his vacation in a sanatorium, came back and found that he completely forgot details of his vacation!
Every day there was a breakfast, a dinner and a supper in a dining room of the sanatorium (of course, in this order). The only thing that Vasiliy has now is a card from the dining room contaning notes how many times he had a breakfast, a dinner and a supper (thus, the card contains three integers). Vasiliy could sometimes have missed some meal, for example, he could have had a breakfast and a supper, but a dinner, or, probably, at some days he haven't been at the dining room at all.
Vasiliy doesn't remember what was the time of the day when he arrived to sanatorium (before breakfast, before dinner, before supper or after supper), and the time when he left it (before breakfast, before dinner, before supper or after supper). So he considers any of these options. After Vasiliy arrived to the sanatorium, he was there all the time until he left. Please note, that it's possible that Vasiliy left the sanatorium on the same day he arrived.
According to the notes in the card, help Vasiliy determine the minimum number of meals in the dining room that he could have missed. We shouldn't count as missed meals on the arrival day before Vasiliy's arrival and meals on the departure day after he left.
The only line contains three integers b, d and s (0 ≤ b, d, s ≤ 1018, b + d + s ≥ 1) — the number of breakfasts, dinners and suppers which Vasiliy had during his vacation in the sanatorium.
Print single integer — the minimum possible number of meals which Vasiliy could have missed during his vacation.
- 3 2 1
- 1
- 1 0 0
- 0
- 1 1 1
- 0
- 1000000000000000000 0 1000000000000000000
- 999999999999999999
In the first sample, Vasiliy could have missed one supper, for example, in case he have arrived before breakfast, have been in the sanatorium for two days (including the day of arrival) and then have left after breakfast on the third day.
In the second sample, Vasiliy could have arrived before breakfast, have had it, and immediately have left the sanatorium, not missing any meal.
In the third sample, Vasiliy could have been in the sanatorium for one day, not missing any meal.
分析:贪心,哪个最大,就以哪个开始到,然后模拟;
代码:
- #include <iostream>
- #include <cstdio>
- #include <cstdlib>
- #include <cmath>
- #include <algorithm>
- #include <climits>
- #include <cstring>
- #include <string>
- #include <set>
- #include <map>
- #include <queue>
- #include <stack>
- #include <vector>
- #include <list>
- #define rep(i,m,n) for(i=m;i<=n;i++)
- #define rsp(it,s) for(set<int>::iterator it=s.begin();it!=s.end();it++)
- #define mod 1000000007
- #define inf 0x3f3f3f3f
- #define llinf 0x3f3f3f3f3f3f3f3fLL
- #define vi vector<int>
- #define pb push_back
- #define mp make_pair
- #define fi first
- #define se second
- #define ll long long
- #define pi acos(-1.0)
- #define pii pair<int,int>
- #define Lson L, mid, ls[rt]
- #define Rson mid+1, R, rs[rt]
- #define sys system("pause")
- const int maxn=2e5+;
- using namespace std;
- ll gcd(ll p,ll q){return q==?p:gcd(q,p%q);}
- ll qpow(ll p,ll q){ll f=;while(q){if(q&)f=f*p;p=p*p;q>>=;}return f;}
- inline ll read()
- {
- ll x=;int f=;char ch=getchar();
- while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
- while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
- return x*f;
- }
- int n,m,k,t;
- ll a[],ans,ma;
- int main()
- {
- int i,j;
- rep(i,,)scanf("%lld",&a[i]),ma=max(ma,a[i]);
- rep(i,,)if(a[i]<ma)ans+=ma--a[i];
- printf("%lld\n",ans);
- //system("Pause");
- return ;
- }
Sanatorium的更多相关文章
- Codeforces Round #377 (Div. 2) C. Sanatorium 水题
C. Sanatorium time limit per test 1 second memory limit per test 256 megabytes input standard input ...
- CodeForces 732C Sanatorium
C. Sanatorium time limit per test 1 second memory limit per test 256 megabytes input standard input ...
- 【43.26%】【codeforces 732C】Sanatorium
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- CodeForces 732C Sanatorium (if-else)
题意:某人去旅游,记录了一共吃了多少顿饭,早中晚,但是有可能缺少,问你最少缺少了多少顿. 析:每把三个数排序,然后再一一对比,肯定是以最大数为主,其他两个肯定是缺少了. 代码如下: #pragma c ...
- codeforces 732
A. Buy a Shovel time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...
- Codeforces Round #377 (Div. 2) A B C D 水/贪心/贪心/二分
A. Buy a Shovel time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...
- codeforces732C
Sanatorium CodeForces - 732C Vasiliy spent his vacation in a sanatorium, came back and found that he ...
- Codeforces Round #377 (Div. 2)A,B,C,D【二分】
PS:这一场真的是上分场,只要手速快就行.然而在自己做的时候不用翻译软件,看题非常吃力非常慢,还有给队友讲D题如何判断的时候又犯了一个毛病,一定要心平气和,比赛也要保证,不要用翻译软件做题: Code ...
- Codeforces Round #377 (Div. 2)部分题解A+B+C!
A. Buy a Shovel 题意是很好懂的,一件商品单价为k,但他身上只有10块的若干和一张r块的:求最少买几件使得不需要找零.只需枚举数量判断总价最后一位是否为0或r即可. #include&l ...
随机推荐
- Sass入门:第四章
1.加法 加法运算是Sass中运算的一种,在变量或属性中都可以做加法运算.如: .box { width: 20px + 8in; } 编译出来的CSS: .box { width: 788px; } ...
- Linux入门(二)Linux基本命令及基本操作
1 常用Linux命令 图形界面进入到字符界面: ctrl+alt+F2~F6 字符界面进入到图形界面:ctrl +alt+F7 查看本机ip: ifconfig (windows是:ipconf ...
- xlrd doc
The xlrd Module A Python module for extracting data from MS Excel ™ spreadsheet files. Version 0.7.3 ...
- CF 604B More Cowbell#贪心
(- ̄▽ ̄)-* //把最大单独放,然后第二大的和最小的放一起,第三大的和第二小的放一起 //由此类推,求最大值,即为盒的最小值 #include<iostream> #include&l ...
- jbpm4.3表结构和表字段说明
整体说明: JBPM4_DEPLOYMENT 流程定义表JBPM4_DEPLOYPROP 流程定义属性表 JBPM4_EXECUTION 流程实例表JBPM4_HIST_ACTINST 流程活动 ...
- Android应用测试性能的工具Emmagee,导出文件格式问题分析
原文引用自:http://www.open-open.com/lib/view/open1367026451078.html Emmagee是监控指定被测应用在使用过程中占用机器的CPU.内存.流量资 ...
- Urbanization
Urbanization time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...
- iOS UIScrollview代理方法
方法&&属性: // 监控目前滚动的位置(默认CGPointZero) CGPoint contentOffset; - (void)setContentOffset:(CGPoint ...
- java 文件的基本操作
1 /** * java 文件操作 * 2016/5/10 **/ package cn.Java_7; import java.io.*; import java.util.Scanner; imp ...
- 河南多校联合训练 南阳理工 1261 音痴又音痴的LT
描述 LT最近一直在无限循环薛之谦的歌,简直都中毒了!可是呢…他的歌LT还是不会唱(其实不止他的歌LT不会唱,所有人的歌LT都不会唱…因为LT是标准的音痴)可是LT又很喜欢唱歌(所以LT不仅是音痴还是 ...