Coins

Coins
Input file: standard input
Output file: standard output
Time limit: 1 second
Memory limit: 1024 megabytes
In ICPCCamp, people usually use coins of value 1; 2; 3.
Bobo was very poor, he had only a1; a2; a3 coins of value 1; 2; 3, respectively. He bought an item of an
unknown value without making change.
The unknown item was of positive integral value. Find out the number of possible values of it.
Input
3 integers a1; a2; a3 (0  a1; a2; a3  109).
Output
An integer denotes the number of possible values of the unknown item.
Examples
standard input standard output
1 0 1 3
0 0 0 0
Note
In the first sample, Bobo can only buy a item with value 1; 3 or 4 without making change.

分析:需要很强的手推(yy)的技巧,否则就GG了。。。

代码:

 

#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 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, rt<<1
#define Rson mid+1, R, rt<<1|1
const int maxn=2e5+10;
using namespace std;
ll gcd(ll p,ll q){return q==0?p:gcd(q,p%q);}
ll qpow(ll p,ll q){ll f=1;while(q){if(q&1)f=f*p;p=p*p;q>>=1;}return f;}
int n,m,k,t;
inline ll read()
{
    ll x=0;int f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
int a,b,c;
ll ans;
int main()
{
    int i,j;
    scanf("%d%d%d",&a,&b,&c);
    if(a&&b&&c)
    {
        printf("%lld\n",(ll)a+2*b+3*c);
    }
    else if(a&&b)
    {
        ans+=(ll)2*b+a;
        printf("%lld\n",ans);
    }
    else if(b&&c)
    {
        if(b==1)printf("%lld\n",(ll)2*c+1);
        else printf("%lld\n",(ll)2*b+3*c-2);
    }
    else if(a&&c)
    {
        if(a==1)printf("%lld\n",(ll)c*2+1);
        else printf("%lld\n",(ll)3*c+a);
    }
    else printf("%lld\n",(ll)a+b+c);
    //system("Pause");
    return 0;
}

 

posted @ 2016-10-02 14:01  mxzf0213  阅读(361)  评论(0编辑  收藏  举报