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 ...
随机推荐
- win2008阿里一键环境包mysql老是1067报错
目前查看并不是染毒导致mysql无法启动,而是在mysql的配置文件中配置了log这个参数,这个参数语义不明确,请您将“--log”更改为general_log_file并添加一行“general_l ...
- Intellij Idea web项目的部署配置[转]
原文地址:http://blog.csdn.net/z69183787/article/details/41416189 1.前言 2.项目配置(Project Structure) 2.1 Proj ...
- el表达式跟ognl表达式的区别
: EL表达式 单纯在jsp页面中出现,是在四个作用域中取值,page,request,session,application. 如果在struts环境中,它除了有在上面的四个作用域的取值功能外,还 ...
- 转 delphi SelText,GetText,SetText用法
转自:http://blog.163.com/wll_009/blog/static/1173731172009102452632968/ 这几个都跟选区有关的,就是选中一串字符串,选中的会变蓝色Se ...
- c++的复制构造函数
在C++中,下面三种对象需要调用拷贝构造函数(有时也称“复制构造函数”): 1) 一个对象作为函数参数,以值传递的方式传入函数体: 2) 一个对象作为函数返回值,以值传递的方式从函数返回: 3) 一个 ...
- LeetCode OJ 41. First Missing Positive
Given an unsorted integer array, find the first missing positive integer. For example,Given [1,2,0] ...
- BASE1(matlab)
version memory clc clear tab键 F5键 运行m文件 F9键 只运行选中的 Ctrl+R 注释 Ctrl+T 反注释 Ctrl+I 格式化代码 edit xxx. ...
- ubuntu切换到超级管理员权限
默认情况下是无法切换的,需要给root用户设置上密码 mars@mars-LIFEBOOK-LH531:~$ sudo passwd root[sudo] password for mars: 输入新 ...
- iOS 打电话、发短信、发邮件功能
打电话 方法1 最简单最直接的方式:直接跳到拨号界面 NSURL *url = [NSURL URLWithString:@"tel://10010"]; [[UIApplicat ...
- Microsoft SqlSever 数据库--软谋1
百度百科--Microsoft SqlSever SQL是英文Structured Query Language的缩写,意思为结构化查询语言.SQL语言的主要功能就是同各种数据库建立联系,进行沟通.按 ...