题目链接: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. 开始工作----微信通过get检查当前网站---是否可用

    01开发者--基本配置--url服务器地址---填写好--需要开通微信接口的域名 http://www.cctv.com/xxx.php文件 xxx.php文件 01参考wx_sample.php 0 ...

  2. LeetCode OJ 86. Partition List

    Given a linked list and a value x, partition it such that all nodes less than x come before nodes gr ...

  3. Java学习笔记之[ 利用扫描仪Scanner进行数据输入 ]

    /*********数据的输入********//**利用扫描仪Scanner进行数据输入 怎么使用扫描仪Scanner *1.放在类声明之前,引入扫描仪 import java.util.Scann ...

  4. rs.Open sql,conn,0,2,1

    例子:rs.Open sql,conn,0,2,1 CursorType = 0,默认值,打开仅向前类型游标.LockType = 2, 开放式锁定Options = 1, 指示 ADO 生成 SQL ...

  5. ubuntu 安装LNMP

    How To Install Linux, nginx, MySQL, PHP (LEMP) stack on Ubuntu 12.04 PostedJune 13, 2012 802.8kviews ...

  6. 关于tab选项卡,选项的css问题。

    刚开始的思路是:让上面的选中的选项背景变成白色,让下面的层position:absolute;z-index:-1;top:1px,就能盖得上上面的横线.实践证明,这样是能盖得上,但是单选按钮不能点了 ...

  7. JQuery中$.ajax()方法参数详解 (20

    url: 要求为String类型的参数,(默认为当前页地址)发送请求的地址. type: 要求为String类型的参数,请求方式(post或get)默认为get.注意其他http请求方法,例如put和 ...

  8. php下载文件的一种方式

    <?php ob_start(); // $file_name="cookie.jpg"; $file_name="abc.jpg"; //用以解决中文不 ...

  9. Chapter 1 First Sight——22

    The girls were opposites. The tall one was statuesque. 女生却相反,高的像雕像一般 She had a beautiful figure, the ...

  10. 剑指offer 整数中1 出现的次数

    给定一个十进制正整数N,写下从1开始,到N的所有整数,然后数一下其中出现的所有"1"的个数. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 1 ...