Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

28-InSange #94

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open

28-InSange #94

wants to merge 4 commits into from

Conversation

InSange
Copy link
Collaborator

@InSange InSange commented Aug 20, 2024

πŸ”— 문제 링크

μ›”λ“œμ»΅

βœ”οΈ μ†Œμš”λœ μ‹œκ°„

ν•˜λ£¨

✨ μˆ˜λ„ μ½”λ“œ

문제 κ°œμš”

image
이미지에 λ‚˜μ™€ μžˆλ“―μ΄ 각 κ΅­ 끼리 μ„œλ‘œ κ²½κΈ°λ₯Ό ν•œ 번 μ”© μ§„ν–‰ν•˜μ˜€μ„ λ•Œ λ‚˜μ˜¬ 수 μžˆλŠ” 결과이면은 1을 좜λ ₯, κ²°κ³Όκ°€ λ‚˜μ˜¬ 수 μ—†λŠ” 경우의 수라면 0을 좜λ ₯ν•˜λΌ

풀이 μ ‘κ·Ό

되게 κ°„λ‹¨ν•˜κ²Œ ν’€ 수 μžˆμ„ 쀄 μ•Œμ•˜λ‹€.
ν•˜λ‚˜μ˜ λ‚˜λΌλ₯Ό μ§€μ •ν–ˆμ„ λ•Œ λ‚˜ 올 수 μžˆλŠ” 경기의 μˆ˜λŠ” 5번 μ΄λ―€λ‘œ 승리, λ¬΄μŠΉλΆ€, 패배λ₯Ό λ‹€ λ”ν–ˆμ„ λ•Œ 5κ°€ λ‚˜μ™€μ•Ό ν•œλ‹€!
그리고 μ „μ²΄μ˜ λ‚˜λΌλ₯Ό λΉ„κ΅ν–ˆμ„ λ•Œ 승의 κ°œμˆ˜λŠ” 패배의 κ°œμˆ˜μ™€ κ°™μ•„μ•Ό ν•˜λ©° 총 30번(6개ꡭ * 5번 κ²½κΈ°) 의 κ²½κΈ° 쀑에 승, 패λ₯Ό μ œμ™Έν•˜λ©΄ λ¬΄μŠΉλΆ€ 값이 λ‚˜μ˜€λ©° ν•΄λ‹Ή λ¬΄μŠΉλΆ€μ˜ 값이 0이 λ‚˜μ˜€λ©΄ 톡과! (drawκ°€ 0보닀 μž‘κ±°λ‚˜ 같을 λ•Œ μž…λ ₯ 받은 draw값을 더해주고 drawκ°€ 0보닀 클 λ•ŒλŠ” λΉΌμ£ΌλŠ” 방식)

정리λ₯Ό ν•˜λ©΄

  1. 승, λ¬΄μŠΉλΆ€, 패배λ₯Ό 더 ν–ˆμ„ λ•Œ 5κ°€ λ‚˜μ™€μ•Ό ν•œλ‹€.
  2. 승과 패배의 κ°œμˆ˜λŠ” κ°™μ•„μ•Ό ν•œλ‹€. 즉 승과 패배λ₯Ό 뺐을 λ•Œ 0이 λ‚˜μ™€μ•Ό 함
  3. λ¬΄μŠΉλΆ€ μ—­μ‹œ 0이 λ‚˜μ™€μ•Ό ν•œλ‹€. -> 0보닀 μž‘κ±°λ‚˜ 같을 λ•ŒλŠ” 더해주고 0보닀 클 λ•ŒλŠ” λΉΌμ£ΌλŠ” ν˜•μ‹
  4. 총 경기의 μˆ˜κ°€ 30이어야 ν•œλ‹€.
#include <iostream>
#include <vector>

using namespace std;

vector<vector<int>> play;
int win, draw, lose, a, b, c, t, playtime;
bool draw_flag, flag;

