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. 教你利用iframe在网页中显示天气

    来源:http://www.ido321.com/921.html css: 1: *{margin:0;padding:0;list-style-type:none;} 2: a,img{borde ...

  2. 关于如果修改 ie 浏览器 文本模式

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/html4/stric ...

  3. 办公室网络二三事 - chunyu

    开始的时候,我们办公室拉了两条家庭百兆宽带,两条宽带分别接到路由器的wan1/wan2口上,我们愉快的工作愉快的上网. 后来,再拉了一条十兆企业专线,接到了路由器的wan3口上面,配了一些静态路由,希 ...

  4. Django settings — Django 1.6 documentation

    Django settings - Django 1.6 documentation export DJANGO_SETTINGS_MODULE=mysite.settings django-admi ...

  5. 第二百七十九天 how can I 坚持

    竟然说我是猪,也是有点受不了了.其实也没什么,无所谓. 一个人有了信仰,不管成不成功,至少不会迷茫. sql语句,left  on  and  和where,left on是先检索,再关联,主表是完整 ...

  6. Local host name unknown: java.net.UnknownHostException:

    在Linux下安装完resin后,每次启动都出现如下错误: [11:06:45.617] {watchdog-} WatchdogProcess[Watchdog[],7] starting Resi ...

  7. powershell里添加对git的支持

    在powershell命令行里依次运行 1. (new-object Net.WebClient).DownloadString("http://psget.net/GetPsGet.ps1 ...

  8. setbuf和freopen

    看memcached代码的时候学习了一个api,setbuf,可以设置文件流的缓冲区.        #include <stdio.h> void setbuf(FILE *stream ...

  9. Understanding CloudStack’s Physical Networking Architecture

    Understanding and configuring the physical connections of a host in a CloudStack deployment can at f ...

  10. 【转】Android真机抓屏- Android Screen Monitor

    http://www.cnblogs.com/xiaofeixiang/p/4086092.html 一般运行Android应用程序有两种方式一种是设置Android虚拟设备模拟器,通过Android ...