Codeforces #639 div2 B

本文解析了Codeforces上编号为639div2B的题目,详细介绍了如何使用算法来确定在给定数量的卡片下可以构建多少个金字塔。通过不断消耗卡片构建最高可能的金字塔,直至无法再构建为止,最终输出构建的金字塔总数。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Codeforces #639 div2 B

原题

连接在这
A card pyramid of height 1 is constructed by resting two cards against each other. For h>1, a card pyramid of height h is constructed by placing a card pyramid of height h−1 onto a base. A base consists of h pyramids of height 1, and h−1 cards on top. For example, card pyramids of heights 1, 2, and 3 look as follows:

You start with n cards and build the tallest pyramid that you can. If there are some cards remaining, you build the tallest pyramid possible with the remaining cards. You repeat this process until it is impossible to build another pyramid. In the end, how many pyramids will you have constructed?

Input
Each test consists of multiple test cases. The first line contains a single integer t (1≤t≤1000) — the number of test cases. Next t lines contain descriptions of test cases.

Each test case contains a single integer n (1≤n≤109) — the number of cards.

It is guaranteed that the sum of n over all test cases does not exceed 109.

Output
For each test case output a single integer — the number of pyramids you will have constructed in the end.

ACcodes

#include <bits/stdc++.h>
using namespace std;
const int N = 1e5;
int test = 1;
int n,a[N];

int main()
{
	scanf("%d",&test);
	while(test--)
	{
		cin >> n;
		int ans = 0;
		while(n>=2){
			int q = 1;
			while((3*q*q+q)/2<=n)
				q++;
			n-=(3*(q-1)*(q-1) + q -1)/2;
			ans++;
		}
		cout << ans << endl;
	}
	return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值