void Solve()
{
	play.assign(6, vector<int>(3, 0));
	t = 4;

	while (t--)
	{
		win = 0;
		draw = 0;
		lose = 0;
		playtime = 0;
		draw_flag = true;
		flag = true;

		for (int i = 0; i < 6; i++)
		{
			int sum = 0;
			for (int j = 0; j < 3; j++)
			{
				cin >> play[i][j];
				if (j == 0)
				{
					win += play[i][j];
				}
				else if (j == 1 && play[i][j])
				{
					draw += (draw_flag) ? play[i][j] : play[i][j] * (-1);
					draw_flag = (draw > 0) ? false : true;
				}
				else if(j==2)
				{
					lose += play[i][j];
				}
				playtime += play[i][j];
				sum += play[i][j];
			}
			if (sum != 5) flag = false;
		}
		if (!flag)
		{
			cout << 0 << " ";
			continue;
		}
		if (playtime != 30) cout << 0 << " ";
		else if (win != lose || draw) cout << 0 << " ";
		else if (win == lose && !draw && playtime == 30) cout << 1 << " ";

	}
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	Solve();

	return 0;
}

image
κ·Έλ ‡κ²Œ λ‚΄ κΏˆμ€ 11%μ—μ„œ 처참히 λ¬΄λ„ˆμ‘Œλ‹€...

이 방식이 ν‹€λ¦Όμ—†λŠ”λ°... 라고 μƒκ°ν•˜λ©° λ†“μΉ˜μ§€ μ•Šμ€ μ˜ˆμ™ΈλŠ” μ—†λŠ”μ§€ κ²€ν† λ₯Ό μ—¬λŸ¬λ²ˆ ν•˜λ©΄μ„œ κ²°κ΅­ λ‚˜λŠ” μ§€μ‹μΈμ˜ 찬슀λ₯Ό μ“°κ²Œ λ˜μ—ˆλ‹€.

image
λ¬΄μŠΉλΆ€κ°€ λ³€μˆ˜λΌκ³  ν•œλ‹€.
λ¬΄μŠΉλΆ€λŠ” μ˜ˆμ™Έ 쑰건 쀑 λͺ¨λ“  경우의 μˆ˜μ— 포함이 κ°€λŠ₯ν•˜κΈ° λ•Œλ¬Έμ—
κ²°κ΅­ μ™„μ „ νƒμƒ‰μœΌλ‘œ 이뀄져야 ν•œλ‹€.

0 ~ 5 번호의 총 6 개의 νŒ€μ΄ μžˆμ„ λ•Œ
0 - 1, 2, 3, 4, 5
1 - 2, 3, 4, 5
...
와 같이 λͺ¨λ“  νŒ€μ˜ κ²½κΈ°λ₯Ό νƒμƒ‰ν•˜λ©΄μ„œ 승, 패, λ¬΄μŠΉλΆ€λ₯Ό λΉ„κ΅ν•΄κ°€λ©΄μ„œ νƒμƒ‰ν•΄λ‚˜κ°€λŠ” 방식이닀.

#include <iostream>
#include <vector>

using namespace std;

vector<vector<int>> record;
int t;
bool draw_flag, flag;
vector<pair<int, int>> game = { {0, 1}, {0, 2}, {0, 3}, {0, 4}, {0, 5},
													 {1, 2}, {1, 3}, {1, 4}, {1, 5},
													 {2, 3}, {2, 4}, {2, 5},
													 {3, 4}, {3, 5},
													 {4, 5} };

