题目链接:1.3.3

我用的枚举法,即每产生一组数据就判断是否是所给数字里的.

AC还沾沾自喜,但一看题解,发现自己的代码真low...

在平时练习时,应该追求高效,精炼的代码,这样比赛时才能省出大量时间去做其他题!

/*
ID:wang9621
PROG:crypt1
LANG:C++
*/
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
int cnt[];
int main()
{
freopen("crypt1.in","r",stdin);
freopen("crypt1.out","w",stdout);
int n;
scanf("%d",&n);
for(int i = ;i<=n; i++) scanf("%d",&cnt[i]);
int count = ;
int flag = ;
int flag1 = ;
int flag2 = ;
int cnt1,cnt2;
for(int i = ; i<=n; i++)
{
if(cnt[i]==&&i==) continue;
for(int j = ; j<=n; j++)
{
for(int k = ; k<=n; k++)
{
flag = cnt[i]*+cnt[j]*+cnt[k];
for(int p = ; p<=n; p++)
{
if(cnt[p]==&&p==) continue;
for(int q = ; q<=n; q++)
{
cnt1 = flag1 = flag*cnt[p];
cnt2 = flag2 = flag*cnt[q];
int flag11 = ;
int wei1 = ;
int flag22 = ;
int wei2 = ;
while(flag1)
{
int sou = flag1%;
for(int s = ; s<=n; s++)
{
if(cnt[s] == sou)
{
flag11++;
break;
}
}
wei1++;
flag1 /= ;
}
while(flag2)
{
int sou = flag2%;
for(int s = ; s<=n; s++)
{
if(cnt[s] == sou)
{
flag22++;
break;
}
}
wei2++;
flag2 /= ;
}
if(flag11==&&flag22==&&wei1==&&wei2==)
{
int sum = cnt1+cnt2*;
int cntt = ;
int cnttt = ;
while(sum)
{
int sou = sum%;
for(int s = ; s<=n; s++)
{
if(cnt[s] == sou)
{
cntt++;
break;
}
}
cnttt++;
sum /= ;
}
if(cntt==&&cnttt==)
{
count++;
}
}
}
}
}
}
}
printf("%d\n",count);
return ;
}

我的代码

测试结果

Executing...
Test 1: TEST OK [0.000 secs, 4184 KB]
Test 2: TEST OK [0.000 secs, 4184 KB]
Test 3: TEST OK [0.000 secs, 4184 KB]
Test 4: TEST OK [0.000 secs, 4184 KB]
Test 5: TEST OK [0.011 secs, 4184 KB]
Test 6: TEST OK [0.000 secs, 4184 KB]
Test 7: TEST OK [0.011 secs, 4184 KB] All tests OK.
/*
ID:wang9621
PROG:crypt1
LANG:C++
*/
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
int cnt[];
bool hash1(int x)
{
while(x)
{
if(!cnt[x%]) return false;
x /= ;
}
return true;
}
int main()
{
freopen("crypt1.in","r",stdin);
freopen("crypt1.out","w",stdout);
int n,x;
int count = ;
scanf("%d",&n);
for(int i = ;i<=n; i++)
{
scanf("%d",&x);
cnt[x] = ;
}
for(int i = ; i<; i++)
{
if(hash1(i))
{
for(int j = ; j<; j++)
{
if(hash1(j))
{
if(i*j<&&i*(j/)<&&i*(j%)<&&hash1(i*(j%))&&hash1(i*(j/))&&hash1(i*j))
{
count++;
}
}
}
}
}
printf("%d\n",count);
return ;
}

高效代码

测试结果

Executing...
Test 1: TEST OK [0.000 secs, 4180 KB]
Test 2: TEST OK [0.000 secs, 4180 KB]
Test 3: TEST OK [0.000 secs, 4180 KB]
Test 4: TEST OK [0.000 secs, 4180 KB]
Test 5: TEST OK [0.000 secs, 4180 KB]
Test 6: TEST OK [0.000 secs, 4180 KB]
Test 7: TEST OK [0.000 secs, 4180 KB]
All tests OK.

