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 ...
随机推荐
- 对象new和不new的理解
1.现象 在一个线程类[QObject]中声明一个对象QTimer,[不new,直接声明],在槽函数中timer.start() 报警告:不能跨线程调用对象 2.分析 不使用new的方式,直接A a; ...
- python --- 04 列表 元组
一 .列表 在python中使用[]来描述列表, 内部元素用逗号隔开. 对数据类型没有要求 1.列表存在索引和切片. 和字符串是一样的. 2.增删改查操作 1).增加 1. .append(" ...
- Eclipse之maven插件link方式安装
maven是开发人员要具备的必不可少的技能之一.在使用eclipse进行开发时,我们需要安装maven插件,网上有很多教程,但是有些教程写的太过模糊.在此,我将自己的安装方法总结一下,尽量细致. 前提 ...
- Flask学习【第11篇】:整合Flask中的一些知识点
SQLAlchemy-Utils 由于sqlalchemy中没有提供choice方法,所以借助SQLAlchemy-Utils组件提供的choice方法 import datetime from sq ...
- cygwin下如何编译安装minicom?
1. 安装依赖的软件和库 apt-cyg install autoconf automake make libncurses-devel (apt-cyg工具的安装方法在此) 2. 获取源码 wget ...
- Manjaro 系统添加国内源和安装搜狗输入法
添加中科大源 #打开配置文件 kate /etc/pacman.conf 在文件末尾添加 [archlinuxcn] SigLevel = Optional TrustedOnly Server = ...
- Git 命令收集
目录 1.清理恢复 2.回滚,reset与revert的区别 3.merge,rebase,cherry-pick区别 4.删除不存在对应远程分支的本地分支 5.git pull,git push 报 ...
- MySQL 5.7的原生JSON数据类型使用
新增测试用表: CREATE TABLE lnmp ( `id` ) unsigned NOT NULL AUTO_INCREMENT, `category` JSON, `tags` JSON, P ...
- 17秋 SDN课程 第一次作业
SDN第一次作业 你会选择作 网络编程 方向的程序员吗?为什么? 有可能.原因如下: 1.我的研究与网络密切相关: 2.SDN侧重软件实现,自然涉及socket等网络编程知识,属于基本功: 3.市场. ...
- 《C语言程序设计》指针篇<一>
指针 指针是C语言的精华,同时也是其中的难点和重点,我在近日对这一部分内容进行了重新的研读,把其中的一些例子自己重新编写和理解了一遍.此篇博客的内容即是我自己对此书例子的一些理解和总结. 一.大问题: ...