Download 2020/round3/chain_explosions.cpp from hackercupai/hackercup: direct link, hf CLI and curl.
- Browser
- Download file 2.29 kB
-
https://huggingface.co/datasets/hackercupai/hackercup/resolve/b7e8aab1bcd10b3d874e66ead6527f208317a786/2020/round3/chain_explosions.cpp
- Command line
-
hf download hf://datasets/hackercupai/hackercup@b7e8aab1bcd10b3d874e66ead6527f208317a786/2020/round3/chain_explosions.cpp
-
curl -L -o chain_explosions.cpp https://huggingface.co/datasets/hackercupai/hackercup/resolve/b7e8aab1bcd10b3d874e66ead6527f208317a786/2020/round3/chain_explosions.cpp
2.29 kB
| // Chain Explosions | |
| // Solution by Jacob Plachta | |
| using namespace std; | |
| template<typename T> T Abs(T x) { return(x < 0 ? -x : x); } | |
| template<typename T> T Sqr(T x) { return(x * x); } | |
| string plural(string s) { return(Sz(s) && s[Sz(s) - 1] == 'x' ? s + "en" : s + "s"); } | |
| const int INF = (int)1e9; | |
| const LD EPS = 1e-12; | |
| const LD PI = acos(-1.0); | |
| bool Read(int& x) | |
| { | |
| char c, r = 0, n = 0; | |
| x = 0; | |
| for (;;) | |
| { | |
| c = GETCHAR(); | |
| if ((c < 0) && (!r)) | |
| return(0); | |
| if ((c == '-') && (!r)) | |
| n = 1; | |
| else | |
| if ((c >= '0') && (c <= '9')) | |
| x = x * 10 + c - '0', r = 1; | |
| else | |
| if (r) | |
| break; | |
| } | |
| if (n) | |
| x = -x; | |
| return(1); | |
| } | |
| void ProcessCase() | |
| { | |
| // input | |
| int K; | |
| Read(K), K /= 2; | |
| // construct graph | |
| int N = 2; | |
| vector<PR> E = { { 1, 2 } }; | |
| while (K) | |
| { | |
| int r = N, d = 1; | |
| while (d <= K) | |
| E.pb({ r, ++N }), K -= d++; | |
| } | |
| // output | |
| printf("%d %d\n", N, Sz(E)); | |
| for (auto e : E) | |
| printf("%d %d\n", e.x, e.y); | |
| } | |
| int main() | |
| { | |
| int T, t; | |
| Read(T); | |
| Fox1(t, T) | |
| { | |
| printf("Case #%d: ", t); | |
| ProcessCase(); | |
| } | |
| return(0); | |
| } |