Educational Codeforces Round 90 (Rated for Div. 2)

A. Donut Shops

AC代码:

int n, m, k;
int ans1, ans2;
int main()
{
	int t;
	sd(t);
	while (t--)
	{
		ll a, b, c;
		slddd(a, b, c);
		if (a >= c)
			ans1 = -1;
		else
			ans1 = 1;
		if (a * b <= c)
			ans2 = -1;
		else
			ans2 = b;
		pdd(ans1, ans2);
	}
	return 0;
}

B. 01 Game

AC代码:

const int N = 5e6 + 50;
int n, m, k;
 
int main()
{
	int t;
	sd(t);
	while (t--)
	{
		string s;
		cin >> s;
		int len = s.size();
		int one = 0, zero = 0;
		rep(i, 0, len - 1)
		{
			if (s[i] == '0')
				zero++;
			else
				one++;
		}
		int minn = min(one, zero);
		if (minn & 1)
			puts("DA");
		else
			puts("NET");
	}
	return 0;
}

C. Pluses and Minuses

AC代码:

const int N = 1e6 + 50;
int n, m, k;
int a[N];
int main()
{
	int t;
	sd(t);
	while (t--)
	{
		string s;
		cin >> s;
		int len = s.size();
		a[0] = 0;
		rep(i, 0, len - 1)
		{
			if (s[i] == '+')
				a[i + 1] = a[i] + 1;
			else
				a[i + 1] = a[i] - 1;
		}
		ll ans = 0, cnt = 0;
		rep(i, 1, len)
		{
			while (cnt + a[i] < 0)
			{
				cnt++;
				ans += i;
			}
		}
		ans += len;
		pld(ans);
	}
	return 0;
}

D. Maximum Sum on Even Positions

AC代码:

const int N = 1e6 + 50;
int n, m, k;
int a[N];
int main()
{
	int t;
	sd(t);
	while (t--)
	{
		sd(n);
		ll ans = 0;
		rep(i, 1, n)
		{
			sd(a[i]);
			if (i % 2 == 1)
				ans += a[i];
		}
		ll sum1 = 0;
		ll ans1 = 0;
		for (int i = 1; i < n; i += 2)
		{
			int val = a[i + 1] - a[i];
			sum1 += val;
			sum1 = max(0LL, sum1);
			ans1 = max(ans1, sum1);
		}
		ll sum2 = 0;
		ll ans2 = 0;
		for (int i = 2; i < n; i += 2)
		{
			int val = a[i] - a[i + 1];
			sum2 += val;
			sum2 = max(0LL, sum2);
			ans2 = max(ans2, sum2);
		}
		ans1 = max(ans1, ans2);
		pld(ans + ans1);
	}
	return 0;
}

你可能感兴趣的:(CodeForces)