【CodeForces - 471C】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:
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.
Examples
Input
13Output
1Input
6Output
0Note
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.
題目大意:
? ?現在有n個卡片,問能疊成多少種高度的房子。(疊法按照題意和圖片就看出來了)
解題報告:
? ? 直接枚舉,因為可以發現推出來的公式中是平方級別的,所以復雜度就是1e6左右,可以直接暴力。推公式是這么推的:先按照最少的方式看看可不可以疊出當前枚舉的層數,然后再看剩下的卡片數是否是3的倍數,如果是3的倍數那就直接都加在最下面一層就ok了,否則就是這一層做不到。
AC代碼:
#include<cstdio> #include<iostream> #include<algorithm> #include<queue> #include<map> #include<vector> #include<set> #include<string> #include<cmath> #include<cstring> #define ll long long #define pb push_back #define pm make_pair #define fi first #define se second using namespace std; const int MAX = 2e5 + 5; ll n; int main() {cin >> n;ll ans = 0;for (ll i = 1;; i++) {ll tmp = (i+1)*i/2 * 2;//房子 tmp += (i-1)*i/2;//天花板 if (tmp>n) break;if ((n-tmp)%3 == 0) ans++;}printf("%d\n",ans);return 0; }?
總結
以上是生活随笔為你收集整理的【CodeForces - 471C】MUH and House of Cards (思维,找规律)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 深圳今年GDP预计超2.8万亿,居亚洲城
- 下一篇: 暴雨黄色预警!14个省份有大到暴雨 可能