CodeForces 471C - MUH and House of Cards(推导)

题意

给出n个木棒,问能叠成多少种不同高度的房子。

思路

  1. 算出某个高度最少所需木棒。

  2. 如果这个高度所需木棒小于当前木棒,判断能否正好用完。

对于第一个,可知从上往下分别是1个屋顶,两个屋顶......k个屋顶。这时候是最省的。

这时候所用木棒为(1 + k) * k / 2 * 2(这是屋顶所用的) + k * (k - 1) / 2(连接屋顶的小横杠) = (1 + k) * k / 2 * 3 - k

如何判断能否正好用完?

在完成最低限度的建房子之后,如果要加木棒,只能3根3根加。所以判断n-k能不能整除3即可。

代码

 
 
  1. #include <cstdio>
  2. #include <stack>
  3. #include <set>
  4. #include <iostream>
  5. #include <string>
  6. #include <vector>
  7. #include <queue>
  8. #include <functional>
  9. #include <cstring>
  10. #include <algorithm>
  11. #include <cctype>
  12. #include <ctime>
  13. #include <cstdlib>
  14. #include <fstream>
  15. #include <string>
  16. #include <sstream>
  17. #include <map>
  18. #include <cmath>
  19. #define LL long long
  20. #define lowbit(x) ((x) & (-x))
  21. #define MP(a, b) make_pair(a, b)
  22. #define MS(arr, num) memset(arr, num, sizeof(arr))
  23. #define PB push_back
  24. #define F first
  25. #define S second
  26. #define ROP freopen("input.txt", "r", stdin);
  27. const double PI = acos(-1.0);
  28. const int INF = 0x3f3f3f3f;
  29. using namespace std;
  30. const int MAXN = 2000 + 5;
  31. const int MOD = 20071027;
  32. typedef pair<int, int> pii;
  33. typedef vector<int>::iterator viti;
  34. typedef vector<pii>::iterator vitii;
  35. int main()
  36. {
  37. LL n, i, j;
  38. cin >> n;
  39. LL ans = 0;
  40. for (i = 1; ; i++)
  41. {
  42. LL temp = (((1 + i) * i) >> 1) * 3 - i;
  43. if (temp > n) break;
  44. if ((n - temp) % 3 == 0) ans++;
  45. }
  46. cout << ans << endl;
  47. return 0;
  48. }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值