2016年中国大学生程序设计竞赛(杭州)1006 Four Operations

Four Operations

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 38    Accepted Submission(s): 18

Problem Description

Little Ruins is a studious boy, recently he learned the four operations!

Now he want to use four operations to generate a number, he takes a string which only contains digits ‘1‘ - ‘9‘, and split it into 5

intervals and add the four operations ‘+‘, ‘-‘, ‘*‘ and ‘/‘ in order, then calculate the result(/ used as integer division).

Now please help him to get the largest result.

Input

First line contains an integer T

, which indicates the number of test cases.

Every test contains one line with a string only contains digits ‘1‘-‘9‘.

Limits
1≤T≤105

5≤length of string≤20

Output

For every test case, you should output ‘Case #x: y‘, where x indicates the case number and counts from 1 and y is the result.

Sample Input

1
12345

Sample Output

Case #1: 1

Source

2016年中国大学生程序设计竞赛(杭州)

Recommend

liuyiding

/*
枚举减号,刚开始天真的以为,除数最多是两位......卡死。
*/
#include<bits/stdc++.h>
#define ll long long
#define INF 0x3fffffffffffffff
#define N 22
using namespace std;

string op;

ll right(string s)
{
    ll e=0;
    int n=s.size();
    for(int i=2;i<n;i++)
        e=e*10+s[i]-‘0‘;
    //cout<<c<<" "<<d<<" "<<e<<endl;
    ll ans=(s[0]-‘0‘)*(s[1]-‘0‘)/e;
    return ans;
}

ll left(string s)//减号左边的部分
{
    ll cur1=0,cur2=0;
    int n=s.size();
    for(int i=1;i<n;i++)
        cur1=cur1*10+(s[i]-‘0‘);
    cur1+=s[0]-‘0‘;
    for(int i=0;i<n-1;i++)
        cur2=cur2*10+(s[i]-‘0‘);
    cur2+=s[n-1]-‘0‘;
    //cout<<"max(cur1,cur2)="<<max(cur1,cur2)<<" ";
    return max(cur1,cur2);
}
ll solve(string s)
{
    ///枚举减号
    ll cur=-INF,s1,s2;
    int n=s.size();
    for(int i=2;i<=n-3;i++)
    {
        s1=left(s.substr(0,i));
        s2=right(s.substr(i,n-i));
        //cout<<s1<<" "<<s2<<endl;
        cur=max(cur,s1-s2);
    }
    printf("%lld\n",cur);
}
int t;
int main()
{
    //freopen("C:\\Users\\acer\\Desktop\\in.txt","r",stdin);
    scanf("%d",&t);
    for(int Case=1;Case<=t;Case++)
    {
        printf("Case #%d: ",Case);
        cin>>op;
        solve(op);
    }
    return 0;
}
时间: 2024-10-09 12:01:21

2016年中国大学生程序设计竞赛(杭州)1006 Four Operations的相关文章

HDU 5943 Kingdom of Obsession 【二分图匹配 匈牙利算法】 (2016年中国大学生程序设计竞赛(杭州))

Kingdom of Obsession Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 49    Accepted Submission(s): 14 Problem Description There is a kindom of obsession, so people in this kingdom do things very

HDU 5934 Bomb 【图论缩点】(2016年中国大学生程序设计竞赛(杭州))

Bomb Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 10    Accepted Submission(s): 3 Problem Description There are N bombs needing exploding. Each bomb has three attributes: exploding radius ri,

HDU 5938 Four Operations 【贪心】(2016年中国大学生程序设计竞赛(杭州))

Four Operations Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 22    Accepted Submission(s): 12 Problem Description Little Ruins is a studious boy, recently he learned the four operations! Now

HDU 5933 ArcSoft&#39;s Office Rearrangement 【模拟】(2016年中国大学生程序设计竞赛(杭州))

ArcSoft's Office Rearrangement Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 3    Accepted Submission(s): 2 Problem Description ArcSoft, Inc. is a leading global professional computer photogra

HDU 5936 Difference 【中途相遇法】(2016年中国大学生程序设计竞赛(杭州))

Difference Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 62    Accepted Submission(s): 19 Problem Description Little Ruins is playing a number game, first he chooses two positive integers y an

HDU 5935 Car 【模拟】 (2016年中国大学生程序设计竞赛(杭州))

Car Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 25    Accepted Submission(s): 12 Problem Description Ruins is driving a car to participating in a programming contest. As on a very tight sche

HDU 5961 传递 【图论+拓扑】 (2016年中国大学生程序设计竞赛(合肥))

传递 Time Limit: 12000/6000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)   Problem Description 我们称一个有向图G是传递的,当且仅当对任意三个不同的顶点a,,若G中有 一条边从a到b且有一条边从b到c ,则G中同样有一条边从a到c.我们称图G是一个竞赛图,当且仅当它是一个有向图且它的基图是完全图.换句 话说,将完全图每条边定向将得到一个竞赛图.下图展示的是一个有4个顶点的竞

HDU 5969 最大的位或 【贪心】 (2016年中国大学生程序设计竞赛(合肥))

最大的位或 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Problem Description B君和G君聊天的时候想到了如下的问题.给定自然数l和r ,选取2个整数x,y满足l <= x <= y <= r ,使得x|y最大.其中|表示按位或,即C. C++. Java中的|运算. Input 包含至多10001组测试数据.第一行有一个正整数,表示数据的组数.接下

HDU 5965 扫雷 【模拟】 (2016年中国大学生程序设计竞赛(合肥))

扫雷 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 998    Accepted Submission(s): 289 Problem Description 扫雷游戏是晨晨和小璐特别喜欢的智力游戏,她俩最近沉迷其中无法自拔.该游戏的界面是一个矩阵,矩阵中有些格子中有一个地雷,其余格子中没有地雷. 游戏中,格子可能处于己知和未知的状态