A very hard Aoshu proble

Problem Description
Aoshu is very popular among primary school students. It is mathematics, but much harder than ordinary mathematics for primary school students. Teacher Liu is an Aoshu teacher. He just comes out with a problem to test his students:
Given a serial of digits, you must put a '=' and none or some '+' between these digits and make an equation. Please find out how many equations you can get. For example, if the digits serial is "1212", you can get 2 equations, they are "12=12" and "1+2=1+2". Please note that the digits only include 1 to 9, and every '+' must have a digit on its left side and right side. For example, "+12=12", and "1++1=2" are illegal. Please note that "1+11=12" and "11+1=12" are different equations.
 
Input
There are several test cases. Each test case is a digit serial in a line. The length of a serial is at least 2 and no more than 15. The input ends with a line of "END".
 
Output
For each test case , output a integer in a line, indicating the number of equations you can get.
 
Sample Input
1212
12345666
1235
END
 
Sample Output
2
2
0
                                                                          
 
由于n小于=15,故暴力枚举即可。又由于只有数字1~9组成,无需考虑几个相邻的0的情况。很简单的一道水题,我们用二进制来枚举。水过。
 
 
 
 
 #include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<algorithm>
using namespace std;
char str[];
int get(int i,int j,int x,int cnt)
{
int ret,a,b,c;
int s=i;
ret=a=;
for(a=;a<cnt;a++)
{
if((<<a)&x)
{
c=;
for(b=s;b<=i+a;b++)
{
c=c*+str[b]-'';
}
s=i+a+;
ret+=c; }
}
c=;
for(b=s;b<=j;b++)
c=c*+str[b]-'';
ret+=c;
return ret;
}
int main()
{
int i,j,k,ans,a,b,c,len;
while(scanf("%s",str)&&str[]!='E')
{
len=strlen(str);
ans=;
for(i=;i<len;i++)
{
for(j=;j<(<<(i-));j++)
{ for(k=;k<(<<(len-i-));k++)
{
a=get(,i-,j,i-);
b=get(i,len-,k,len-i-);
if(a==b)
{
++ans;
}
} }
}
cout<<ans<<endl;
}
return ;
}
 
 
 
 
 
 
 
 
 
 
 

A very hard Aoshu problem的更多相关文章

  1. HDU 4403 A very hard Aoshu problem(DFS)

    A very hard Aoshu problem Problem Description Aoshu is very popular among primary school students. I ...

  2. A very hard Aoshu problem(dfs或者数位)

    题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=4403 A very hard Aoshu problem Time Limit: 2000/1000 ...

  3. hdu 3699 10 福州 现场 J - A hard Aoshu Problem 暴力 难度:0

    Description Math Olympiad is called “Aoshu” in China. Aoshu is very popular in elementary schools. N ...

  4. HDU 3699 A hard Aoshu Problem(暴力枚举)(2010 Asia Fuzhou Regional Contest)

    Description Math Olympiad is called “Aoshu” in China. Aoshu is very popular in elementary schools. N ...

  5. HDU4403 A very hard Aoshu problem DFS

    A very hard Aoshu problem                           Time Limit: 2000/1000 MS (Java/Others)    Memory ...

  6. UVALive - 5107 - A hard Aoshu Problem

    题目链接:https://vjudge.net/problem/UVALive-5107 题目大意:用ABCDE代表不同的数字,给出形如ABBDE___ABCCC = BDBDE的东西: 空格里面可以 ...

  7. 【HDOJ】4403 A very hard Aoshu problem

    HASH+暴力. /* 4403 */ #include <iostream> #include <cstdio> #include <cstring> #incl ...

  8. HDU 3699 A hard Aoshu Problem (暴力搜索)

    题意:题意:给你3个字符串s1,s2,s3;要求对三个字符串中的字符赋值(同样的字符串进行同样的数字替换), 替换后的三个数进行四则运算要满足左边等于右边.求有几种解法. Sample Input 2 ...

  9. HDU 4403 A very hard Aoshu problem

    暴力$dfs$. 先看数据范围,字符串最长只有$15$,也就是说枚举每个字符后面是否放置“$+$”号的复杂度为${2^{15}}$. 每次枚举到一种情况,看哪些位置能放“$=$”号,每个位置都试一下, ...

随机推荐

  1. 瞬间从IT屌丝变大神——CSS规范

    CSS规范主要包括以下内容: CSS Reset用YUI的CSS Reset. CSS采用CSSReset+common.css+app.css的形式. app.css采用分工制,一个前端工程师负责一 ...

  2. String比较

    String str1 = "abc"; String str2 = "abc"; String str3 = new String("abc&quo ...

  3. LUA和C++绑定的一些天然的麻烦

    最近在看Luatinker的源代码,打算自己改(仿写)写搞一个简单的封装C++和LUA的结合的库,结果发现其实麻烦和困惑比想象的多. 比如这些点: 1)有时候使用模板的时候,引用会退化. classt ...

  4. 转载-MySQL 加锁处理分析

    MySQL 加锁处理分析 发表于 2013 年 12 月 13 日 由 hedengcheng 1    背景    1 1.1    MVCC:Snapshot Read vs Current Re ...

  5. UVALive 7457 Discrete Logarithm Problem (暴力枚举)

    Discrete Logarithm Problem 题目链接: http://acm.hust.edu.cn/vjudge/contest/127401#problem/D Description ...

  6. Linux下MongoDB备份脚本

    #!/bin/bash today=`date +%Y%m%d` mongodump -h localhost -d salary -o /home/chzhao/mongobackup/$today ...

  7. codeforces 631A Interview

    A. Interview time limit per test 1 second memory limit per test 256 megabytes input standard input o ...

  8. [转]eclipse中使用maven插件的时候,运行run as maven build的时候报错

    转至:http://fxb4632242.iteye.com/blog/2193945 -Dmaven.multiModuleProjectDirectory system propery is no ...

  9. freemaker获取字符串长度

    freemarker 判断字符串长度大于多少或者int变量大于多少,比较<#if "test"?length gt 2>    长度大于2</#if> 大于 ...

  10. C#学习笔记(十三):I/O操作

    C#的IO操作主要是针对文件夹和文件的读取和写入操作,下面我们来学习一下相关操作的类. 获取文件信息 Directory和DirectoryInfo 两个类的功能基本相同,区别如下: 前者继承Syst ...