HDU 2277 Change the ball

脑洞题。

如果存在两个数字是一样的,那么有解,费用为那两个相同的数字的个数。

也可能是如果存在两个球个数差为3 6 9 12 .. 3的倍数 也可以转,并且是转换成第三种颜色,并且转换次数是较多的那个球的个数。 
#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<iostream>
using namespace std;
typedef long long LL;
const double pi=acos(-1.0),eps=1e-6;
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(); }
}

int Y,B,R;
int ans[100];

int main()
{
    while(~scanf("%d%d%d",&Y,&B,&R))
    {
         for(int i=1;i<=20;i++) ans[i]=9999999;

         if(Y==B) ans[1]=Y;
         if(Y==R) ans[2]=R;
         if(B==R) ans[3]=B;

         if(Y>B&&(Y-B)%3==0) ans[4]=Y;
         if(Y>R&&(Y-R)%3==0) ans[5]=Y;

         if(B>Y&&(B-Y)%3==0) ans[6]=B;
         if(B>R&&(B-R)%3==0) ans[7]=B;

         if(R>Y&&(R-Y)%3==0) ans[8]=R;
         if(R>B&&(R-B)%3==0) ans[9]=R;


         int Ans=9999999;
         for(int i=1;i<=9;i++) Ans=min(Ans,ans[i]);

         if(Ans==9999999) printf("):\n");
         else printf("%d\n",Ans);

    }
    return 0;
}

 

posted @ 2017-01-17 18:45  Fighting_Heart  阅读(142)  评论(0编辑  收藏  举报