题意:给定两个数的n和m,有一种操作,把 n 的各位数字加起来放到 n后面形成一个新数n,问重复 m 次所得的数能否整除 11。

析:这个题首先要知道一个规律奇数位的和减去偶数位的和能被11整除的数字一定能被11整除。当然不知道这个题也可以过,直接模拟。

还有几个其他的规律;

被3整除:每位的和能被3整除即可;

被4整除:末尾两位能被4整除即可;

被7整除:将个位数字截去,在余下的数中减去个位数字的二倍,差是7的倍数即可;(可以递归)

被8整除:末尾三位能被8整除即可;

被9整除:每位的和能被9整除即可;

被11整除:第一种方法就是用上面说的,还有一种是采用和“被7整除”一样的方法,不过要减去的是个位的一倍;

被12整除:同时被3和4整除;

被13整除:同“被7整除”,不过我们不是要减去,而是要加上个位的四倍;

被17整除:同“被7整除”,不过要减去的是个位数的五倍;

被19整除:同“被7整除”,不过要加上个位数的两倍;

代码如下:

直接模拟:

  1. #pragma comment(linker, "/STACK:1024000000,1024000000")
  2. #include <cstdio>
  3. #include <string>
  4. #include <cstdlib>
  5. #include <cmath>
  6. #include <iostream>
  7. #include <cstring>
  8. #include <set>
  9. #include <queue>
  10. #include <algorithm>
  11. #include <vector>
  12. #include <map>
  13. #include <cctype>
  14. #include <cmath>
  15. #include <stack>
  16. #include <sstream>
  17. #define debug() puts("++++");
  18. #define gcd(a, b) __gcd(a, b)
  19. #define lson l,m,rt<<1
  20. #define rson m+1,r,rt<<1|1
  21. #define freopenr freopen("in.txt", "r", stdin)
  22. #define freopenw freopen("out.txt", "w", stdout)
  23. using namespace std;
  24.  
  25. typedef long long LL;
  26. typedef unsigned long long ULL;
  27. typedef pair<int, int> P;
  28. const int INF = 0x3f3f3f3f;
  29. const LL LNF = 1e17;
  30. const double inf = 0x3f3f3f3f3f3f;
  31. const double PI = acos(-1.0);
  32. const double eps = 1e-8;
  33. const int maxn = 10 + 10;
  34. const int mod = 1000000007;
  35. const int dr[] = {-1, 0, 1, 0};
  36. const int dc[] = {0, 1, 0, -1};
  37. const char *de[] = {"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"};
  38. int n, m;
  39. const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
  40. const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
  41. inline bool is_in(int r, int c){
  42. return r >= 0 && r < n && c >= 0 && c < m;
  43. }
  44.  
  45. int a[30];
  46.  
  47. int calc(int sum, int &ans){
  48. int cnt = 0;
  49. while(sum){
  50. a[cnt++] = sum % 10;
  51. sum /= 10;
  52. }
  53. for(int i = cnt-1; i >= 0; --i){
  54. ans = (ans * 10 + a[i]) % 11;
  55. sum += a[i];
  56. }
  57.  
  58. return sum;
  59. }
  60.  
  61. int main(){
  62. int kase = 0;
  63. while(scanf("%d %d", &n, &m) == 2){
  64. if(-1 == m && -1 == n) break;
  65. int ans = 0;
  66. int sum = calc(n, ans);
  67. for(int i = 0; i < m; ++i)
  68. sum += calc(sum, ans);
  69.  
  70. printf("Case #%d: %s\n", ++kase, ans ? "No" : "Yes");
  71. }
  72. return 0;
  73. }

使用规律:

  1. #pragma comment(linker, "/STACK:1024000000,1024000000")
  2. #include <cstdio>
  3. #include <string>
  4. #include <cstdlib>
  5. #include <cmath>
  6. #include <iostream>
  7. #include <cstring>
  8. #include <set>
  9. #include <queue>
  10. #include <algorithm>
  11. #include <vector>
  12. #include <map>
  13. #include <cctype>
  14. #include <cmath>
  15. #include <stack>
  16. #include <sstream>
  17. #define debug() puts("++++");
  18. #define gcd(a, b) __gcd(a, b)
  19. #define lson l,m,rt<<1
  20. #define rson m+1,r,rt<<1|1
  21. #define freopenr freopen("in.txt", "r", stdin)
  22. #define freopenw freopen("out.txt", "w", stdout)
  23. using namespace std;
  24.  
  25. typedef long long LL;
  26. typedef unsigned long long ULL;
  27. typedef pair<int, int> P;
  28. const int INF = 0x3f3f3f3f;
  29. const LL LNF = 1e17;
  30. const double inf = 0x3f3f3f3f3f3f;
  31. const double PI = acos(-1.0);
  32. const double eps = 1e-8;
  33. const int maxn = 10 + 10;
  34. const int mod = 1000000007;
  35. const int dr[] = {-1, 0, 1, 0};
  36. const int dc[] = {0, 1, 0, -1};
  37. const char *de[] = {"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"};
  38. int n, m;
  39. const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
  40. const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
  41. inline bool is_in(int r, int c){
  42. return r >= 0 && r < n && c >= 0 && c < m;
  43. }
  44.  
  45. int a[30];
  46.  
  47. int calc(int &odd, int &even, int sum, bool &ok){
  48. int cnt = 0;
  49. while(sum){
  50. a[cnt++] = sum % 10;
  51. sum /= 10;
  52. }
  53. for(int i = cnt-1; i >= 0; --i, ok = !ok){
  54. if(ok) odd += a[i];
  55. else even += a[i];
  56. }
  57. return odd + even;
  58. }
  59.  
  60. int main(){
  61. int kase = 0;
  62. while(scanf("%d %d", &n, &m) == 2){
  63. if(-1 == m && -1 == n) break;
  64. int even = 0, odd = 0;
  65. bool ok = true;
  66. int sum = calc(odd, even, n, ok);
  67. for(int i = 0; i < m; ++i){
  68. int dodd = 0, deven = 0;
  69. sum += calc(dodd, deven, sum, ok);
  70. odd += dodd;
  71. even += deven;
  72. }
  73. int det = odd - even;
  74. printf("Case #%d: %s\n", ++kase, det % 11 ? "No" : "Yes");
  75. }
  76. return 0;
  77. }

  

