hdu3699 A hard Aoshu Problem
来源:互联网 发布:中国网络空间安全 编辑:程序博客网 时间:2024/04/29 04:30
正解是DFS每种字母代表的数字
其实暴力枚举就可以了
#include <cstdio>#include <ctime>#include <cstdlib>#include <cstring>#include <queue>#include <string>#include <set>#include <stack>#include <map>#include <cmath>#include <vector>#include <iostream>#include <algorithm>#include <bitset>#include <fstream>#include <sstream>using namespace std;//LOOP#define FF(i, a, b) for(int i = (a); i < (b); ++i)#define FE(i, a, b) for(int i = (a); i <= (b); ++i)#define FED(i, b, a) for(int i = (b); i>= (a); --i)#define REP(i, N) for(int i = 0; i < (N); ++i)#define CLR(A,value) memset(A,value,sizeof(A))#define FC(it, c) for(__typeof((c).begin()) it = (c).begin(); it != (c).end(); it++)//INPUT#define RI(n) scanf("%d", &n)#define RII(n, m) scanf("%d%d", &n, &m)#define RIII(n, m, k) scanf("%d%d%d", &n, &m, &k)#define RS(s) scanf("%s", s)typedef long long LL;typedef vector <int> VI;const int INF = 1000000007;const double eps = 1e-10;const int MOD = 1000000000;const int MAXN = 10050 * 30;int up[10], len1, len2, len3, num[10];bool f[10];char s1[20], s2[20], s3[20];int fun(int a, int b, int c, int d, int e){// cout << a << b << c << d << e << endl; LL x, y, z; int ans; x = y = z = ans = 0; num[0] = a, num[1] = b, num[2] = c, num[3] = d, num[4] = e; REP(i, 5) FF(j, i + 1, 5) if (f[i] && f[j] && num[i] == num[j]) return 0; REP(i, len1) x *= 10, x += num[s1[i] - 'A']; REP(i, len2) y *= 10, y += num[s2[i] - 'A']; REP(i, len3) z *= 10, z += num[s3[i] - 'A']; if (len1 > 1 && num[s1[0] - 'A'] == 0) return 0; if (len2 > 1 && num[s2[0] - 'A'] == 0) return 0; if (len3 > 1 && num[s3[0] - 'A'] == 0) return 0; if (x + y == z) ans++; if (x - y == z) ans++; if (x * y == z) ans++; if (y && x == z * y) ans++; return ans;}int solve(){ int ans = 0; REP(a, up[0]) REP(b, up[1]) REP(c, up[2]) REP(d, up[3]) REP(e, up[4]) ans += fun(a, b, c, d, e); return ans;}int main(){ int T; RI(T); while (T--) { RS(s1), RS(s2), RS(s3); CLR(f, 0); len1 = strlen(s1), len2 = strlen(s2), len3 = strlen(s3); REP(i, strlen(s1)) f[s1[i] - 'A'] = 1; REP(i, strlen(s2)) f[s2[i] - 'A'] = 1; REP(i, strlen(s3)) f[s3[i] - 'A'] = 1; REP(i, 5) if (f[i]) up[i] = 10; else up[i] = 1; cout << solve() << endl; }}
- HDU3699 A hard Aoshu Problem
- hdu3699 A hard Aoshu Problem
- HDU3699(POJ 3989)A hard Aoshu Problem(暴力模拟dfs)
- A very hard Aoshu problem
- A hard Aoshu Problem HDU
- A hard Aoshu Problem HDU
- A hard Aoshu Problem HDU
- A very hard Aoshu problem
- HDU 3699 A hard Aoshu Problem
- HDU 4403 A very hard Aoshu problem
- hdu 4403 A very hard Aoshu problem
- HDU:4403 A very hard Aoshu problem
- HDU 4403 A very hard Aoshu problem
- HDU 4403 A very hard Aoshu problem
- HDU 4403(A very hard Aoshu problem)
- 暴力dfs 3699 A hard Aoshu Problem
- HDOJ3699 A hard Aoshu Problem[暴力]
- HDU 4403 A very hard Aoshu problem
- Android : 线程的结束,挂起和恢复(下)
- 3.11 CMMI3级——组织培训(Organizational Training)
- ASP.NET如何实现FTP上传文件
- 在cpu架构为power的linux下安装JDK
- VMware linux 增加根目录空间 (使用图形分区工具gparted LiveCd)
- hdu3699 A hard Aoshu Problem
- UIApplication、AppDelegate、委托
- lightoj 1045 - Digits of Factorial 取对数
- C++虚继承时内存布局
- 网页bug--UTF-8 网页莫名其妙地头部出现一行空白
- 【LeetCode OJ】Populating Next Right Pointers in Each Node II
- Windows7 64bit下配置Apache+PHP+MySQL
- mysql备份还原(视图、存储过程)
- 3.12 CMMI3级——深入理解三个O(OPF OPD OT)