Programming

[CF] Educational Round 87 (Rated for Div. 2) _ 201017

minigb 2021. 4. 13. 03:13

(2020년 10월 21일에 작성한 글입니다.)

 

 

Dashboard - Educational Codeforces Round 87 (Rated for Div. 2) - Codeforces

 

codeforces.com

코포 스터디에서 버추얼로 푼 라운드.

A.

문제를 꼼꼼히 잘 읽으면 풀린다.

근데 헷갈려서 시간 많이 걸렸다.

int main()
{
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int T;
	ll a, b, c, d;
	int i;

	cin >> T;
	while (T--)
	{
		cin >> a >> b >> c >> d;
		if (a <= b) {
			cout << b << '\n';
			continue;
		}
		if (c <= d) {
			cout << -1 << '\n';
			continue;
		}
		cout << b + c * ((a - b + (c - d - 1)) / (c - d)) << '\n';
	}

	return 0;
}

 

B.

i = 0부터 끝까지 돌면서

그때까지의 1, 2, 3의 가장 최근 인덱스를 저장해놓고

만약 1, 2, 3 모두 한 번이라도 등장했다면

(인덱스를 저장하는 배열을 처음에 -1로 초기화해놓고

idx값이 -1인 게 하나라도 있는지를 확인하였다)

1, 2, 3의 인덱스 중 가장 큰 것에서 가장 작은 것을 뺀 값 + 1

이게 substring의 길이다

int main()
{
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int T;
	string s;
	int ans;
	int i;

	cin >> T;
	while (T--)
	{
		cin >> s;
		ans = int_inf;
		vector<int> idx(3, -1);
		for (i = 0; s[i]; i++) {
			idx[s[i] - '1'] = i;
			if (idx[0] == -1 || idx[1] == -1 || idx[2] == -1) {
				continue;
			}
			ans = min(*max_element(idx.begin(), idx.end()) - *min_element(idx.begin(), idx.end()) + 1, ans);
		}
		if (ans == int_inf) {
			ans = 0;
		}
		cout << ans << '\n';
	}

	return 0;
}

C1.

각을 잘 계산해서 코드 작성하면 되는 문제

재미있었다.

int main()
{
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int T;
	double N;
	double degree;
	double ans;
	int cnt;
	bool costurn;
	int i;

	cin >> T;
	while (T--)
	{
		cin >> N;

		cnt = (int)N / 2 - 1;
		costurn = true;
		ans = 0;
		for (i = 1; i <= cnt; i++) {
			if (costurn) {
				degree = (i / 2 + 1)*(pi / N);
				ans += cos(degree);
				costurn = false;
			}
			else {
				ans += sin(degree);
				costurn = true;
			}
		}

		cout << fixed;
		cout.precision(10);
		cout << ans * 2 + 1 << '\n';
	}

	return 0;
}