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\n", ans);
51      }
52
53     return 0;
54 }
时间: 2024-10-20 15:12:05

CQUOJ 10819 MUH and House of Cards的相关文章

CodeForces 471C MUH and House of Cards

看题目的Hint 图形就知道题意了,对着图形,稍微观察一下就会发现,每一层需要的卡牌数目为 2 * n + (n - 1)个,然后大致就有个思路,暴力枚举,但是仅仅这样没法子枚举,这个公式 只代表其中一层,不可能对每一层都枚举吧,可以化简一下  公式就是 3 * n - 1,这样就会发现 每次差1就是3的倍数了,然后每一层都差1,如果有i层的话,那么其实就是差了i,这样就很容易想到了,假设共有卡牌 x张,其实 就是枚举 i  ,有多少个i 使得  (x + i)%3 == 0,这样就简单了,但是

#269(div2) C. MUH and House of Cards

题意:给出N,问可以组装成不同的层. 思路:发现第一层的mod3=2,第二层的mod3=1,第三层的mod3=0,第四层的mod3=2......然后我们判断N是否足够建立该层最少的所需,第i层所需=3*n*(n-1)/2+2*n,for循环里的i也要开longlong ,不然超时,别问我为什么知道. 1 #include<bits/stdc++.h> 2 using namespace std; 3 typedef long long ll; 4 5 int main(){ 6 ll n;

大神刷题表

9月27日 后缀数组:[wikioi3160]最长公共子串 dp:NOIP2001统计单词个数 后缀自动机:[spoj1812]Longest Common Substring II [wikioi3160]最长公共子串 [spoj7258]Lexicographical Substring Search 扫描线+set:[poj2932]Coneology 扫描线+set+树上删边游戏:[FJOI2013]圆形游戏 结论:[bzoj3706][FJ2014集训]反色刷 最小环:[poj1734

Throwing cards away I

Throwing cards away I   Given is an ordered deck of n cards numbered 1 to n with card 1 at the top and card n at the bottom. The following operation is performed as long as there are at least two cards in the deck:  Throw away the top card and move t

UVa 10935 - Throwing cards away I

模拟队列操作.  注意当n == 1时第一行输出末尾没有空格.PE一次~~~ 代码  : import java.util.*; public class Main10935 { public static void main(String[] args) { Scanner scan = new Scanner(System.in); Queue<Integer> q = new LinkedList<Integer>(); while(true) { int n = scan.

D - MUH and Cube Walls

D. MUH and Cube Walls Polar bears Menshykov and Uslada from the zoo of St. Petersburg and elephant Horace from the zoo of Kiev got hold of lots of wooden cubes somewhere. They started making cube towers by placing the cubes one on top of the other. T

高橋君とカード / Tak and Cards

高橋君とカード / Tak and Cards Time limit : 2sec / Stack limit : 256MB / Memory limit : 256MB Score : 300 points Problem Statement Tak has N cards. On the i-th (1≤i≤N) card is written an integer xi. He is selecting one or more cards from these N cards, so t

练习题目 4 Little Elephant and Cards

Little Elephant and Cards Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Description The Little Elephant loves to play with color cards. He has n cards, each has exactly two colors (the color of the front side and the c

ZOJ 题目2734 Exchange Cards(DFS 去重OR 母函数)

Exchange Cards Time Limit: 2 Seconds      Memory Limit: 65536 KB As a basketball fan, Mike is also fond of collecting basketball player cards. But as a student, he can not always get the money to buy new cards, so sometimes he will exchange with his