跳到正文

算法·理论

T1 water题解

#SUSPENDED#约 2 分钟
原文
文章信息与版本

文章信息

收录
2025年12月12日
更新
2025年12月12日
篇幅
约 2 分钟
获赞
1

版本

  1. v1当前

大家好,这里是Yuexingfei。本次8月月赛题解由Yuexingfei和ycyxh1讲解;本篇是T1的讲解。

ycy小仓鼠敲可爱滴~awa

题目: 有一个试管,里面装有水。开始时,水的高度为10格,每过1秒,水就流走1格。 在某些时候,会有水从滴管上方落下,每滴水能让水高度升高2格。 问第几秒时,水能流完。

本题难度为入门,但通过人数仅1人,也许是我描述的太不清楚了。 本题为模拟,顺着题意写就好了。

AC CODE:

C++
#include <bits/stdc++.h>
#include <iostream>
#include <time.h>
#include <stdlib.h>
#include <cmath>
#include <cstdlib>
#include <cstdio>
#include <stdio.h>
#include <algorithm>
#include <string>
#include <string.h>
#include <math.h>

using namespace std;

int n, r = 10, a[10010] = {0};//初始化

int main() {
	scanf ("%d", &n);
	while (n--) {
		int x;
		scanf ("%d", &x);
		a[x]++;//利用桶排序的思想
	}
	//输入
	for (int i = 1; ; i++) {
		if (r == 0) {
			printf ("%d\n", i - 1);//到达结束要求时输出答案
			break;
		}
		for (int j = 1; j <= a[i]; j++) {
			r += 2;
		}
		r--;
		//模拟
	}
	return 0;
}
原文