首页 > 代码库 > CodeForces 732C Sanatorium

CodeForces 732C Sanatorium

分类讨论。

分几种情况讨论一下即可。

#pragma comment(linker, "/STACK:1024000000,1024000000")#include<cstdio>#include<cstring>#include<cmath>#include<algorithm>#include<vector>#include<map>#include<set>#include<queue>#include<stack>#include<ctime>#include<iostream>using namespace std;typedef long long LL;const double pi=acos(-1.0),eps=1e-10;void File(){    freopen("D:\\in.txt","r",stdin);    freopen("D:\\out.txt","w",stdout);}template <class T>inline void read(T &x){    char c = getchar();    x = 0;    while(!isdigit(c)) c = getchar();    while(isdigit(c))    {        x = x * 10 + c - 0;        c = getchar();    }}long long A,B,C;long long get(long long a,long long b,long long c){    long long x=min(a,min(b,c));    a=a-x;    b=b-x;    c=c-x;    if(a==0&&b==0&&c==0) return 0;    if(a!=0&&b==0&&c==0) return (a-1)*2;    if(a==0&&b!=0&&c==0) return (b-1)*2;    if(a==0&&b==0&&c!=0) return (c-1)*2;    if(a==0&&b!=0&&c!=0)    {        b=b-1; c=c-1;        if(b>c) return b+b-c;        if(b==c) return b;        return c+c-b;    }    if(a!=0&&b==0&&c!=0)    {        if(a>c) return a-1+a-1-c;        if(a==c) return a;        return c+c-a;    }    if(a!=0&&b!=0&&c==0)    {        if(a>b) return a-1-b+a-1;        if(a==b) return a-1;        return b-1+b-a;    }}int main(){    cin>>A>>B>>C;    printf("%lld\n",min(get(A,B,C),min(get(B,C,A),get(C,A,B))));    return 0;}

 

CodeForces 732C Sanatorium