This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
https://community.topcoder.com/stat?c=problem_statement&pm=11204 | |
ํ๊ฒ๊ณผ ๋์ต์๊ฒ์ ํ๋์ ๋ฒกํฐ์ ๋ด์์ X๊ฐ์ผ๋ก ์ ๋ ฌํ์๋ | |
๋งจ์ผ์ชฝ์ด ํ๊ฒ์ด๊ฑฐ๋ ๋งจ์ค๋ฅธ์ชฝ์ด ๋์ต์๊ฒ์ด๋ฉด ๋ฌด์กฐ๊ฑด ๋ถ๊ฐ๋ฅํ๊ณ | |
๋ง์ฝ ์๋๋ผ๋ฉด, ํ๊ฐ์ง ์ฌ์ค์ ํ์ ํด์ผํ๋ค. ์๋์ ๋๊ฐ๋ฅผ ์ ์ธํ์๋ | |
๋ชจ๋ ํ ๋นต์ ๋งจ์ผ์ชฝ์์๋ ๋์ต์ ๋นต๊ณผ ๋งค์น์ํฌ์์๊ณ | |
๋ชจ๋ ๋์ต์ ๋นต์ ๋งจ ์ค๋ฅธ์ชฝ์ ์๋ ํ ๋นต๊ณผ ๋งค์น ์ํฌ์๊ฐ์์ผ๋ฏ๋ก ๋ต์ 2๋ณด๋ค ์ปค์ง์๊ฐ์๋ค. ๊ทธ๋ฐ๋ฐ ๋ฑ ํ ๊ฒฝ์ฐ์ ๋ต์ด 1์ด ๋๋ค. | |
๋ฐ๋ก ๋ชจ๋ ๋์ต์๋นต์ด ๋ชจ๋ ํ๋นต๋ณด๋ค ์ผ์ชฝ์ ์์ ๋ ์ด๋ค. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
https://community.topcoder.com/stat?c=problem_statement&pm=11233 | |
๊ทธ๋ฅ ์ฌ๊ทํจ์๋ก ๊ตฌํํ๋ฉด๋๋ค | |
์ธ์๋ก๋ ์ํ๋ฐ์ ์ฌ๋ถ์ ์๋ฐ์ ์ฌ๋ถ ๊ทธ๋ฆฌ๊ณ ๋จ์์๋ ์ผ์ชฝ๋๊ณผ ์ค๋ฅธ์ชฝ๋๋ง ๊ฐ์ง๊ณ ์์ผ๋ฉด๋๋ค | |
์๋ํ๋ฉด ๊ณต์ ๋นผ๋ ์ ๋์ผ๋ก๋ง ๋น ์ ธ๋๊ฐ๊ธฐ ๋๋ฌธ์ ๊ฐ์ด๋ฐ๋ ๊ทธ๋๋ก ๋จ์์๊ฒ ๋๊ธฐ๋๋ฌธ์ ์ข ํน์ ์ฐ๋ก ํ์นธ์ฉ๋ง ๋ณํ๊ฒ ๋๊ธฐ๋๋ฌธ์ด๋ค. | |
์๊ฐ ๋ณต์ก๋๋ O(N) ์ฆ 10๋ง๋ฒ์ ๋ ๋๋ค. | |
*/ | |
#include <bits/stdc++.h> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
https://community.topcoder.com/stat?c=problem_statement&pm=11334 | |
์ฒ์์ ์ํ๋ค์ ์ ์ ์ํ๋ค ๊ทธ๋ํ๋ฅผ ํ์ฑํด์ ๋ค์ต์คํธ๋ผ๋ฅผ ๋๋ฆฌ๋ ์์ผ๋ก ํ ์๊ฐ ์์ ๊ฑฐ๋ผ๊ณ ์๊ฐํ๋๋ฐ | |
์ฝ์ง์์๋ค. ์๋ง ์ง๊ธ๊น์ง ๊ทธ๋ ๊ฒ ํ์๋ ๋ฌธ์ ๋ค์ ๋ฌธ์ ์์ ์ฃผ์ด์ง ๊ฒฝ๋ก๋๋ก ์ด๋ํ๋ ๊ฒ์ด ์๋๋ผ | |
์ถ๋ฐ์ง์ ๋์ฐฉ์ง๋ง ์ฃผ์ด์ง๊ณ ์ถ๋ฐ์ง์์ ๋์ฐฉ์ง๋ก ์ด๋ํ๋ ๊ฐ์ฅ ์ ์ ๋น์ฉ์ ๋ฌป๋ ๋ฌธ์ ์๋๊ฒ๊ฐ๊ณ | |
์ด ๋ฌธ์ ๋ ๊ฒฝ๋ก๊ฐ ์ฃผ์ด์ง๊ณ ๋ฐ๋์ ๊ทธ ๊ฒฝ๋ก๋๋ก ์ด๋ํด์ผ ํ๋ฉด์ ํ์ ๋ ์์์ด ์กด์ฌํ ๋์ ์ต์ ๋น์ฉ์ ๊ตฌํ๋ ๋ฌธ์ ์ด๋ค. | |
๊ทธ๋์ ์ด ๋ฌธ์ ๋ network flow graph ๋ก ํ ์๊ฐ ์๊ณ ์ต์ ๋น์ฉ์ ์ฐพ์์ผ ํ๊ธฐ ๋๋ฌธ์ mcmf ๋ก ํ ์๊ฐ ์๋ค. | |
์ฐ์ ํ๊ฐ์ง ์ฌ์ค์ ๊นจ๋ฌ์์ผ ํ๋ค. ๊ฒฝ๋ก๊ฐ ์ฃผ์ด์ก์ผ๋ k๋ฒ์งธ ๋์๊ฐ ์ถ๋ฐ์ง์ผ๋ k+1๋ฒ์งธ ๋์๋ ๋์ฐฉ์ง๋ผ๊ณ ๋ณผ ์๊ฐ์๋ค. | |
๊ทธ๋ ๋ค๋ฉด ๋งจ์ฒ์ 0๋ฒ๋์์ ์๋ค๋ ๊ฒ์ ๊ณ ๋ คํ์๋ ์ ๋ ฅ์ผ๋ก ์ฃผ์ด์ง ๋์๋ค์ ๋ฐฐ์ด์ ํฌ๊ธฐ๊ฐ M ์ด๋ผ๋ฉด |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
https://community.topcoder.com/stat?c=problem_statement&pm=11063 | |
์ฐ์ Linearity of expectation ์ ์์์ผ ํ๋ค. | |
๊ทธ๋๊น ๊ฑด์คํ ๋๋ก๋ค์ ๊ธธ์ด์ ์ด ํฉ์ ๊ธฐ๋๊ฐ์ | |
๊ฐ๊ฐ์ ๋๋ก์ ๊ธธ์ด์ ๊ธฐ๋๊ฐ๋ค์ ์ด ํฉ๊ณผ ๊ฐ๋ค๋ผ๋ ๊ฒ์ด๋ค. | |
Editorial ์ ์๋ ์์ ์ธ์ฉํ์๋ฉด | |
Expected Length of all roads build after picking all villages = | |
Expected Length (Sum of lengths of the roads built when village i is picked, for all i) = |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
https://community.topcoder.com/stat?c=problem_statement&pm=11342 | |
์ฒ์์ ์ด ๋ฌธ์ ๊ฐ ํด์์ด ๋๋ฌด์๋ผ์ ๋ฐฉ์นํด ๋๋ค๊ฐ ๊ฒฐ๊ตญ ๋ ์ก๊ณ ์ค์ค๋ก ํ์๋ค. | |
ํ๋ฅ ์ ๋ํ ์ดํด์ ์จ๊ฒจ์ง ๊ท์น์ ๋ฐ๊ฒฌ์ด ์๊ตฌ๋๋ ๋ฌธ์ ๋ผ๊ณ ์๊ฐํ๋ค. | |
์ฐ์ ๊ฐ์ฅ ์ค์ํ ๊ท์น์ ๋ฐ๊ฒฌํด์ผํ๋๋ฐ | |
๋งจ ์ฒ์์ definite decisions ๋ฅผ ๋ฐํ์ผ๋ก ๋ค๋ฅธ์ฌ๋์๊ฒ ์ ํ๋ ์๋ฅผ ๊ฐ๊ฐ์ ์ฌ๋๋ง๋ค ์ธ์ด๋ณด๋ฉด | |
ํ ๋ช ์๊ฒ๋ ์ ํ๋์ง ์์ ์ฌ๋์ 0, ํ ๋ช ์๊ฒ ์ ํ๋ ์ฌ๋์ 1, ... ์ด๋ฐ์์ผ๋ก ๊ฐ๊ฒ๋๋๋ฐ | |
์ ํ๋ ํ์๊ฐ ๋ชจ๋ 0 ๋๋ 1์ด๋ผ๋ฉด ๋ค์๋ฒ round ์๋ ๋ชจ๋๊ฐ vulerable ํด์ง๋ค. ์๋ํ๋ฉด | |
definite decisions ์ ํฌํจ ๋์ง์์ ๋๋จธ์ง ์ฌ๋๋ค์ ๋ํด์๋ ํ์ฌ ๊ฐ์ฅ ์ ๊ฒ ๋ฝํ ์ฌ๋๋ค์ ๋๋คํ๊ฒ ๋ฝ๊ฒ๋๋๋ฐ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
https://community.topcoder.com/stat?c=problem_statement&pm=11315 | |
๋จ์ํ ๊ทธ๋ฆฌ๋+๊ตฌํ+์๋ฃ๊ตฌ์กฐ ๋ฌธ์ ์ด๋ค. | |
map ์ ์์ key ๊ฐ์ผ๋ก ๊ฐ์๋ฅผ ์ธ์ด์ค๋ค ๋๊ฐ์ด์์ด ์๋ ์์ด์์ผ๋ฉด ๋ฌด์กฐ๊ฑด | |
๋ง์ฃผ๋ณด๋ ๋ ๋ฉด์ ์ฐ๊ณ ๋ฒ๋ฆฌ๋๊ฒ ์ด๋์ด๋ค. | |
๊ทธ๋ฆฌ๊ณ ์๋ก ๋ค๋ฅธ ์๋ค์ ์๋ฌด๋ ๊ฒ๋ ๋ถ์ฌ๋ ๋๋ค. | |
*/ | |
#include <bits/stdc++.h> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
https://community.topcoder.com/stat?c=problem_statement&pm=11355 | |
์ผ๋จ ๋ช๊ฐ์ง๋ฅผ ์บ์นํด์ผํ๋ค. | |
์ฐ์ ๋งจ์์ค์ ๋ณํ์ง ์๋๋ค. | |
๊ทธ๋ฆฌ๊ณ ํน์ ์ค์ ๋ฌด์กฐ๊ฑด ๋ฐ๋ก ์์ค์ ์ํด ์ํฅ์ ๋ฐ๋๋ค. ์๋ํ๋ฉด ๋ฌธ์ ์์ ์ฃผ์ด์ง ์ฝ๋๋ฅผ ๋ณด๋ฉด ์์ ๋ฐ๊ฟ์ฃผ๋ ์์๋ฅผ ์์์๋๋ฐ | |
ํน์ ์ค์ ๋ณผ๋๋ ์ด๋ฏธ ์์ค์ด ๋ฐ๋ ์ํ์ด๊ธฐ ๋๋ฌธ์ ์ ๋ ฅ์ผ๋ก ์ฃผ์ด์ง๋ output์์์์ ๋ฐ๋ก์์ค๊ณผ ๊ฐ์์ํ์์ ์ํฅ์ ๋ฐ๋๊ฒ์ด๋ค. | |
๊ทธ๋ฆฌ๊ณ ๋์ ๋๊ฐ์ง๋ฅผ ์ ๋ฐ์ ธ์ค์ผํ๋ค. | |
์ฒซ๋ฒ์งธ๋ W์ B ๋๋ค ๊ฐ๋ฅํ ๊ณณ์ด ์๊ธฐ๋ ์กฐ๊ฑด๋ค | |
๋๋ฒ์งธ๋ ํน์ ์์น๊ฐ ๋ฌด์กฐ๊ฑด W๋ B์ค ํ๊ฐ์ง ์ฌ์ผํ๋ ์กฐ๊ฑด๋ค |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
์ฐ์ ๋ช๊ฐ์ง ๋ฐ๊ฒฌํด์ผ ํ๋ ๊ท์น๋ค์ ์์ ํ์ด์ ๊ฐ๊ณ ์กฐ๊ฑด๋ค์ ๋ํด ๋ชจ๋ ํจํด์ ๋ฐ์ ธ์ฃผ์ง ์์๋ ๋๋ ๊ตฌํ๋ ๊ฐ๋จํ๊ณ ๊น๋ํ ํ์ด๊ฐ ์๋ค. | |
๋ฐ๋๋ก ๋ค์์ ๋ถํฐ ๋ณด๋ ๊ฒ์ด๋ค. ์ ์ ๋ญ๊ฐ ์์์์ง ๋ชจ๋ฅด๋๊ฑด ? ๋ผ๋ ๋ณ๊ฐ์ ๋ฌธ์๋ฅผ ํ๋ ์ ํด์ ํ์๋ฅผ ํด์ฃผ๊ณ BB ์ผ๊ฒฝ์ฐ | |
์๋ ๋๊ฐ๋ฅผ ์ค์ ๋ก swap์ ํด์ฃผ๋ฉฐ WB ๋ BW ์ผ๊ฒฝ์ฐ๋ ๋๋ค ์๋ ๋๊ฐ๋ฅผ ??๋ก ๋ฐ๊ฟ์ฃผ๋ฉด ๋๋ค. WW์ผ๋ ๊ฐ๋งํ ๋๋ฉด๋๋ค. | |
๊ทธ๋ฆฌ๊ณ ๋ง์ง๋ง์ ?์ ๊ฐ์๋งํผ 2๋ฅผ ๊ณฑํด์ฃผ๋ฉด ๋๋ค. ๋ฌผ๋ก ์ค๊ฐ์ ๋ถ๊ฐ๋ฅํ ๊ฒฝ์ฐ๋ฅผ ๋ฐ์ ธ์ค์ผํ๋๋ฐ ์ด๊ฑด WB์ผ๋์ BW์ผ๋ ์๋์ ๊ฐ๊ฐ B๋ W๊ฐ | |
ํ๋๋ผ๋ ์์ผ๋ฉด ๋ถ๊ฐ๋ฅํ ๊ฒฝ์ฐ์ด๊ณ ๊ฐ๊ฐ W์ B๋ ์์ด๋๋๊ณ ?๋ ๋๋ค ์ธ์ ๋ ์ง ์์ด๋ ๋๋ค. | |
*/ | |
#include <bits/stdc++.h> | |
#define REP(i,a,b) for(int i=a;i<=b;++i) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
์ฐ์ 1x1x1 ํ๋ธ๋ค๊ณผ LxLxL ํ๋ธ๋ค์ ๋ถํผ์ ์ดํฉ์ ๊ตฌํด๋ณด๋ฉด | |
Ns+Nb*L^3 ์ธ๋ฐ ์ด๊ฒ์ T ๋ผ๊ณ ํด๋ณด์. ๊ทธ๋ผ ์ ์ด๋ ์ฐ๋ฆฌ๊ฐ ์ด ํ๋ธ๋ค์ ํฌ์ฅํ๋ ํ๋์ ํ๋ธ์ ๋ถํผ V๋ T๋ณด๋ค ํฌ๊ฑฐ๋ ๊ฐ๋ค. | |
๊ทธ๋ ๋ค๋ฉด T๋ณด๋ค ํฌ๊ฑฐ๋ ๊ฐ์ ๋ชจ๋ V์ ๋ํด ๊ฒ์ฌํด๋ณด์. ๊ทธ๋ฐ๋ฐ ์ฌ๊ธฐ์ ๋ฐ์ ธ์ค์ผ ํ ๊ฒ์ด ์ธ๊ฐ์ง๊ฐ ์๋ค. | |
์ฒซ๋ฒ์งธ๋ก ํ๋ธ์ ๋ชจ์๋ฆฌ์ ๊ธธ์ด๋ฅผ x,y,z ๋ผ๊ณ ํ ๋ x<=y<=z ๊ด๊ณ๋ฅผ ์ ์งํด์ค์ผ ์ ๋๊ฒ์ ๋ ์์ผ๋ค. ํ์ ํ๋ฉด ๊ฒฐ๊ตญ ๊ฐ์๊ฒ ๋์ค๊ธฐ๋๋ฌธ์ด๋ค. | |
(๊ทธ๋ ๊ธฐ ๋๋ฌธ์ x^3 <= 2e9 ์ผ ๊ฒ์ด๋ค) | |
๋๋ฒ์งธ๋ก ์ง๊ธ ๋ณด๋ V์ ๋ถํผ๊ฐ T๋ณด๋ค ํฌ๋ค ํ ์ง๋ผ๋ Nb๊ฐ์ ํ๋ธ๊ฐ ๋ชจ๋ ๋ค์ด๊ฐ ์ ์๋ ์ํฉ์ด ์๋ค. ์ด๊ฒ์ ๋ถ๋ฆฌ ํด์ฃผ๊ธฐ ์ํด์ | |
LxLxL ํ๋ธ๊ฐ ๋ค์ด๊ฐ ์ ์๋ ๊ฐ์๋ฅผ ์ธ์ด ์ค์ผํ๋๋ฐ ์ด๊ฒ์ (x/L)*(y/L)*(z/L) ์ด๋ค. ์ด๊ฒ์ด Nb๋ณด๋ค ํฌ๊ฑฐ๋ ๊ฐ์์ง๋ฅผ ๋ด์ฃผ๋ฉด๋๋ค. | |
์ธ๋ฒ์งธ๋ก x์ y๊ฐ ์ ํด์ง๋ฉด x*y*z๊ฐ T๋ณด๋ค ํฌ๊ฑฐ๋ ๊ฐ์์ผํ๊ธฐ๋๋ฌธ์ ์ต์ z๊ฐ ์ ํด์งํ ๋ฐ | |
์ด ์ต์z๋ถํฐ ๋ชจ๋ ๊ฐ๋ฅํ z๊ฐ์ ๋ค ๋ด์ฃผ์ง ์์๋ ๋๋ค๋ ๊ฒ์ด๋ค. ๋ฑ ์ด๊ฑฐ ํ๋๋ง ๋ด์ฃผ๋ฉด๋๋ค. ๊ทธ๋ ๊ธฐ ๋๋ฌธ์ ์๊ฐ๋ณต์ก๋๋ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
https://community.topcoder.com/stat?c=problem_statement&pm=11434 | |
์ด ๋ฌธ์ ๋ ์ํ์ ์ง์์ด ํ์ํ๋ค. ์ฐ์ ๋ฌธ์ ์์ ์นธ๋ค์ด K๊ฐ๊ฐ ์์ ๋ K์ ์ฝ์์ด๋ฉด์ ์์์ธ ์๋ก ๋๋ ์๊ฐ ์๋ค๊ณ ํ๋๋ฐ | |
์ด๊ฒ์ ๋ฐ๋ก ๋งค ํ์ ์์ธ์๋ก ํ๋ฒ ๋๋ ์ ์๋ค๋ ๊ฒ์ ์๋ฏธํ๋ค. ๊ทธ๋ ๊ธฐ ๋๋ฌธ์ ์์ธ์ ๋ถํด๋ฅผ ํ์ ๋ ์์ธ์๋ค์ ์ง์ ๋ค์ ๋ชจ๋ ๋ํ ๊ฐ์ด | |
์ต๋ํ์ผ๋ก ๋๋ ์ ์๋ ํ์์ธ ๊ฒ ์ด๋ค. ๊ทธ๋ ๋ค๋ฉด ์ฐ๋ฆฌ๊ฐ ํน์ ์นธ์ ๊ฐ์ ธ๊ฐ๊ธฐ ์ํ ์ต์ ํ์๊ฐ ์๋ค๊ณ ์น๋ฉด ๊ทธ ์ต์ ํด๋ | |
๋ช๋ฒ์ ๋๋๊ฒ์ด๊ณ ๋ช๋ฒ์ ์์ผ๋ก ์ด๋์ํฌ ๊ฒ์ด๋ค. ์ฐ์ ๋๋๋ ํ์๋ฅผ ๋จผ์ ๋ณด๋ฉด ๊ฐ๊ฐ์ ์์ธ์ ๋ง๋ค ๋๋๋ ํ์๊ฐ ์์ ๊ฑฐ๊ณ ๊ทธ ํ์๋ 0์ผ ์๋ ์์๊ฒ์ด๋ค. | |
๊ทธ๋ ๋ค๋ฉด ๊ฐ๊ฐ์ ์์ธ์์ ๋ํ์ฌ ๋๋๋ ํ์๋ค์ ๋ชจ๋ ์กฐํฉ์ ๋ํ ๊ฒฝ์ฐ๋ค์ ๋ชจ๋ ๋ณด๋ฉด์ | |
์ฐ๋ฆฌ๊ฐ ๊ณ ๋ฅด๋ ค๊ณ ํ๋ ๋์ด ๋งจ ์ผ์ชฝ ์นธ์ผ๋ก ๋ถํฐ ๋ช ๋งํผ ๋จ์ด์ ธ ์๋์ง ๋ด์ ๊ทธ์ค ์ต์ ๊ฐ์ด ๋ต์ด ๋ ๊ฒ์ด๋ค. | |
๋ฌผ๋ก ๋งจ ์ผ์ชฝ ์นธ์ผ๋ก ๋ถํฐ ๋จ์ด์ง ๊ฑฐ๋ฆฌ๋ min(์ข์ธก์ผ๋ก ๊ฐ์๋ ๊ฑฐ๋ฆฌ, ์ฐ์ธก์ผ๋ก ๊ฐ์๋ ๊ฑฐ๋ฆฌ) ์ผ ๊ฒ์ด๋ค. |
OlderNewer