codeforces 471C MUH and House of Cards 数论
来源:互联网 发布:淘宝退货骗局给假地址 编辑:程序博客网 时间:2024/06/04 19:32
题目链接:cf 471C
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:
- The house consists of some non-zero number of floors.
- 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.
- 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.
The single line contains integer n (1 ≤ n ≤ 1012) — the number of cards.
Print the number of distinct heights that the houses made of exactly n cards can have.
13
1
6
0
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根火柴如上图一样搭建房屋的层数有多少种
不难发现,每一行的火柴减去边上的2根之后都是3的倍数,(n-2×k)%3==0时 构成了k层,k层最少需要(k-1)*k/2*3根火柴,循环找出可行k即可
/****************************************************** * File Name: c.cpp * Author: kojimai * Creater Time:2014年09月27日 星期六 00时03分32秒******************************************************/#include<cstdio>#include<cstring>#include<cmath>#include<algorithm>#include<iostream>using namespace std;int main(){long long n;cin>>n;long long ans=0;long long cnt=0;long long all;if(n%3==0){cnt = 3;n-=6;}else if(n%3==1){cnt = 2;n-=4;}else{cnt = 1;n -= 2;}while(n>=0){all=(cnt-1)*cnt/2;if(n/3<all)break;elseans++;n-=6;cnt+=3;}cout<<ans<<endl;return 0;}
- codeforces 471C MUH and House of Cards 数论
- CodeForces 471C - MUH and House of Cards(推导)
- CodeForces 471C MUH and House of Cards
- CodeForces 471C MUH and House of Cards
- CodeForces 471C MUH and House of Cards
- CodeForces 471C MUH and House of Cards
- CodeForces 471C MUH and House of Cards
- C. MUH and House of Cards(数论规律题)
- C. MUH and House of Cards(Codeforces Round #269)
- Codeforces 471C MUH and House of Cards【找规律+二分】
- Codeforces #269 (Div. 2)C. MUH and House of Cards(数学:通项公式)
- Codeforces Round #269 (Div. 2) C MUH and House of Cards 爆搜+剪枝
- CF 269C MUH and House of Cards
- C. MUH and House of Cards (题目类型很有特点,存一下以便学习)
- MUH and House of Card
- CodeForces 399C Cards (数论)
- CodeForces 471B MUH and Important Things
- Codeforces 471B MUH and Important Things
- C. MUH and House of Cards(Codeforces Round #269)
- 数组的指针特性
- DSP-BIOS使用入门
- 使用Tcl脚本分配FPGA管脚
- 几乎都不放过大米饭北京的风格能否夺冠发
- codeforces 471C MUH and House of Cards 数论
- Markdown中插入数学公式的方法
- 金庸武侠小说之我的见解
- 实例学习gcc+gdb+make
- 改变世界的17个等式
- 滤波器设计指标
- 数字信号处理中各种频率关系
- 学习FPGA的网站推荐
- 常见算法在实际项目中的应用