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\n",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]=‘\0‘;
        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]=‘\0‘;
            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\n",++cas,b);
    }
    return 0;
}
时间: 2024-08-27 23:39:09

HDU5938 Four Operations(思路水题)的相关文章

Codeforces-Translation(水题)

The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pronounced) reversely. For

(补题 水题 汇总)四川大学第二届SCUACM新生赛

B-丁姐姐喜欢LCS 原题链接 输入 abc bca wad ad as asd wa aw wa wwa 输出 bc ad as a 解题思路 暴力呀!暴力呀!暴力呀!!!(我真是白学了ORZ) 代码样例 #include <bits/stdc++.h> using namespace std; int main(){ string a,b; while(cin >> a >> b){ bool judge = false; int cnt=0; for(int i=

杭电(hdu)2053 Switch Game 水题

Switch Game Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 13113    Accepted Submission(s): 7970 Problem Description There are many lamps in a line. All of them are off at first. A series of o

codeforces 710A A. King Moves(水题)

题目链接: A. King Moves 题意: 给出king的位置,问有几个可移动的位置; 思路: 水题,没有思路; AC代码: #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <cmath> #include <bits/stdc++.h> #include <stack> #include &l

UVa 1586 Molar mass --- 水题

UVa 1586 题目大意:给出一种物质的分子式(不带括号),求分子量.本题中分子式只包含4种原子,分别为C.H.O.N, 原子量分别为12.01,1.008,16.00,14.01 解题思路:先实现一个从字符型的数到整型的数的转换函数,再将输入的串从头到尾扫描,遇到字母,则进一步扫描后面的数字的区间, 再调用函数进行转换,再乘以其的原子质量,最后累加到sum中即可. /* UVa 1586 Molar mass --- 水题 */ #include <cstdio> #include <

UVa 272 Tex Quotes --- 水题

题目大意:在TeX中,左引号是 ``,右引号是 ''.输入一篇包含双引号的文章,你的任务是把他转成TeX的格式 解题思路:水题,定义一个变量标记是左引号还是右引号即可 /* UVa 272 Tex Quotes --- 水题 */ #include <cstdio> #include <cstring> int main() { #ifdef _LOCAL freopen("D:\\input.txt", "r", stdin); #endi

hdu 4274 Spy&amp;#39;s Work(水题)

Spy's Work Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1266    Accepted Submission(s): 388 Problem Description I'm a manager of a large trading company, called ACM, and responsible for the

poj1061——扩展gcd水题

poj1061——扩展gcd水题 青蛙的约会 Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 94176   Accepted: 17413 Description 两只青蛙在网上相识了,它们聊得很开心,于是觉得很有必要见一面.它们很高兴地发现它们住在同一条纬度线上,于是它们约定各自朝西跳,直到碰面为止.可是它们出发之前忘记了一件很重要的事情,既没有问清楚对方的特征,也没有约定见面的具体位置.不过青蛙们都是很乐观的,它们觉

HDU 4006 The kth great number (基本算法-水题)

The kth great number Problem Description Xiao Ming and Xiao Bao are playing a simple Numbers game. In a round Xiao Ming can choose to write down a number, or ask Xiao Bao what the kth great number is. Because the number written by Xiao Ming is too mu