hdu4403- A very hard Aoshu problem(搜索)
枚举等号的位置,然后暴力搜索一波 这个题本身不难,但它是我第一次使用对拍程序来查找错误,值得纪念。
#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(搜索)的更多相关文章
- HDU4403 A very hard Aoshu problem DFS
A very hard Aoshu problem Time Limit: 2000/1000 MS (Java/Others) Memory ...
- HDU 4403 A very hard Aoshu problem(DFS)
A very hard Aoshu problem Problem Description Aoshu is very popular among primary school students. I ...
- A very hard Aoshu problem(dfs或者数位)
题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=4403 A very hard Aoshu problem Time Limit: 2000/1000 ...
- 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 ...
- 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 ...
- HDU 3699 A hard Aoshu Problem (暴力搜索)
题意:题意:给你3个字符串s1,s2,s3;要求对三个字符串中的字符赋值(同样的字符串进行同样的数字替换), 替换后的三个数进行四则运算要满足左边等于右边.求有几种解法. Sample Input 2 ...
- A very hard Aoshu problem
A very hard Aoshu proble Problem Description Aoshu is very popular among primary school students. It ...
- Codeforces C. NP-Hard Problem 搜索
C. NP-Hard Problem time limit per test:2 seconds memory limit per test:256 megabytes input:standard ...
- UVALive - 5107 - A hard Aoshu Problem
题目链接:https://vjudge.net/problem/UVALive-5107 题目大意:用ABCDE代表不同的数字,给出形如ABBDE___ABCCC = BDBDE的东西: 空格里面可以 ...
随机推荐
- BZOJ 2020 [Usaco2010 Jan]Buying Feed,II:贪心【定义价值】
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=2020 题意: FJ开车去买K份食物. 如果他的车上有X份食物,每走一里就花费X元. FJ的 ...
- 2017SN多校D1T1 loveletter:模拟
题意: 两张n*m的纸.一张透明纸,上面有些地方是黑的,有些地方是透明的.另一张纸上写满了字母. 你需要将透明纸放在写字的纸上,分别顺时针旋转0°.90°.180°.270°,每次从上到下.从左到右写 ...
- Lucene默认的打分算法——ES默认
改变Lucene的打分模型 随着Apache Lucene 4.0版本在2012年的发布,这款伟大的全文检索工具包终于允许用户修改默认的基于TF/IDF原理的打分算法.Lucene API变得更加容易 ...
- 【HDU 6126】Give out candies 最小割
题意 有$n$个小朋友,给每个人分$1~m$个糖果,有k个限制 限制形如$(x,y,z)$ 表示第$x$个人分到的糖数减去第$y$个人分到的糖数不大于$z$,给第$i$个人$j$颗糖获 ...
- C++中的宏和const
在C语言中使用const来定义一个变量,可以通过变量类型的指针形式来进行修改,而C++中增强了这种表现形式,使得即使通过类型变量指针也不能对变量进行修改. 在C++中const和宏是有区别的. con ...
- BZOJ1926:[SDOI2010]粟粟的书架
浅谈主席树:https://www.cnblogs.com/AKMer/p/9956734.html 题目传送门:https://www.lydsy.com/JudgeOnline/problem.p ...
- 优化EF的性能
Entity Framework的性能优化: 1.使用MergeOption.NoTracking (发现添加这个代码后, 导致"The object cannot be deleted ...
- winform 控件合集2
http://www.cnblogs.com/peterzb/archive/2009/06/18/1505424.html 包含自定义绘制的ListBox, 带拖动,图片显示, 内嵌其它控件, 打印 ...
- Primer回顾 标准库类型
string类型的输入操作符: 1.读取并忽略开头所有的空白字符(如空格,换行符,制表符). 2.读取字符直至再次遇到空白字符,读取终止. 用getline读取整行文本 getline.接受两个参 ...
- mysql连接错误解决
EB101IWSWD-eyJsaWNlbnNlSWQiOiJFQjEwMUlXU1dEIiwibGljZW5zZWVOYW1lIjoibGFuIHl1IiwiYXNzaWduZWVOYW1lIjoiI ...