PE 112 Bouncy numbers (模拟)

亦凉 2022-07-13 06:00 240阅读 0赞

Bouncy numbers

Problem 112

Working from left-to-right if no digit is exceeded by the digit to its left it is called an increasing number; for example, 134468.

Similarly if no digit is exceeded by the digit to its right it is called a decreasing number; for example, 66420.

We shall call a positive integer that is neither increasing nor decreasing a “bouncy” number; for example, 155349.

Clearly there cannot be any bouncy numbers below one-hundred, but just over half of the numbers below one-thousand (525) are bouncy. In fact, the least number for which the proportion of bouncy numbers first reaches 50% is 538.

Surprisingly, bouncy numbers become more and more common and by the time we reach 21780 the proportion of bouncy numbers is equal to 90%.

Find the least number for which the proportion of bouncy numbers is exactly 99%.

题意:额…自己看…

题解:额……手动模拟一遍就可以了….

代码:

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. typedef long long ll;
  4. typedef long double ld;
  5. int increase(ll x)
  6. {
  7. int p=x%10;
  8. x/=10;
  9. while(x>0)
  10. {
  11. int c=x%10;
  12. if(c>p)return 0;
  13. p=c;
  14. x/=10;
  15. }
  16. return 1;
  17. }
  18. int decrease(ll x)
  19. {
  20. int p=x%10;
  21. x/=10;
  22. while(x>0)
  23. {
  24. int c=x%10;
  25. if(c<p)return 0;
  26. p=c;
  27. x/=10;
  28. }
  29. return 1;
  30. }
  31. int gao(ll x)
  32. {
  33. if(increase(x) || decrease(x))return 0;
  34. else return 1;
  35. }
  36. int main()
  37. {
  38. ld s=0;
  39. for(int i=100;i<=10000000;i++)
  40. {
  41. if(gao(i)) s++;
  42. if(gao(i) && (s/i)*100.0==99)
  43. {
  44. cout<<i<<endl;
  45. }
  46. }
  47. return 0;
  48. }

发表评论

表情:
评论列表 (有 0 条评论,240人围观)

还没有评论,来说两句吧...

相关阅读

    相关 PE1-什么是pe

    PE是什么? PE即 Portable Executable(可移植的执行体)。它是 Win32环境自身所带的执行体文件格式。它的一些特性继承自 Unix的 Coff 文

    相关 LeetCode 112

    问题描述: 给定一个二叉树和一个目标和,判断该树中是否存在根节点到叶子节点的路径,这条路径上所有节点值相加等于目标和。 说明: 叶子节点是指没有子节点的节点。 示例: