多多色-多人伦交性欧美在线观看-多人伦精品一区二区三区视频-多色视频-免费黄色视屏网站-免费黄色在线

國內最全IT社區平臺 聯系我們 | 收藏本站
阿里云優惠2
您當前位置:首頁 > php開源 > C. MUH and House of Cards(Codeforces Round #269)

C. MUH and House of Cards(Codeforces Round #269)

來源:程序員人生   發布時間:2014-10-06 08:00:01 閱讀次數:2818次
C. MUH and House of Cards
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

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 usingexactly 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 test(s)
input
13
output
1
input
6
output
0
Note

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.


很容易發現,每層的牌數為3t+2,先對x=n%3,當x=1時,最少有兩個2,即最少有兩層,當x=2時,最少有一層,x=3時最少有兩層,剛好是x=3-x,現在假設有k層,最少為(3*0+2)+(3*1+2)+(3*2+2)+.......+(3*(k-1)+2<=n,整理得(k*(k+1)/2*3<=(n+k),然后再對層數加3,直到不滿足上面的條件。

代碼:

#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> using namespace std; int main() { long long n; scanf("%I64d",&n); long long x=n%3; x=3-x; long long cou=0; for(long long i=x;i*(i+1)/2*3<=(n+i);i=i+3) { cou++; } printf("%I64d ",cou); return 0; }



生活不易,碼農辛苦
如果您覺得本網站對您的學習有所幫助,可以手機掃描二維碼進行捐贈
程序員人生
------分隔線----------------------------
分享到:
------分隔線----------------------------
關閉
程序員人生
主站蜘蛛池模板: 亚洲乱搞| 欧美最爽乱淫视频播放黑人 | 亚洲国产欧美在线成人aaaa | 日本一级毛片视频无遮挡免费 | 亚洲国产欧美在线人成 | 欧美中日韩在线 | 国产亚洲福利一区二区免费看 | 日本高清免费网站 | 久久精品蜜芽亚洲国产a | 亚洲a级 | 亚洲欧美综合色区小说 | 性xxxx| 韩国jizz | 欧美视频在线观看爱爱 | 欧美xxxx另类 | 性欧美free高清video | 日本无套| 国产精品女人在线观看 | 亚洲精品成人一区二区aⅴ 亚洲精品成人在线 | 精品成人毛片一区二区视 | 日本一区精品久久久久影院 | 欧美成人精品一区二区 | 国产成人高清精品免费5388密 | 日韩精品一区二区三区乱码 | 高清在线观看视频 | 欧美国产精品一区二区免费 | 手机成人在线视频 | 欧美日本日韩aⅴ在线视频 欧美日本视频一区 | 亚洲美女福利 | 国内精自视频品线六区免费 | 亚洲国产精品成人综合久久久 | 在线免费激情视频 | 欧美一级永久免费毛片在线 | 在线高清视频18jin观看 | 午夜影院美女 | 性欧美高清久久久久久久 | 精品国产福利 | 亚洲欧美一区二区三区 | 国产一区二区三区久久精品小说 | 最近中文字幕高清免费大全8 | 中国毛片免费观看 |