zoukankan      html  css  js  c++  java
  • 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
    ",(ll)a+2*b+3*c);
        }
        else if(a&&b)
        {
            ans+=(ll)2*b+a;
            printf("%lld
    ",ans);
        }
        else if(b&&c)
        {
            if(b==1)printf("%lld
    ",(ll)2*c+1);
            else printf("%lld
    ",(ll)2*b+3*c-2);
        }
        else if(a&&c)
        {
            if(a==1)printf("%lld
    ",(ll)c*2+1);
            else printf("%lld
    ",(ll)3*c+a);
        }
        else printf("%lld
    ",(ll)a+b+c);
        //system("Pause");
        return 0;
    }
  • 相关阅读:
    一本通1268 完全背包问题
    一本通1267 01背包
    合并石子1,2
    求最长不下降子序列++
    数字金字塔升级版
    一本通1354 括弧匹配检验
    一本通1353表达式括号匹配
    一本通1357车厢调度
    Centos查看端口占用情况和开启端口命令
    centos后台运行python程序
  • 原文地址:https://www.cnblogs.com/dyzll/p/5927458.html
Copyright © 2011-2022 走看看