USACO 1.3.3 Prime Cryptarithm的更多相关文章

  1. USACO Section 1.3 Prime Cryptarithm 解题报告

    题目 题目描述 牛式的定义,我们首先需要看下面这个算式结构: * * * x * * ------- * * * <-- partial product 1 * * * <-- parti ...

  2. USACO 1.3.4 Prime Cryptarithm 牛式(模拟枚举)

    Description 下面是一个乘法竖式,如果用我们给定的那n个数字来取代*,可以使式子成立的话,我们就叫这个式子牛式. * * * x * * ------- * * * * * * ------ ...

  3. 洛谷P1211 [USACO1.3]牛式 Prime Cryptarithm

    P1211 [USACO1.3]牛式 Prime Cryptarithm 187通过 234提交 题目提供者该用户不存在 标签USACO 难度普及- 提交  讨论  题解 最新讨论 题面错误 题目描述 ...

  4. l洛谷——P1211 [USACO1.3]牛式 Prime Cryptarithm

    P1211 [USACO1.3]牛式 Prime Cryptarithm 题目描述 下面是一个乘法竖式,如果用我们给定的那n个数字来取代*,可以使式子成立的话,我们就叫这个式子牛式. *** x ** ...

  5. 洛谷 P1211 [USACO1.3]牛式 Prime Cryptarithm

    P1211 [USACO1.3]牛式 Prime Cryptarithm 题目描述 下面是一个乘法竖式,如果用我们给定的那n个数字来取代*,可以使式子成立的话,我们就叫这个式子牛式. *** x ** ...

  6. USACO Section1.3 Prime Cryptarithm 解题报告

    crypt1解题报告 —— icedream61 博客园(转载请注明出处)--------------------------------------------------------------- ...

  7. 【USACO题库】1.3.4 Prime Cryptarithm牛式

    好久没有发题解了,今天发一个很久很久之前写过得题吧 题目其实莫名的难 但是理解后,原来就是一只纸老虎 题目加工中~~~~(缩短题目) 加工完成:已知数字1-9组成集合的一个子集,求满足题意乘法步骤的情 ...

  8. 【USACO 1.5】Prime Palindromes

    /* TASK: pprime LANG: C++ SOLVE: 枚举数的长度,dfs出对称的数,判断是否在范围内,是否是素数 原来想着枚举每个范围里的数,但是显然超时,范围最大是10^9. 对称的数 ...

  9. p1211 Prime Cryptarithm

    直接深搜+检验. #include <iostream> #include <cstdio> #include <cmath> #include <algor ...

随机推荐

  1. mvc Controller类介绍

    1.Controller类 i.Controller必须为公开类: ii.必须以Controller结尾: iii.继承Controller基类或实现IController接口的类: iv.类中必须包 ...

  2. SharePoint2013 Set Value To PeoplePicker

    var columnName = 'Display Name';var userName = 'domain\\name';var searchText = RegExp("FieldNam ...

  3. R语言笔记5--读数据

    1.读文本文件数据 (1)先设置工作目录,把文本文件放于该目录下 备注:在记事本里写完数据后,按一下回车,负责在R语言中出现错误 (2)读剪贴板 文本或EXCEL的数据均可通过剪贴板操作 (3)读ex ...

  4. UnicodeEncodeError: 'ascii' codec can't encode characters in position 14-15: ordinal not in range(128)

    python在安装时,默认的编码是ascii,当程序中出现非ascii编码时,python的处理常常会报类似这样的错误. UnicodeEncodeError: 'ascii' codec can't ...

  5. 最佳死链接href= "#" VS href= "javascript:void(0);"

    href= "#" 熟悉hash跳转的同学都知道,只是一个hash跳转,跳转到页面的顶部,可以发现地址栏多了一个#,点击返回会返回本页面. href= "javascri ...

  6. 四种xml的解析方式

    这篇文章是我上网找资料,加上自己总结了一些而得 资料来源: http://www.cnblogs.com/allenzheng/archive/2012/12/01/2797196.html http ...

  7. T-shirts Distribution

    T-shirts Distribution time limit per test 1 second memory limit per test 256 megabytes input standar ...

  8. js 弹层 提示

    <!DOCTYPE html><html style="height: 100%;"><head lang="en"> &l ...

  9. js 关键字 in

    对于数组 ,迭代出来的是数组元 素,对于对象 ,迭代出来的是对象的属性: var x var mycars = new Array() mycars[0] = "Saab" myc ...

  10. Jdk1.7环境变量的配置

    在"系统属性——高级——环境变量——系统变量"中新建如下变量: 变量名:JAVA_HOME 变量值:C:\Program Files\Java\jdk1.7.0_03  (即jdk ...