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. 【暑假】[基本数据结构]根据in_order与post_order构树

    Tree Time Limit: 3000MS   Memory Limit: Unknown   64bit IO Format: %lld & %llu Submit Status Des ...

  2. HDU 1708

    思路 :二位数组维护数目. #include<iostream> #include<stdio.h> #include<stdlib.h> #include< ...

  3. Tkinter教程之Label篇

    本文转载自:http://blog.csdn.net/jcodeer/article/details/1811293 #Tkinter教程之Label篇'''1.Label的第一个例子text属性使用 ...

  4. CTS FAIL(一)

    首先简单介绍下CTS:全称Compatibility Test Suite,通过CTS测试,来检测android apk与android系统的兼容性. 最近公司release一版新的Image,但在新 ...

  5. Hbase物理模型

    ​Hbase ​ 一种高可靠,面向列,可伸缩,事实读写的分布式数据库. 利用HDFS作为其文件存储系统. MapReduce处理数据. Zookeeper分布式协同服务. 数据结构 Row Key:行 ...

  6. Google Appengine参考路径

    1.Hello, World! in 5 minutes 2.Creating a Guestbook -Introduction 3.Sample Applications 1.Programmin ...

  7. HDU 5660 jrMz and angles (暴力枚举)

    jrMz and angles 题目链接: http://acm.hust.edu.cn/vjudge/contest/123316#problem/E Description jrMz has tw ...

  8. Linux下常用的shell命令记录

     硬件篇 CPU相关 lscpu #查看的是cpu的统计信息. cat /proc/cpuinfo #查看CPU信息详细信息,如每个CPU的型号,主频等 内存相关 free -m #概要查看内存情况 ...

  9. string中c_str()、data()、copy(p,n)函数的用法

    标准库的string类提供了3个成员函数来从一个string得到c类型的字符数组:c_str().data().copy(p,n). 1. c_str():生成一个const char*指针,指向以空 ...

  10. C++中void型指针

    问题由来: PX_FORCE_INLINE void* operator new(size_t size, const char* handle, const char * filename, int ...