Created
November 19, 2017 13:11
-
-
Save wwiiiii/afc1f0f433f34cba209516c9992d43cc to your computer and use it in GitHub Desktop.
This file contains 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
#include <cstdio> | |
#include <queue> | |
#include <cmath> | |
#include <algorithm> | |
#include <vector> | |
using namespace std; | |
int depth(int a) | |
{ | |
int now = 3, res = 0, sum = 0; | |
while (sum < a) | |
{ | |
res++; | |
for (int i = 0; i < now; i++) sum++; | |
now *= 3; | |
} | |
return res; | |
} | |
int main() | |
{ | |
int hw = 100; | |
for (int i = 1; i <= 50; i++) { // i는 처음 쿠키의 개수 | |
priority_queue<pair<int, int> > pq; | |
for (int j = 1; j <= i; j++) { | |
pq.push({ -(hw - i), j }); | |
} | |
int cnt = 0; | |
while (!pq.empty()) // pq에는 (-남은경로의길이, 쿠키번호) 가 들어 있음 | |
{ | |
cnt++; | |
int move = depth(pq.size()); | |
vector<pair<int, int>> vec; | |
for (int k = 0; k < move; k++) { | |
auto now = pq.top(); pq.pop(); | |
now.first += 1; | |
if (now.first != 0) vec.push_back(now); | |
} | |
for (auto v : vec) pq.push(v); | |
} | |
printf("cookie %d : move %d\n", i, cnt); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment