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 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
 
Recommend
liuyiding   |   We have carefully selected several similar problems for you:  5943 5942 5941 5940 5939 
 

Statistic | Submit | Discuss | Note

题目链接:

  http://acm.hdu.edu.cn/showproblem.php?pid=5938

题目大意:

  给一串长度为5~20的数字串(只含1~9),要求按顺序将 + - * / 各1个分别插入数字之间,使得最终运算结果最大。

题目思路:

  【贪心】

  分析*,因为前面是-号所以希望乘的数小,所以乘和- /之间只隔1位。

  分析/,除只可能除1位数或2位数(因为乘只乘1位,3位不优,2位可能是111991,原先我以为只要/一位)。

  分析+,可以知道位数越大加的结果越大,所以+只能是1位数与多位数相加。

  所以综上可以分类讨论,/1位或2位,乘紧挨/前,-紧挨*,之前的数字要么在第一个断开,要么最后一个。

  答案取最大即可。

 //
//by coolxxx
//#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<iomanip>
#include<map>
#include<stack>
#include<queue>
#include<set>
#include<bitset>
#include<memory.h>
#include<time.h>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
//#include<stdbool.h>
#include<math.h>
#pragma comment(linker,"/STACK:1024000000,1024000000")
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define abs(a) ((a)>0?(a):(-(a)))
#define lowbit(a) (a&(-a))
#define sqr(a) ((a)*(a))
#define swap(a,b) ((a)^=(b),(b)^=(a),(a)^=(b))
#define mem(a,b) memset(a,b,sizeof(a))
#define eps (1e-8)
#define J 10000
#define mod 1000000007
#define MAX 0x7f7f7f7f
#define PI 3.14159265358979323
#define N 24
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
double anss;
LL aans;
int cas,cass;
int n,m,lll,ans;
LL sum,tot,s1,s2;
char s[N];
int main()
{
#ifndef ONLINE_JUDGEW
// freopen("1.txt","r",stdin);
// freopen("2.txt","w",stdout);
#endif
int i,j,k;
int x,y,z;
// init();
// for(scanf("%d",&cass);cass;cass--)
for(scanf("%d",&cas),cass=;cass<=cas;cass++)
// while(~scanf("%s",s))
// while(~scanf("%d%d",&n,&m))
{
tot=;sum=;s1=;s2=;
printf("Case #%d: ",cass);
scanf("%s",s);
n=strlen(s);
tot=-(s[n-]-'')*(s[n-]-'')/(s[n-]-'');
s1=s[]-'';s2=;
for(i=;i<n-;i++)
s2=s2*+s[i]-'';
sum=tot+s1+s2;
s1=s[n-]-'';s2=;
for(i=;i<n-;i++)
s2=s2*+s[i]-'';
tot+=s1+s2;
sum=max(sum,tot);
if(n>)
{
tot=-(s[n-]-'')*(s[n-]-'')/((s[n-]-'')*+s[n-]-'');
s1=s[]-'';s2=;
for(i=;i<n-;i++)
s2=s2*+s[i]-'';
tot+=s1+s2;
sum=max(sum,tot);
tot=-(s[n-]-'')*(s[n-]-'')/((s[n-]-'')*+s[n-]-'');
s1=s[n-]-'';s2=;
for(i=;i<n-;i++)
s2=s2*+s[i]-'';
tot+=s1+s2;
sum=max(sum,tot);
}
printf("%lld\n",sum);
}
return ;
}
/*
// //
*/

HDU 5938 Four Operations 【贪心】(2016年中国大学生程序设计竞赛(杭州))的更多相关文章

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

    最大的位或 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Problem De ...

  2. HDU 5933 ArcSoft's Office Rearrangement 【模拟】(2016年中国大学生程序设计竞赛(杭州))

    ArcSoft's Office Rearrangement Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K ...

  3. HDU 5963 朋友 【博弈论】 (2016年中国大学生程序设计竞赛(合肥))

    朋友 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Problem Descr ...

  4. HDU 5968 异或密码 【模拟】 2016年中国大学生程序设计竞赛(合肥)

    异或密码 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Problem Des ...

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

    传递 Time Limit: 12000/6000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)     Problem ...

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

    扫雷 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submissi ...

  7. HDU 5937 Equation 【DFS+剪枝】 (2016年中国大学生程序设计竞赛(杭州))

    Equation Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total S ...

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

    Difference Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total ...

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

    Kingdom of Obsession Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Oth ...

随机推荐

  1. iOS-开发记录-UIView属性

    UIView属性 1.alpha 设置视图的透明度.默认为1. // 完全透明 view.alpha = ; // 不透明 view.alpha = ; 2.clipsToBounds // 默认是N ...

  2. javascript 基础3第13节

    <html> <head> <title>javascript基础</title> </head> <body> 1.流程控制 ...

  3. 04_过滤器Filter_02_Filter解决中文乱码问题

    [过滤器解决中文乱码问题实例] [工程截图] [web.xml] <?xml version="1.0" encoding="UTF-8"?> &l ...

  4. URL重写 UrlRewrite

    为什么要URL重写? 1.有利于SEO,带参数的URL权重较低: 2.地址看起来更正规,推广uid 伪静态:看起来像普通页面,而非动态生成的页面. 原理:在Global.asax的Applicatio ...

  5. siege 压力测试

    Ben: $ siege -u shemp.whoohoo.com/Admin.jsp -d1 -r10 -c25 ..Siege 2.65 2006/05/11 23:42:16 ..Prepari ...

  6. javascript下动态this与动态绑定实例代码

    this 的值取决于 function 被调用的方式,一共有四种, 如果一个 function 是一个对象的属性,该 funtion 被调用的时候,this 的值是这个对象. 如果 function ...

  7. Log4j 密码屏蔽

    Log4j filter to mask Payment Card numbers (PCI DSS) According to PCI DSS (Payment Card Industry Data ...

  8. obj-c 坑

    BOOL,使用8位存储空间,具有YES和NO值,如果赋值微长于8位的变量,那么只有低位字节会用作BOOL值,例如8960=0x2300,低8位为0,BOOL为NO.

  9. 列表页url参数格式分析【求指教】

    运营对列表页url制定静态化模式,与区区观点相悖.遂请大家指教点解. 动态参数包含6个,分别是: 1认证(有机),2品类(水果),3地区(丰台),4状态(众筹中),5排序(评分),6分页 使用状态非常 ...

  10. CentOS下Redis 2.2.14安装配置详解(转载)

    一. 下载redis最新版本2.2.14 cd /usr/local/src wget –c http://redis.googlecode.com/files/redis-2.2.14.tar.gz ...