bool CheckPlay(int round)
{
	if (round == 15)
	{
		for (int i = 0; i < 6; i++)
		{
			for (int j = 0; j < 3; j++)
			{
				if (record[i][j]) return false;
			}
		}
		return true;
	}

	int firstTeam, secondTeam;
	firstTeam = game[round].first;
	secondTeam = game[round].second;

	if (record[firstTeam][0] && record[secondTeam][2])	// first team win, second team lose
	{
		--record[firstTeam][0];
		--record[secondTeam][2];
		if (CheckPlay(round + 1)) return true;
		++record[firstTeam][0];
		++record[secondTeam][2];
	}

	if (record[firstTeam][1] && record[secondTeam][1])	// first team draw, second team draw
	{
		--record[firstTeam][1];
		--record[secondTeam][1];
		if (CheckPlay(round + 1)) return true;
		++record[firstTeam][1];
		++record[secondTeam][1];
	}

	if (record[firstTeam][2] && record[secondTeam][0])	// first team lose, second team win
	{
		--record[firstTeam][2];
		--record[secondTeam][0];
		if (CheckPlay(round + 1)) return true;
		++record[firstTeam][2];
		++record[secondTeam][0];
	}

	return false;
}

void Solve()
{
	record.assign(6, vector<int>(3, 0));
	t = 4;

	while (t--)
	{
		for (int i = 0; i < 6; i++)
		{
			for (int j = 0; j < 3; j++)
			{
				cin >> record[i][j];
			}
		}

		if (CheckPlay(0)) cout << 1 << " ";
		else cout << 0 << " ";
	}
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	Solve();

	return 0;
}

image

κ°„λ‹¨ν•˜κ²Œ μ ‘κ·Όν•  수 μžˆμ„ 쀄 μ•Œμ•˜μœΌλ‚˜ λ‹€ν–‰νžˆ 경기에 μ°Έμ—¬ν•˜λŠ” κ΅­κ°€μ˜ μˆ˜κ°€ 6개 λΏμΌλ”λŸ¬ λͺ¨λ“  μ‘°ν•©μ˜ μˆ˜κ°€ 15개 밖에 μ•ˆλ˜λ‹ˆ 3^15을 κ°μ•ˆν•˜λ”λΌλ„ μ‹œκ°„ λ‚΄λ‘œ 잘 μ°©λ₯™ν•  수 μžˆμ—ˆλ˜ 것 κ°™λ‹€.
κ·ΈλŸ¬λ‚˜ λ‹€μ‹œ ν’€λΌκ³ ν•˜λ©΄ 이런 방식이 λ– μ˜€λ₯Ό 것 κ°™μ§€λŠ” μ•Šμ„ 것 κ°™λ‹Ή..

πŸ“š μƒˆλ‘­κ²Œ μ•Œκ²Œλœ λ‚΄μš©

Copy link
Collaborator

@yuyu0830 yuyu0830 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

λ¬΄μŠΉλΆ€μ— μ˜ν•œ λ³€μˆ˜λ₯Ό μž‘κΈ°κ°€ νž˜λ“€κΈ°μ— μ™„μ „ 탐색을 ν•΄μ•Όν•˜κ³ , 쀑간쀑간 남은 승, λ¬΄μŠΉλΆ€, 패 의 κ°œμˆ˜κ°€ μ—†μœΌλ©΄ 더 이상 νƒμƒ‰ν•˜μ§€ μ•Šμ•„λ„ λ˜κΈ°μ— λ°±νŠΈλž˜ν‚ΉμœΌλ‘œ νƒμƒ‰ν•˜λŠ”κ΅°μš”..
저도 μ˜ˆμ „μ— ν’€λ‹€ μ‹€νŒ¨ν–ˆλ˜ 문제고, λΉ„μŠ·ν•˜κ²Œ μ ‘κ·Όν–ˆμ—ˆλ˜ 것 같은데 이런 μ‹μœΌλ‘œ μ™„μ „ 탐색을 ν•΄μ•Όν•˜λ„€μš” γ…Žγ…Ž.. λ­”κ°€ ν•œλ²ˆμ— ν™• ν•˜κ³  μ™€λ‹ΏλŠ” 풀이라기 λ³΄λ‹€λŠ” μ΄ν•΄ν•˜κ³  λ‚˜λ©΄ μ•„! ν•˜κ³  κ°νƒ„ν•˜λŠ” μž¬λ°ŒλŠ” ν’€μ΄μ˜€μŠ΅λ‹ˆλ‹€.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants