【Codeforces】920A Water The Garden(浇花)

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/CSDN___CSDN/article/details/88075701

http://codeforces.com/problemset/problem/920/A

给你花坛的数目,花坛都是连续的,某一些花坛里有水龙头,给出了这些有水龙头的位置

The garden from test 1. White colour denotes a garden bed without a tap, red colour — a garden bed with a tap.

一开始的红色区域,需要1s的时间变成蓝色,之后每向左右扩展一格,也需要1s时间

直接模拟也可以的吧,但是判断的太多

先考虑a[1](第一个最左边的有水龙头的花坛)到1号花坛的的位置,以及a[n](最右边的有水龙头的位置)到n号花坛的距离

然后再看中间a[i]和a[i-1]的之间有几个花坛,有奇数个的话,t=t/2+1,偶数的话,就是t=t/2(自己想想就通了)。

#include <iostream>
#include <algorithm>

using namespace std;

int a[205];

int main ()
{
	int i,n,k,t;
	cin >> t;
	while(t--)
	{
		cin >> n >> k;
		for(i=1;i<=k;i++)
		{
			cin >> a[i];
		}
		int ans=max(a[1]-1,n-a[k]);
		for(i=2;i<=k;i++)
		{
			int t = a[i]-a[i-1]-1;
			if(t&1)
			{
				t = t/2+1;
			}
			else
			{
				t/=2;
			}
			ans = max(t,ans);
		}
		cout << ans+1 << endl;
	}
	return 0;
}

猜你喜欢

转载自blog.csdn.net/CSDN___CSDN/article/details/88075701