zoukankan      html  css  js  c++  java
  • 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
    1T105
    5length of string20
     
    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
     
    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
    ",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;
    }
  • 相关阅读:
    ftp如果有文件夹直接建文件,没有创建文件夹
    jfinal相关
    jfinal多数据源
    创建maven项目多模块项目
    多线程分批处理list内的值
    内部类_常见的用途
    获取aplicationContext对象,从而获取任何注入的对象
    jquery表单验证
    monkeyrunner录制回放
    android稳定性测试
  • 原文地址:https://www.cnblogs.com/wuwangchuxin0924/p/6011471.html
Copyright © 2011-2022 走看看