题目链接:1.3.3

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

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

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

  1. /*
  2. ID:wang9621
  3. PROG:crypt1
  4. LANG:C++
  5. */
  6. #include <iostream>
  7. #include <cstdio>
  8. #include <algorithm>
  9. using namespace std;
  10. int cnt[];
  11. int main()
  12. {
  13. freopen("crypt1.in","r",stdin);
  14. freopen("crypt1.out","w",stdout);
  15. int n;
  16. scanf("%d",&n);
  17. for(int i = ;i<=n; i++) scanf("%d",&cnt[i]);
  18. int count = ;
  19. int flag = ;
  20. int flag1 = ;
  21. int flag2 = ;
  22. int cnt1,cnt2;
  23. for(int i = ; i<=n; i++)
  24. {
  25. if(cnt[i]==&&i==) continue;
  26. for(int j = ; j<=n; j++)
  27. {
  28. for(int k = ; k<=n; k++)
  29. {
  30. flag = cnt[i]*+cnt[j]*+cnt[k];
  31. for(int p = ; p<=n; p++)
  32. {
  33. if(cnt[p]==&&p==) continue;
  34. for(int q = ; q<=n; q++)
  35. {
  36. cnt1 = flag1 = flag*cnt[p];
  37. cnt2 = flag2 = flag*cnt[q];
  38. int flag11 = ;
  39. int wei1 = ;
  40. int flag22 = ;
  41. int wei2 = ;
  42. while(flag1)
  43. {
  44. int sou = flag1%;
  45. for(int s = ; s<=n; s++)
  46. {
  47. if(cnt[s] == sou)
  48. {
  49. flag11++;
  50. break;
  51. }
  52. }
  53. wei1++;
  54. flag1 /= ;
  55. }
  56. while(flag2)
  57. {
  58. int sou = flag2%;
  59. for(int s = ; s<=n; s++)
  60. {
  61. if(cnt[s] == sou)
  62. {
  63. flag22++;
  64. break;
  65. }
  66. }
  67. wei2++;
  68. flag2 /= ;
  69. }
  70. if(flag11==&&flag22==&&wei1==&&wei2==)
  71. {
  72. int sum = cnt1+cnt2*;
  73. int cntt = ;
  74. int cnttt = ;
  75. while(sum)
  76. {
  77. int sou = sum%;
  78. for(int s = ; s<=n; s++)
  79. {
  80. if(cnt[s] == sou)
  81. {
  82. cntt++;
  83. break;
  84. }
  85. }
  86. cnttt++;
  87. sum /= ;
  88. }
  89. if(cntt==&&cnttt==)
  90. {
  91. count++;
  92. }
  93. }
  94. }
  95. }
  96. }
  97. }
  98. }
  99. printf("%d\n",count);
  100. return ;
  101. }

我的代码

测试结果

  1. Executing...
  2. Test 1: TEST OK [0.000 secs, 4184 KB]
  3. Test 2: TEST OK [0.000 secs, 4184 KB]
  4. Test 3: TEST OK [0.000 secs, 4184 KB]
  5. Test 4: TEST OK [0.000 secs, 4184 KB]
  6. Test 5: TEST OK [0.011 secs, 4184 KB]
  7. Test 6: TEST OK [0.000 secs, 4184 KB]
  8. Test 7: TEST OK [0.011 secs, 4184 KB]
  9.  
  10. All tests OK.
  1. /*
  2. ID:wang9621
  3. PROG:crypt1
  4. LANG:C++
  5. */
  6. #include <iostream>
  7. #include <cstdio>
  8. #include <algorithm>
  9. using namespace std;
  10. int cnt[];
  11. bool hash1(int x)
  12. {
  13. while(x)
  14. {
  15. if(!cnt[x%]) return false;
  16. x /= ;
  17. }
  18. return true;
  19. }
  20. int main()
  21. {
  22. freopen("crypt1.in","r",stdin);
  23. freopen("crypt1.out","w",stdout);
  24. int n,x;
  25. int count = ;
  26. scanf("%d",&n);
  27. for(int i = ;i<=n; i++)
  28. {
  29. scanf("%d",&x);
  30. cnt[x] = ;
  31. }
  32. for(int i = ; i<; i++)
  33. {
  34. if(hash1(i))
  35. {
  36. for(int j = ; j<; j++)
  37. {
  38. if(hash1(j))
  39. {
  40. if(i*j<&&i*(j/)<&&i*(j%)<&&hash1(i*(j%))&&hash1(i*(j/))&&hash1(i*j))
  41. {
  42. count++;
  43. }
  44. }
  45. }
  46. }
  47. }
  48. printf("%d\n",count);
  49. return ;
  50. }

