zoukankan      html  css  js  c++  java
  • HDU5938 Four Operations(思路水题)

    题意:

    给你一个长度为5-20的数字串(1-9),让你在其中顺序添加+-*/使得运算结果最大

    思路:

    假设是a+b-c*d/e的形式,可以发现,c*d越小越好,所以c d各占1位

    然后e的话只可能是1位或者两位(长度为6,7的时候可能会有,如111991)

    然后a和b就有两种情况,一个占1位,剩下的占据所有其他的位置,比较一下哪个大就可以了

    总共就4种情况

    /* ***********************************************
    Author        :devil
    ************************************************ */
    #include <cstdio>
    #include <cstring>
    #include <iostream>
    #include <algorithm>
    #include <vector>
    #include <queue>
    #include <set>
    #include <stack>
    #include <map>
    #include <string>
    #include <time.h>
    #include <cmath>
    #include <stdlib.h>
    #define LL long long
    #define rep(i,a,b) for(int i=a;i<=b;i++)
    #define dep(i,a,b) for(int i=a;i>=b;i--)
    #define ou(a) printf("%d
    ",a)
    #define pb push_back
    #define mkp make_pair
    template<class T>inline void rd(T &x)
    {
        char c=getchar();
        x=0;
        while(!isdigit(c))c=getchar();
        while(isdigit(c))
        {
            x=x*10+c-'0';
            c=getchar();
        }
    }
    #define IN freopen("in.txt","r",stdin);
    #define OUT freopen("out.txt","w",stdout);
    using namespace std;
    const int inf=0x3f3f3f3f;
    const int mod=1e9+7;
    const int N=1e5+10;
    char s[30],s2[30];
    int main()
    {
    #ifndef ONLINE_JUDGE
    //IN
    #endif
        int t,cas=0;
        scanf("%d",&t);
        while(t--)
        {
            scanf("%s",s+1);
            LL ans=0,a,b;
            int l=strlen(s+1);
            for(int i=1;i<=l;i++) s2[i]=s[i];
            LL c=s[l-2]-'0';
            LL d=s[l-1]-'0';
            LL e=s[l]-'0';
            s[l-2]='';
            c=c*d/e;
            if(strncmp(s+1,s+2,l-4)>0)
            {
                a=atoll(s+1);
                b=a%10+a/10-c;
            }
            else
            {
                a=atoll(s+2);
                b=a+s[1]-'0'-c;
            }
            if(l>5)
            {
                c=s2[l-3]-'0';
                d=s2[l-2]-'0';
                e=(s2[l-1]-'0')*10+s2[l]-'0';
                s2[l-3]='';
                c=c*d/e;
                if(strncmp(s2+1,s2+2,l-5)>0)
                {
                    a=atoll(s2+1);
                    b=max(b,a%10+a/10-c);
                }
                else
                {
                    a=atoll(s2+2);
                    b=max(b,a+s2[1]-'0'-c);
                }
            }
            printf("Case #%d: %lld
    ",++cas,b);
        }
        return 0;
    }
  • 相关阅读:
    java String format格式字符串语法
    spring 小示例 yongqi
    mysql GROUP_CONCAT()函数最大长度之坑 yongqi
    连接数据库超时设置autoReconnect=true mysql经典的8小时问题 yongqi
    Kafka 可视化工具(Kafka Tool) yongqi
    kettle 优化 yongqi
    mysql 修改字段名 yongqi
    SQL: Cannot drop database XXX because it is currently in use解决方法 yongqi
    .Net Core 控制台应用程序 依赖注入
    记一次部署Skywalking(基于Elasticsearch),并使用 .NET6接入Skywalking
  • 原文地址:https://www.cnblogs.com/d-e-v-i-l/p/6012845.html
Copyright © 2011-2022 走看看