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 1680 [Usaco2005 Mar]Yogurt factory:贪心【只用考虑上一个】
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1680 题意: 在接下来的n周内,第i周生产一吨酸奶的成本为c[i],订单为y[i]吨酸奶. ...
- 华为机试题 N阶楼梯的走法,每次走一步或者两步
在Stairs函数中实现该功能: 一个楼梯有N阶,从下往上走,一步可以走一阶,也可以走两阶,有多少种走法? (0<n<=30)<> 例如3阶楼梯有3种走法: 1.1.1 1.2 ...
- 使用svg的几种方式
<!-- 图片,背景,框架引入svg文件 --> <img src="test.svg" alt=""> <?xml versio ...
- 「LOJ#6121」「网络流 24 题」孤岛营救问题(BFS
题目描述 1944 年,特种兵麦克接到国防部的命令,要求立即赶赴太平洋上的一个孤岛,营救被敌军俘虏的大兵瑞恩.瑞恩被关押在一个迷宫里,迷宫地形复杂,但幸好麦克得到了迷宫的地形图.迷宫的外形是一个长方形 ...
- 【算法模板】Binary Search 二分查找
模板:(通用模板,推荐) 给定一个排序的整数数组(升序)和一个要查找的整数target,用O(logn)的时间查找到target第一次出现的下标(从0开始),如果target不存在于数组中,返回-1. ...
- dataguard类型转换与模式转化
修改数据保护模式步骤 前提:是否满足转换模式的配置要求 最大保护(Maximum Protection):Standby Database 必须配置Standby Redo Log,Primary D ...
- algorithm-exercise
https://github.com/billryan/algorithm-exercise Part I - Basics Basic Data Structure string: s2 = &qu ...
- ipv4 ipv6简介
互联网协议地址(英语:Internet Protocol Address,又译为网际协议地址),缩写为IP地址(IP Address),在Internet上,一种给主机编址的方式.常见的IP地址,分为 ...
- PCL推荐的命名规范(2)
博客转载自:http://www.pclcn.org/study/shownews.php?lang=cn&id=210 函数/成员函数命名 函数和类的成员函数的命名应该采用camelCase ...
- 第3章 编写ROS程序-2
1.发布者程序 在本节中,我们将看到如何发送随机生成的速度指令到一个turtlesim海龟,使它漫无目的地巡游.这个程序的源文件称为pubvel,这个程序展示了从代码中发布消息涉及的所有要素. 其代码 ...