枚举等号的位置,然后暴力搜索一波 这个题本身不难,但它是我第一次使用对拍程序来查找错误,值得纪念。

 #include<cstdio>

 #include<string.h>

 #include<map>

 #include<algorithm>

 #define inf 0x3f3f3f3f

 const int maxn=;

 using namespace std;

 typedef pair<int,int> P;

 int len,d,b,c,ans;

 char a[maxn+];

 map<P,int> m1,m2;

 int cal(int l,int r){
if(l>r) return ;
int res=;
for(int i=l;i<=r;i++){
res=res*+a[i]-'';
}
return res;
} void dfs(int l,int r,int sum,int f,int eq){
if(!f){
if(l>r){
m1[P(sum,eq)]++;
return ;
}
for(int i=l;i<=r;i++){
dfs(i+,r,sum+cal(l,i),,eq);
}
} else {
if(l>r){
m2[P(sum,eq)]++;
return ;
}
for(int i=l;i<=r;i++){
dfs(i+,r,sum+cal(l,i),,eq);
} }
} int main()
{
// freopen("e://duipai//data.txt","r",stdin);
// freopen("e://duipai//out1.txt","w",stdout);
while(scanf("%s",a)!=EOF){
if(a[]=='E')
break;
len=strlen(a);
ans=;
for(int i=;i<len;i++){
m1.clear();
dfs(,i-,,,i);
m2.clear();
dfs(i,len-,,,i);
map<P,int>::iterator it=m1.begin();
for(;it!=m1.end();++it){
int a=m1[P((*it).first.first,(*it).first.second)];
int b=m2[P((*it).first.first,(*it).first.second)];
if(a&&b) {
ans+=(a*b);
}
}
}
printf("%d\n",ans);
}
return ;
}

hdu4403- A very hard Aoshu problem(搜索)的更多相关文章

  1. HDU4403 A very hard Aoshu problem DFS

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

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

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

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

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

  4. 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 ...

  5. 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 ...

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

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

  7. A very hard Aoshu problem

    A very hard Aoshu proble Problem Description Aoshu is very popular among primary school students. It ...

  8. Codeforces C. NP-Hard Problem 搜索

    C. NP-Hard Problem time limit per test:2 seconds memory limit per test:256 megabytes input:standard ...

  9. UVALive - 5107 - A hard Aoshu Problem

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

随机推荐

  1. 一小时搞明白自定义注解(Annotation)

    原文链接:http://blog.csdn.net/u013045971/article/details/53433874 什么是注解 Annotation(注解)就是Java提供了一种元程序中的元素 ...

  2. BZOJ 1638 [Usaco2007 Mar]Cow Traffic 奶牛交通:记忆化搜索【图中边的经过次数】

    题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1638 题意: 给你一个有向图,n个点,m条有向边. 对于所有从入度为0的点到n的路径,找出 ...

  3. EOF的使用

    1.我疑惑了 char a[20]; while(scanf("%s",a)!=EOF){ cout<<"hello"<<endl; } ...

  4. ES6 generator 基础

    参考文档 harmony:generators Generator是ES6的新特性,通过yield关键字,可以让函数的执行流挂起,那么便为改变执行流程提供了可能. 创建Generator functi ...

  5. leetcode 23. Merge k Sorted Lists(堆||分治法)

    Merge k sorted linked lists and return it as one sorted list. 题意:把k个已经排好序的链表整合到一个链表中,并且这个链表是排了序的. 题解 ...

  6. js图片上传及显示

    html部分: <form action='' method='post' name='myform'> <input type='file' id='iptfileupload' ...

  7. Linux 中安装软件报缺少共享库文件的错误

    linux 安装一些如软件 或者相关的模块时,经常报出缺少一些依赖包的 libxxx.so等的共享库文件 首先找到 该共享库文件 然后查看/etc/ld.so.conf 这个文件记录了编译时使用的动态 ...

  8. javaScript运算符之in运算符

  9. Tensorflow知识点学习

    1.TensorFlow中Tensor维度理解: (1)对于2维Tensor 0维对应列 1维对应行 (2)维度操作举例: 对于k维的,tf.reduce_sum(x, axis=k-1)的结果是对最 ...

  10. linux svn 客户端基本使用命令

    1.从svn获取项目 svn co URL --username XX --password XX; 2.添加code file svn add codeFile; svn ci -m "c ...