USACO Section1.3 Prime Cryptarithm 解题报告
crypt1解题报告 —— icedream61 博客园(转载请注明出处)
------------------------------------------------------------------------------------------------------------------------------------------------
【题目】
用给出的N个数字,替换以下竖式,能生成多少个正确的竖式?
* * *
x * *
-------
* * *
* * *
-------
* * * *
输入文件,第一行N表示有N个数字,第二行给出所有数字(空格分割。)
【数据范围】
所有数字∈{1,2,3,4,5,6,7,8,9}
【输入样例】
5
2 3 4 6 8
【输出样例】
1
------------------------------------------------------------------------------------------------------------------------------------------------
【分析】
竖式中,只要知道乘数和被乘数,就可以计算出下面三个结果。
因此,只要枚举这两个数就好,一共5位,9^5<100000,一定没问题。
------------------------------------------------------------------------------------------------------------------------------------------------
【总结】
一遍AC。
样例一开始本机测试没过,原因是乘出来的三个结果没判断位数是否正确。可以说,还是读题不够严谨仔细。
------------------------------------------------------------------------------------------------------------------------------------------------
【代码】
/*
ID: icedrea1
PROB: crypt1
LANG: C++
*/ #include <iostream>
#include <fstream>
using namespace std; int N,D[];
bool have[]; bool ok(int num)
{
while(num)
{
if(!have[num%]) return false;
num/=;
}
return true;
}
bool ok(int A,int B,int C,int D,int E)
{
int i = A*+B*+C;
int j = D*+E;
int x = i*E; if(x< || x>) return false;
int y = i*D; if(y< || y>) return false;
int z = x+y*; if(z< || z>) return false;
return ok(x) && ok(y) && ok(z);
} int main()
{
ifstream in("crypt1.in");
ofstream out("crypt1.out"); in>>N;
for(int i=;i<=N;++i) { in>>D[i]; have[D[i]]=true; } int s=;
for(int a=;a<=N;++a)
for(int b=;b<=N;++b)
for(int c=;c<=N;++c)
for(int d=;d<=N;++d)
for(int e=;e<=N;++e)
if(ok(D[a],D[b],D[c],D[d],D[e])) ++s;
out<<s<<endl; in.close();
out.close();
return ;
}
USACO Section1.3 Prime Cryptarithm 解题报告的更多相关文章
- USACO Section1.5 Prime Palindromes 解题报告
pprime解题报告 —— icedream61 博客园(转载请注明出处)--------------------------------------------------------------- ...
- USACO Section1.5 Superprime Rib 解题报告
sprime解题报告 —— icedream61 博客园(转载请注明出处)--------------------------------------------------------------- ...
- USACO Section1.5 Number Triangles 解题报告
numtri解题报告 —— icedream61 博客园(转载请注明出处)--------------------------------------------------------------- ...
- USACO Section1.4 Arithmetic Progressions 解题报告
ariprog解题报告 —— icedream61 博客园(转载请注明出处)-------------------------------------------------------------- ...
- USACO Section1.3 Combination Lock 解题报告
combo解题报告 —— icedream61 博客园(转载请注明出处)---------------------------------------------------------------- ...
- USACO Section1.3 Barn Repair 解题报告
barn1解题报告 —— icedream61 博客园(转载请注明出处)---------------------------------------------------------------- ...
- USACO Section1.3 Mixing Milk 解题报告
milk解题报告 —— icedream61 博客园(转载请注明出处)----------------------------------------------------------------- ...
- USACO Section1.2 Palindromic Squares 解题报告
palsquare解题报告 —— icedream61 博客园(转载请注明出处)------------------------------------------------------------ ...
- USACO Section1.2 Dual Palindromes 解题报告
dualpal解题报告 —— icedream61 博客园(转载请注明出处)-------------------------------------------------------------- ...
随机推荐
- Windows 静态IP脚本
@echo off echo 快速设置IP地址和DNS为“静态” set 连接名称=以太网 set ip地址=192.168.1.80 set 子网掩码=255.255.255.0 set 网关地址= ...
- 利用批处理结合Msbuild实现快速编译
我们经常在用vs2005做项目的时候会把一个项目分成几个模块(不管是对于功能上,还是系统构架上面),为的是以后部署,还有修改维护时候的方便.这样就会带来一个问题,随着模块的增加(这里所说得每个模块就是 ...
- BestCoder Round #89 1001 Fxx and string
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5944 分析: 竟然 i,j,k成等比数列,即i*k = j*j,还要满足 j|i or j|k. 不防 ...
- DP之背包问题详解及案例
0-1背包 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2602 #include <stdio.h> #include <stri ...
- libtool: Version mismatch error. 解决方法
在编译一个软件的时候,在 ./configure 和 make 之后可能会出现如下错误: libtool: Version mismatch error. This is libtool 2.4. ...
- python 删除空白
Python能够找出字符串开头和末尾多余的空白.要确保字符串末尾没有空白,可使用方法rstrip() . >>> favorite_language = 'python ' > ...
- ThinkPHP 更新数据 save方法
ThinkPHP save() 方法 ThinkPHP 中使用 save() 方法来更新数据库,并且也支持连贯操作的使用. 例子: public function update(){ header(& ...
- iOS内存区域部分内容
目前参考这里: https://www.zhihu.com/question/263823072/answer/273452932 以后整理相关的代码问题. 更多参考资料: https://stack ...
- 2、SpringBoot+Mybatis整合------一对一
开发工具:STS 代码下载链接:https://github.com/theIndoorTrain/SpringBoot_Mybatis01/tree/93398da60c647573645917b2 ...
- Python爬虫,看看我最近博客都写了啥,带你制作高逼格的数据聚合云图
转载请标明出处: http://blog.csdn.net/forezp/article/details/70198541 本文出自方志朋的博客 今天一时兴起,想用python爬爬自己的博客,通过数据 ...