p1211 Prime Cryptarithm
直接深搜+检验。
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cstring>
#include <map>
#include <queue>
#include <set>
#include <cassert>
#include <stack>
#define mkp make_pair
using namespace std;
const double EPS=1e-;
typedef long long lon;
const lon SZ=,INF=0x7FFFFFFF;
int n,tot;
vector<int> vct; int getr(vector<int> &x,int pos)
{
int res=;
for(int i=;i<;++i)
{
res+=x[pos]*x[i]*pow(,i)+0.5;
}
return res;
} bool chk(int x,int dgt)
{
int std=pow(,dgt)+0.5;
if(x>=std)return ;
for(;x;)
{
if(find(vct.begin(),vct.end(),x%)==vct.end())return ;
x/=;
}
return ;
} void dfs(vector<int> &x)
{
if(x.size()==)
{
int res1=getr(x,);
int res2=getr(x,);
int res=res1+res2*; if(chk(res1,)&&chk(res2,)&&chk(res,))
{
//cout<<res1<<" "<<res2<<" "<<res<<endl;
++tot;
}
return;
}
for(int i=;i<vct.size();++i)
{
x.push_back(vct[i]);
dfs(x);
x.pop_back();
}
} int main()
{
std::ios::sync_with_stdio();
//freopen("d:\\1.txt","r",stdin);
lon casenum;
//cin>>casenum;
//for(lon time=1;time<=casenum;++time)
{
cin>>n;
vct.assign(n,);
for(int i=;i<n;++i)
{
cin>>vct[i];
}
vector<int> tmp;
dfs(tmp);
cout<<tot<<endl;
}
return ;
}
p1211 Prime Cryptarithm的更多相关文章
- 洛谷P1211 [USACO1.3]牛式 Prime Cryptarithm
P1211 [USACO1.3]牛式 Prime Cryptarithm 187通过 234提交 题目提供者该用户不存在 标签USACO 难度普及- 提交 讨论 题解 最新讨论 题面错误 题目描述 ...
- l洛谷——P1211 [USACO1.3]牛式 Prime Cryptarithm
P1211 [USACO1.3]牛式 Prime Cryptarithm 题目描述 下面是一个乘法竖式,如果用我们给定的那n个数字来取代*,可以使式子成立的话,我们就叫这个式子牛式. *** x ** ...
- 洛谷 P1211 [USACO1.3]牛式 Prime Cryptarithm
P1211 [USACO1.3]牛式 Prime Cryptarithm 题目描述 下面是一个乘法竖式,如果用我们给定的那n个数字来取代*,可以使式子成立的话,我们就叫这个式子牛式. *** x ** ...
- USACO Section 1.3 Prime Cryptarithm 解题报告
题目 题目描述 牛式的定义,我们首先需要看下面这个算式结构: * * * x * * ------- * * * <-- partial product 1 * * * <-- parti ...
- USACO 1.3.3 Prime Cryptarithm
题目链接:1.3.3 我用的枚举法,即每产生一组数据就判断是否是所给数字里的. AC还沾沾自喜,但一看题解,发现自己的代码真low... 在平时练习时,应该追求高效,精炼的代码,这样比赛时才能省出大量 ...
- 2312--1.3.4 Prime Cryptarithm 牛式
Description 下面是一个乘法竖式,如果用我们给定的那n个数字来取代*,可以使式子成立的话,我们就叫这个式子牛式. * * * x * * ------- * * * * * * ------ ...
- USACO 1.3.4 Prime Cryptarithm 牛式(模拟枚举)
Description 下面是一个乘法竖式,如果用我们给定的那n个数字来取代*,可以使式子成立的话,我们就叫这个式子牛式. * * * x * * ------- * * * * * * ------ ...
- USACO Section1.3 Prime Cryptarithm 解题报告
crypt1解题报告 —— icedream61 博客园(转载请注明出处)--------------------------------------------------------------- ...
- Prime Cryptarithm
链接 分析:对于三位数我们限定为[100,999],两位数我们限定为[10,99],然后我们依次判断是否满足乘法式且各个数位是否在数列中,若都满足+1 /* PROB:crypt1 ID:wangha ...
随机推荐
- vS+QT生成.pro文件
- topcoder srm 470 div1
problem1 link 首先预处理在已选字母的状态为$state$时是否可达. 然后就是按照题目进行dp.设$f[i]$表示已选字母集合为$i$时的结果. 每次可以根据$i$中含有的字母是奇数还是 ...
- P2042 [NOI2005]维护数列
思路 超级恶心的pushdown 昏天黑地的调 让我想起了我那前几个月的线段树2 错误 这恶心的一道题终于过了 太多错误,简直说不过来 pushup pushdown 主要就是这俩不太清晰,乱push ...
- 洛谷luogu2782
P2782 友好城市 题目描述 有一条横贯东西的大河,河有笔直的南北两岸,岸上各有位置各不相同的N个城市.北岸的每个城市有且仅有一个友好城市在南岸,而且不同城市的友好城市不相同.每对友好城市都向政府申 ...
- 【做题】CF1045(ABH)
原文链接https://www.cnblogs.com/cly-none/p/9697662.html 题目当然不会做完了,这里只讲有做&会做的. A. Last chance 题意:有\(n ...
- Elasticsearch 异常处理
cluster_block_exception https://stackoverflow.com/questions/50609417/elasticsearch-error-cluster-blo ...
- Excel lastindex of a substring
I think I get what you mean. Let's say for example you want the right-most \ in the following string ...
- MVC 之 初识(一)
创建一个mvc项目,在项目中会startup.cs文件,startup文件主要是将项目寻找一个宿主 过去,项目一般都是寄宿在iis上的,通过owin可以寄宿到不同的宿主. 可以关闭owin:<a ...
- springBoot 全局异常捕捉
package cn.com.cs.core.exception; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import or ...
- js操作css变量
原文:http://css-live.ru/articles/dostup-k-css-peremennym-i-ix-izmenenie-spomoshhyu-javascript.html :ro ...