Codeforces Round #377 (Div. 2) C 模拟

本文解析了一道来自 CodeForces 的算法题,题目要求根据主人公在疗养院就餐次数的记录,计算其至少错过多少次就餐机会。通过分析不同就餐时间段之间的数量差异,并利用 C++ 实现了计算逻辑。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

题目传送门:http://codeforces.com/problemset/problem/732/C


题意:vasiliy去疗养院度假,他可能在早饭前,午饭前,晚饭前到,可能在早饭前,午饭前,晚饭前走。他有一张卡片上面记录了他在疗养院吃早饭,午饭,晚饭的次数,问他最少少吃了多少此饭


思路:由于他来跟离开的时间不确定,所以这三餐的数量可以不相等,但人依赖两个间的数量相差不会超过1,然后就能算了


代码如下:

#include <iostream>
#include <algorithm>
#include <cstring>
#include <stdio.h>
#include <string>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <bitset>
#include <cstdlib>

using namespace std;
#define   lson          l,m,rt<<1
#define   rson          m+1,r,rt<<1|1
#define   ll            long long
#define   ull           unsigned long long
#define   mem(n,v)      memset(n,v,sizeof(n))
#define   MAX           100005
#define   MAXN          10005
#define   PI            3.1415926
#define   E             2.718281828459
#define   opnin         freopen("text.in.txt","r",stdin)
#define   opnout        freopen("text.out.txt","w",stdout)
#define   clsin         fclose(stdin)
#define   clsout        fclose(stdout)
#define   haha1         cout << "haha1"<< endl
#define   haha2         cout << "haha2"<< endl
#define   haha3         cout << "haha3"<< endl

const int    INF    =   0x3f3f3f3f;
const ll     INFF   =   0x3f3f3f3f3f3f3f3f;
const double pi     =   3.141592653589793;
const double inf    =   1e18;
const double eps    =   1e-8;
const ll     mod    =   1e18;
const ull    mx     =   133333331;
/**************************************************************************/
int main()
{
    ll a[3];
    cin >> a[0] >> a[1] >> a[2];
    sort(a,a+3);
    ll sum = 0;
    if(a[2] > a[1] + 1) sum += a[2] - 1 - a[1];
    if(a[2] > a[0] + 1) sum += a[2] - 1 - a[0];
    cout  << sum << endl;


    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值