CF1099A Snowball 题解

Content

有一个重量为 \(w\) 的雪球从高度为 \(h\) 的位置开始滚落,每秒它的高度会减少 \(1\),同时在高度为 \(i\) 的位置它的重量会增加 \(i\)。在雪球滚动的路线上还有两块石头,雪球在高度为 \(h_i\) 的位置碰到第 \(i\) 块石头,重量会减少 \(u_i\)。求到达高度为 \(0\) 的位置时雪球的最终重量。

数据范围:\(0\leqslant w,h,u_i\leqslant 100,0\leqslant h_i\leqslant h,h_1\neq h_2\)

Solution

数据范围这么小,为什么不直接模拟呢?从高度为 \(h\) 开始,每秒增加 \(h\),碰到一块石头就减少重量,但注意只能减到 \(0\),不能到负数,然后再 \(h\leftarrow h-1\)。最后直接输出即可。

Code

int w, h, u[3], a[3], vis[107];

int main() {
	getint(w), getint(h);
	_for(i, 1, 2) {getint(u[i]), getint(a[i]); vis[a[i]] = u[i];}
	while(h) {
		w += h, w = max(0, w - vis[h]);
		h--;
	}
	writeint(w);
	return 0;
}
posted @ 2021-12-17 14:33  Eason_AC  阅读(22)  评论(0)    收藏  举报