zoukankan      html  css  js  c++  java
  • CodeForces 471C MUH and House of Cards

    MUH and House of Cards
    Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u

    Description

    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 usingexactlyn 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 #include <stdio.h>
     2 
     3 int main()
     4 {
     5     long long n,num;
     6     long long i,j;
     7     while(scanf("%I64d",&n)!=EOF)
     8     {
     9         num=0;
    10         for(i=0;;i++)
    11         {
    12             long long x=(2*(i+1)*(i+2))/2+(i*(i+1))/2,y;
    13             //printf("%I64d
    ",x);
    14             if(n>=x)
    15                 y=n-x;
    16             else
    17                 break;
    18             if(y%3==0)
    19                 num++;
    20         }
    21         printf("%I64d
    ",num);
    22     }
    23     return 0;
    24 }
    View Code
  • 相关阅读:
    http://download.microsoft.com/download/A/9/1/A91D6B2BA79847DF9C7EA97854B7DD18/VC.iso
    你的公积金账户在易才,请联系: 地址:武汉市汉口解放大道686号武汉世界贸易大厦49层612 客服电话:85362651 联系人:刘思明
    22
    http://www.cnblogs.com/uniqueliu/archive/2011/08/03/2126545.html
    多层的一个框 架
    MS Jet SQL for Access 2000中级篇
    窗体间传递复杂数据
    小议数据库主键选取策略(转)
    eWebSoft在线编辑器实例说明
    一个程序详细研究DataReader(转)
  • 原文地址:https://www.cnblogs.com/cyd308/p/4771547.html
Copyright © 2011-2022 走看看