HDU 5373 The shortest problem (数学)的更多相关文章

  1. hdu 5373 The shortest problem(杭电多校赛第七场)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5373 The shortest problem Time Limit: 3000/1500 MS (J ...

  2. 2015 Multi-University Training Contest 7 hdu 5373 The shortest problem

    The shortest problem Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Oth ...

  3. 同余模定理 HDOJ 5373 The shortest problem

    题目传送门 /* 题意:题目讲的很清楚:When n=123 and t=3 then we can get 123->1236->123612->12361215.要求t次操作后, ...

  4. hdoj 5373 The shortest problem

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5373 一开始想到用整除11的性质去做,即奇位数的和和偶位数的和的差为11的倍数,但估不准数据范围没敢去 ...

  5. HDU 5373(2015多校7)-The shortest problem(模拟%11)

    题目地址:pid=5373">HDU 5373 题意:给你一个数n和操作次数t,每次操作将n的各位数之和求出来放在n的末尾形成新的n,问t次操作后得到的n能否够被11整除. 思路:就是 ...

  6. The shortest problem(hdu,多校

    The shortest problem Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Oth ...

  7. HDU-5373 The shortest problem

    The shortest problem http://acm.hdu.edu.cn/showproblem.php?pid=5373 Time Limit: 3000/1500 MS (Java/O ...

  8. HDU 4725 The Shortest Path in Nya Graph [构造 + 最短路]

    HDU - 4725 The Shortest Path in Nya Graph http://acm.hdu.edu.cn/showproblem.php?pid=4725 This is a v ...

  9. HDU 5832 A water problem(某水题)

    p.MsoNormal { margin: 0pt; margin-bottom: .0001pt; text-align: justify; font-family: Calibri; font-s ...

随机推荐

  1. UVA 10417 Gift Exchanging

    #include <iostream> #include <cstring> #include <stdio.h> #include <math.h> ...

  2. python exec内置表达式--exec()

    exec obj功能: exec 执行储存在字符串或文件中的Python语句,相比于 eval,exec可以执行更复杂的 Python 代码.obj 是 要执行的表达式.exec 返回值永远为 Non ...

  3. 释放Windows C盘空间 -- 虚拟内存和休眠文件

    本文由Suzzz原创,发布于 http://www.cnblogs.com/Suzzz/p/4111718.html ,转载请保留此声明. 项目组有一Windows工作站, 由于需要使用Kinect最 ...

  4. 5、Selenium+Python自动登录163邮箱发送邮件

    1.Selenium实现自动化,需要定位元素,以下查看163邮箱的登录元素 (1)登录(定位到登录框,登录框是一个iframe,如果没有定位到iframe,是无法定位到账号框与密码框) 定位到邮箱框( ...

  5. IHE 官方网址有用资源介绍

    实现标准: http://www.ihe.net/Technical_Frameworks/ 各个实现框架文档, 比如XDS,XCA,PIX,PDQ等 测试工具:http://www.ihe.net/ ...

  6. vim编辑 小笔记

    http://jingyan.baidu.com/article/495ba8410ff14d38b30ede01.html vim编辑器笔记 1.vi 文件名 打开文件 2.按 i 键 进入inse ...

  7. 用Json Template在Azure上创建Cisco CSR路由器

    Azure的ARM模式可以通过Json的模板创建VM.本文以Cisco的CSR的image为例,介绍如何用Json的创建VM. 一.Cisco CSR的Image 首先把Cisco CSR的image ...

  8. HDU5468(dfs序+容斥原理)

    Puzzled Elena Time Limit: 5000/2500 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)T ...

  9. Java基础--单例类创建和测试

    单例模式的主要作用是保证在Java程序中,某个类只有一个实例存在.单例模式有很多好处,它能够避免实例对象的重复创建,不仅可以减少每次创建对象的时间开销,还可以节约内存空间:能够避免由于操作多个实例导致 ...

  10. live555源码分析----RSTPServer创建过程分析

    最近五一回家,终于有机会能安静的看一下流媒体这方面相关的知识,准备分析live555的源码,接下来会把我读源码的过程记录成博客,以供其他的同路人参考. 因为再读源码的过程中,并不是一路顺着读下来,往往 ...