高效代码

  1. 测试结果
  2.  
  3. Executing...
  4. Test 1: TEST OK [0.000 secs, 4180 KB]
  5. Test 2: TEST OK [0.000 secs, 4180 KB]
  6. Test 3: TEST OK [0.000 secs, 4180 KB]
  7. Test 4: TEST OK [0.000 secs, 4180 KB]
  8. Test 5: TEST OK [0.000 secs, 4180 KB]
  9. Test 6: TEST OK [0.000 secs, 4180 KB]
  10. Test 7: TEST OK [0.000 secs, 4180 KB]
  1. 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. R语言笔记4--可视化

    接R语言笔记3--实例1 R语言中的可视化函数分为两大类,探索性可视化(陌生数据集,不了解,需要探索里面的信息:偏重于快速,方便的工具)和解释性可视化(完全了解数据集,里面的故事需要讲解别人:偏重全面 ...

  2. listview前几个item的图片怎么是空白的、listview更新了ui不起作用、在handler里更新了UI不起作用

    不是不起作用,不信你可以在更新ui代码附近加输出的log,说明程序是跑到那里了.但是未达到我们的想要的效果. 我们知道在listview里更新UI,listview的适配器Adapter里有个getV ...

  3. MySQL 对于千万级的大表要怎么优化

    转自知乎 作者:哈哈链接:http://www.zhihu.com/question/19719997/answer/81930332来源:知乎著作权归作者所有,转载请联系作者获得授权. 很多人第一反 ...

  4. Eclipse的Console乱码

    1.找到服务器bin目录:例:D:\WebLogic_11g\Middleware\user_projects\domains\dsrhd_domain\bin, 在该目录下找到setDomainEn ...

  5. queue(),dequeue()

    这两个方法,一个是往里面添加队列,一个是执行队列 也是分静态方法和实例方法, 同样,实例方法最后调用静态方法 源码主要分析一下延迟delay方法,如何起作用的,写的有点仓促,先记录一下 在这里参照了网 ...

  6. 首次编译TI Android JB-4.2.2-DevKit-4.1.1的时候提示jdk版本不对

    http://processors.wiki.ti.com/index.php/TI-Android-JB-4.2.2-DevKit-4.1.1_DeveloperGuide#Configure_An ...

  7. 转载,find.sh

    #!/bin/bash #find files contains a keyword #write by xiaojing.zhao #2012.12.14 echo -e "\nThis ...

  8. Echarts自适应浏览器大小

    var myChart = echarts.init(document.getElementById('sitesChar')); var option = { title : { text: 'No ...

  9. HDU 3732 Ahui Writes Word 多重背包优化01背包

    题目大意:有n个单词,m的耐心,每个单词有一定的价值,以及学习这个单词所消耗的耐心,耐心消耗完则,无法学习.问能学到的单词的最大价值为多少. 题目思路:很明显的01背包,但如果按常规的方法解决时间复杂 ...

  10. 50条规则提高PHP开发提高效率技巧

    0.用单引号代替双引号来包含字符串,这样做会更快一些.因为PHP会在双引号包围的字符串中搜寻变量,单引号则不会,注意:只有echo能这么做,它是一种可以把多个字符串当作 参数的“函数”(译注:PHP手 ...