Problem Description
In this problem, we should solve an interesting game. At first, we have an integer n, then we begin to make some funny change. We sum up every digit of the n, then insert it to the tail of the number n, then let the new number be the interesting number n. repeat it for t times. When n=123 and t=3 then we can get 123->1236->123612->12361215.
Sample Input
35 2
35 1
-1 -1
 
Sample Output
Case #1: Yes
Case #2: No

对生成的数%11,余数与下次多增的部分结合,不停求余

(官方:用long long 写不好的会超时,是int的四倍  - -)

  1. #include <iostream>
  2. #include <cstdio>
  3.  
  4. using namespace std;
  5. typedef long long ll;
  6.  
  7. int f(int sum)
  8. {
  9. int i = 0;
  10. while(sum>0)
  11. {
  12. sum /= 10;
  13. i++;
  14. }
  15.  
  16. return i;
  17. }
  18.  
  19. int p(int num)
  20. {
  21. int i = f(num);
  22. int sum = 1;
  23. while(i--)
  24. {
  25. sum *= 10;
  26. }
  27.  
  28. return sum;
  29. }
  30.  
  31. int main()
  32. {
  33. int n, t, tt=1;
  34. while(scanf("%d%d", &n, &t))
  35. {
  36. if(n==-1&&t==-1) break;
  37.  
  38. int sum = 0;
  39. int div = 0;
  40. int temp;
  41. int temps;
  42.  
  43. temp = n;
  44. while(temp>0)
  45. {
  46. sum += (temp%10);
  47. temp /= 10;
  48. }
  49.  
  50. for(int i=0; i<t; i++)
  51. {
  52. div = n % 11;
  53.  
  54. n = div*p(sum) + sum;
  55.  
  56. temp = sum;
  57. temps = 0;
  58. while(temp>0)
  59. {
  60. temps += (temp%10);
  61. temp /= 10;
  62. }
  63. sum += temps;
  64.  
  65. }
  66. if(n%11==0) printf("Case #%d: Yes\n", tt++);
  67. else printf("Case #%d: No\n", tt++);
  68. }
  69.  
  70. return 0;
  71.  
  72. }

  

2015 多校联赛 ——HDU5373(模拟)的更多相关文章

  1. 2015 多校联赛 ——HDU5319(模拟)

    Painter Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Su ...

  2. 2015 多校联赛 ——HDU5402(模拟)

    For each test case, in the first line, you should print the maximum sum. In the next line you should ...

  3. 2015 多校联赛 ——HDU5334(构造)

    Virtual Participation Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Ot ...

  4. 2015 多校联赛 ——HDU5302(构造)

    Connect the Graph Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others ...

  5. 2015 多校联赛 ——HDU5294(最短路,最小切割)

    Tricks Device Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) To ...

  6. 2015 多校联赛 ——HDU5325(DFS)

    Crazy Bobo Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others) Tota ...

  7. 2015 多校联赛 ——HDU5316(线段树)

    Fantasy magicians usually gain their ability through one of three usual methods: possessing it as an ...

  8. 2015 多校联赛 ——HDU5323(搜索)

    Solve this interesting problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K ...

  9. 2015 多校联赛 ——HDU5301(技巧)

    Your current task is to make a ground plan for a residential building located in HZXJHS. So you must ...

随机推荐

  1. android数据库持久化框架, ormlite框架,

    前言 Android中内置了SQLite,但是对于数据库操作这块,非常的麻烦.其实可以试用第3方的数据库持久化框架对之进行结构上调整, 摆脱了访问数据库操作的细节,不用再去写复杂的SQL语句.虽然这样 ...

  2. verilog学习笔记(4)_有限状态机

    有限状态机: 有限状态机是由寄存器组和组合逻辑构成的硬件时序电路: - 其状态(即由寄存器组的1和0的组合状态所构成的有限个状态)只能在同一时钟跳变沿的情况下才能从一个状态转向另一个状态: - 究竟转 ...

  3. Python split()方法

    Python split()方法 描述 Python split()通过指定分隔符对字符串进行切片,如果参数num 有指定值,则仅分隔 num 个子字符串 语法 split()方法语法: str.sp ...

  4. css3动画 一行字鼠标触发 hover 从左到右颜色渐变

    偶然的机会发现的这个东东 这几天做公司的官网 老板突然说出了一个外国网站 我就顺手搜了 并没有发现他说的高科技 但是一个东西深深地吸引了我 就是我下面要说的动画  这个好像不能放视频 我就简单的描述一 ...

  5. C#中DBNull.Value和Null的用法和区别

    DBNull.Value,, 是适用于向数据库的表中插入空值.而 null,是指在程序中表示空引用. 或者对象为空.就是没有实例化. row[column]的值为DBNull.Value的话,至少说明 ...

  6. Python内置函数(14)——bytes

    英文文档: class bytes([source[, encoding[, errors]]]) Return a new "bytes" object, which is an ...

  7. SpringCloud的应用发布(四)顺序启动各个应用

    一.部署应用 二.启动应用(注意顺序) 三.观察效果 1.查看进程和日志 ps -ef | grep java tail -f AppYml.txt 2.验证功能

  8. javascript学习(2)修改html元素和提示对话框

    一.修改html元素 1.修改p元素 1.1.源代码 1.2.执行前 1.3.执行后 2.修改div元素的className 2.1.源代码 1.2.执行前 1.3.执行后 3.直接在当前位置输出内容 ...

  9. 【52ABP实战教程】0.1-- Devops如何用VSTS持续集成到Github仓库!

    工欲善其事,必先利其器.在开始正式的教程之前我们先来聊聊准备工作. 管理工具会VSTS. 代码管理会用GITHUB. 服务器会用Azure. 所有的东西都是利用现有服务.不会说自己从虚拟机开始玩.我们 ...

  10. RxJava系列7(最佳实践)

    RxJava系列1(简介) RxJava系列2(基本概念及使用介绍) RxJava系列3(转换操作符) RxJava系列4(过滤操作符) RxJava系列5(组合操作符) RxJava系列6(从微观角 ...