日本搞逼视频_黄色一级片免费在线观看_色99久久_性明星video另类hd_欧美77_综合在线视频

國內最全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 閱讀次數:2830次
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; }



生活不易,碼農辛苦
如果您覺得本網站對您的學習有所幫助,可以手機掃描二維碼進行捐贈
程序員人生
------分隔線----------------------------
分享到:
------分隔線----------------------------
關閉
程序員人生
主站蜘蛛池模板: 亚洲永久 | 国产又黄又爽又色的免费视频 | 999毛片| 欧美乱子伦 | 国产精品久久99 | 久久伊99综合婷婷久久伊 | 国产精品视频久久 | 日韩视频在线免费观看 | 九一精品| 中文字幕在线观看一区二区三区 | 国产中文视频 | 亚洲免费美女视频 | 久久久一区二区三区 | 久久三级视频 | 国产色区| 天天射天天搞 | 日本 欧美 在线 | 欧美精品www | 日本一区二区三区久久 | 久久免费精品视频 | 久久久久久影院 | 99视频在线播放 | 欧美一区二区三区视频在线 | 91久久久久久久久 | 国产偷久久一级精品60部 | 黄色av免费在线播放 | 国产高潮在线 | 欧洲一区 | 久久性色| 国产精品一区二区av | 午夜网址| 午夜精品一区二区三区在线视 | 国产高清中文字幕 | 成人黄色在线播放 | 毛片毛片毛片毛片毛片毛片毛片毛片毛片毛片 | 亚洲se主站 | 欧美国产精品一区二区 | 欧美日韩国产精品一区二区 | 久久99视频 | 久久精品99国产精品日本 | 免费精品视频 |