楼上真的是签到题 ZZULIOJ - 2460 模拟

题解

假设单位秒内给酒杯倒的量为512 (512是因为一共10层每次分2个叉最多分9次 2的9次方足够)
最开始直接将T秒的酒量导入最上层杯子中 至于他为什么装得下不用考虑 反正这样不会影响结果
然后一层一层遍历杯子 如果杯子容量超过512将多出部分分给他下层的两个杯子分别是a[当前层+1][当前位置]和a[当前层+1][当前位置+1]模拟即可

AC代码

#include <stdio.h>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

const int INF = 0x3f3f3f3f;
const int MAXN = 20;
int a[MAXN][MAXN];

int main()
{
#ifdef LOCAL
	//freopen("C:/input.txt", "r", stdin);
#endif
	int N, T;
	while (cin >> N >> T)
	{
		memset(a, 0, sizeof(a));
		int base = 512, ans = 0;
		a[1][1] = base * T;
		for (int i = 1; i <= N; i++) //层
			for (int j = 1; j <= i; j++) //同层
			{
				if (a[i][j] > base)
				{
					a[i + 1][j] += (a[i][j] - base) / 2;
					a[i + 1][j + 1] += (a[i][j] - base) / 2;
					a[i][j] = base;
				}
				if (a[i][j] == base)
					ans++;
			}
		cout << ans << endl;
	}

	return 0;
}

猜你喜欢

转载自blog.csdn.net/CaprYang/article/details/85058472
今日推荐