Codeforces Round #269 (Div. 2) C 递推+打表
来源:互联网 发布:最新全国省份数据库 编辑:程序博客网 时间:2024/06/02 10:03
链接:戳这里
C. MUH and House of Cards
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard 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: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 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
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.
题意:
给出n根长度一样的木棍,去堆房子。问能堆出多少种不同高度房子
堆的过程如上图
思路:
发现堆每一层最少需要的木棍数能打表搞出来。
然后找出多少对(x,y)满足2*x+3*y=n,这里还需要满足一个条件 : (x-1)*x/2<=y
代码:
#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<string>#include<vector>#include <ctime>#include<queue>#include<set>#include<map>#include<stack>#include<iomanip>#include<cmath>#include<bitset>#define mst(ss,b) memset((ss),(b),sizeof(ss))///#pragma comment(linker, "/STACK:102400000,102400000")typedef long long ll;#define INF (1ll<<60)-1#define Max 1000000000000using namespace std;ll n;ll f[2000100];int main(){ f[1]=2; ll cnt=5; int num=0; for(int i=2;f[i-1]<=Max;i++) { f[i]=f[i-1]+cnt; cnt+=3LL; num=i; } ///cout<<f[num]<<endl; scanf("%I64d",&n); int ans=0; for(int i=1;i<=num;i++){ if(n>=f[i]){ if((n-2LL*i)%3LL==0){ ans++; } } else break; } cout<<ans<<endl; return 0;}
0 0
- Codeforces Round #269 (Div. 2) C 递推+打表
- Codeforces Round #335 (Div. 2) (C 思维题(递推,贪心))
- Codeforces Round #382 (Div. 2) C. Tennis Championship 递推、斐波拉契数列
- Codeforces Round #382 (Div. 2)C. Tennis Championship(递推,斐波那契)
- Codeforces Round #382 (Div. 2)-735C. Tennis Championship(递推)
- Codeforces Round #315 (Div. 2) C. Primes or Palindromes? (素数打表 回文数)
- Codeforces Round #315 (Div. 2) C. Primes or Palindromes? (打表枚举)
- Codeforces Round #315 (Div. 2) C - Primes or Palindromes?(暴力打表)
- Codeforces Round #355 (Div. 2) C. Vanya and Label (打表+字符串)
- Codeforces Round #401 (Div. 2) C Alyona and Spreadsheet —— 打表
- Codeforces Round #240 (Div. 2)(D:dp递推)
- Codeforces Round #346 (Div. 2) G 递推
- Codeforces Round #325 (Div. 2) B 递推
- Codeforces Round #271 (Div. 2) D 递推
- Codeforces Round #277 (Div. 2)(A)模拟,打表
- Codeforces Round #383 (Div. 2) B(打表)
- Codeforces Round #269 (Div. 2) C
- Codeforces Round #269 (Div. 2) C
- 安卓速记3----网络编程JSON解析与XML解析
- 【中间件】消息队列(一):RabbitMQ、ActiveMQ、Kafka和Redis
- GlassFish部署应用总结
- iOS学习笔记16—@synthesize obj=_obj的意义详解 @property和@synthesize
- 遍历文件夹
- Codeforces Round #269 (Div. 2) C 递推+打表
- 这几天学习到的Java设计模式
- mysql5.7.14 windows主从配置简记
- 如何用好 Google 等搜索引擎?
- 关于初次搭建环境第一次运行react-native run-android命令报错问题
- Java编程题目-6:二分法搜索
- C语言str函数系列
- mysql
- ios中NSUserDefaults的用法