• CQUOJ 10819 MUH and House of Cards


    Polar bears Menshykov and Uslada from the zoo of St. Petersburg and elephant Horace from the zoo of Kiev decided to build a house of cards. For that they've already found a hefty deck of n playing cards. Let's describe the house they want to make:

    1. The house consists of some non-zero number of floors.
    2. Each floor consists of a non-zero number of rooms and the ceiling. A room is two cards that are leaned towards each other. The rooms are made in a row, each two adjoining rooms share a ceiling made by another card.
    3. Each floor besides for the lowest one should contain less rooms than the floor below.

    Please note that the house may end by the floor with more than one room, and in this case they also must be covered by the ceiling. Also, the number of rooms on the adjoining floors doesn't have to differ by one, the difference may be more.

    While bears are practicing to put cards, Horace tries to figure out how many floors their house should consist of. The height of the house is the number of floors in it. It is possible that you can make a lot of different houses of different heights out of n cards. It seems that the elephant cannot solve this problem and he asks you to count the number of the distinct heights of the houses that they can make using exactly n cards.

     

    Input

    The single line contains integer n (1 ≤ n ≤ 1012) — the number of cards.

     

    Output

    Print the number of distinct heights that the houses made of exactly n cards can have.

     

    Sample Input

    Input
    13
    Output
    1
    Input
    6
    Output
    0

    Hint

    In the first sample you can build only these two houses (remember, you must use all the cards):

    Thus, 13 cards are enough only for two floor houses, so the answer is 1.

    The six cards in the second sample are not enough to build any house.

     1 /*
     2 2016年4月24日14:55:30
     3 
     4 这道题目要看清啊  给n个卡牌, 求所能搭建的 不同楼层房子 的数 
     5 
     6 看题目的Hint 图形就知道题意了,
     7 对着图形观察一下就会发现, 
     8 (这个图形不是题目所给的那个图形,而是自己画的 第一层2个卡牌, 第二层5个卡牌 ....),
     9 第 n 层(从上往下)需要的卡牌数目为 2 * n + (n - 1)个,
    10 可以化简一下 公式就是 3 * n - 1,这样就会发现 
    11 
    12 每层所需卡牌的数差1就是3的倍数了,
    13 然后每一层都差1,如果有i层的话,那么其实就是差了i
    14 
    15 所以, 假设共有卡牌 x张,其实 就是枚举 i ,有多少个i 使得 (x + i)%3 == 0,
    16 ( 这里的意思是  如果 i 符合(x + i)% 3 == 0 , 
    17     则可以搭建 i 层的房子(因为每层楼的卡牌数都是差1 就是3的倍数 ) 
    18         再想想你就懂 )
    19 
    20 但是还有个限制的,因为 搭建i层 至少需要的牌数要知道,
    21 不能超过所给的卡牌数目x张, 
    22 由等差公式 (2 + (3*i-1)) * i / 2 = (3 * i + 1) * i / 2 可得
    23 搭建i层  至少需要 (3 * i + 1)* i/2张卡牌,这样 就很容易确定枚举范围了,
    24 而且 答案不大,所以直接枚举答案没事
    25 
    26 */
    27 
    28 # include <iostream>
    29 # include <cstdio>
    30 # include <cstring>
    31 # include <algorithm>
    32 # include <queue>
    33 # include <vector>
    34 # include <cmath>
    35 # define LL long long 
    36 # define INF 0x3f3f3f3f
    37 using namespace std;
    38 
    39 int main(void)
    40 {
    41      LL n, i, ans;
    42      while (~scanf("%I64d", &n)){
    43          ans = 0;
    44          for (i = 1; ; i++){
    45              if (n < (3 * i + 1)* i / 2)
    46                  break;
    47              if ((n + i) % 3 == 0)
    48                  ans++;
    49          }
    50          printf("%I64d
    ", ans);
    51      }
    52     
    53     return 0;    
    54 }
  • 相关阅读:
    我这里面所用的DBHelper
    同时向主表和从表里面导入execl数据 (asp.net webform)
    在asp.net webform中的 gridview 里面的一些基本操作
    在ASP.NET WEBFORM 中后台实现gridview全选功能
    asp.net webform 发送电子邮件
    Asp.Net中的三种分页方式
    asp.net获取客户端浏览器及主机信息
    在asp.net webfrom 中上传execl (读取单个sheet的数据)
    Linux五种IO模型性能分析
    epoll/poll/select的原理
  • 原文地址:https://www.cnblogs.com/hyq123456/p/5427664.html
Copyright © 2020-2023  润新知