Logo Ray's Blog
  • Home
  • About
  • News
  • Publications
  • Education
  • More
    Experiences
  • Posts
  • Notes
  • Dark Theme
    Light Theme
Logo Inverted Logo
  • Posts
  • AI
    • Infrastructure
      • Guides On Choosing Deep Learning Server
    • LLM
      • Asksage
    • PyTorch
      • Learning PyTorch Part I
      • Pytorch Distributed Data Parallel With Model Parallel in an HPC Environment
  • Tools
    • NeoVim
    • An Intro to a CLI Password Management: Pass
    • Exercism Cli Shortcut
    • Random Docker/Podman tips
  • HPC
    • ALCF
      • Distributed Training
      • QWen2.5-VL
  • Linux
    • Manage Users in Linux
    • Setup Ubuntu 22.04
  • Embedded Systems
  • Programming
    • C++
      • C++ Enum Pattern
    • Competitive Programming
      • How to Learn Programming
      • Mistakes I Have Made
      • TopCoder
        • HoleCakeCuts topcoder SRM411 div2 level3
        • InfiniteSequence topcoder SRM413 div2 level3
        • StringsAndTabs topcoder SRM412 div2 level3
        • TeleportsNetwork topcoder SRM409 div2 level3
    • Design Patterns
      • Object-Oriented Analysis
      • Object-Oriented Design Principles
    • Python
      • Python Conditional Timeit Decorator
Hero Image
InfiniteSequence topcoder SRM413 div2 level3

Introduction If you have not tried to solve this problem by yourself, please do so. Otherwise, this post will make little sense to you. The statement of the problem is a recursion, $a_i = a_{[i/p]} + a_{[i/q]}$, $a_0 = 1$. $p, q$ are integers. The symbol $[\cdot]$ represents the floor. The question is to find the value of $a_n$ for any given $n$, $p$, and $q$. The constraints are that $ 0 \leq n \leq 10^{12} $ and $ 1 < p, q \leq 10^9 $.

    Saturday, April 1, 2017 | 5 minutes Read
    Hero Image
    StringsAndTabs topcoder SRM412 div2 level3

    Introduction If you have not tried to solve this problem by yourself, please do so. Otherwise, this post will make little sense to you. This problem has a very interesting background: translate a tablature (tab) from one string instrument to another, i.e. guitar to ukulele or balalaika and vise versa. Knowing the tab system definitely helps, but even if one has no background on tab, the explanation is very clear. 🎸 The solution is straightforward, but to write a bug-free code in a short period is challenging.

      Saturday, April 1, 2017 | 6 minutes Read
      Hero Image
      HoleCakeCuts topcoder SRM411 div2 level3

      Introduction If you have not tried to solve this problem by yourself, please do so. Otherwise, this post will make little sense to you. Given a square cake of size $L$ with a square hole of size $\ell < L $, and a set of vertical cuts, $vcut$, and horizontal cuts, $hcut$, how many pieces of cake in the end. A Solution using Logic Let $n= \vert vcut\vert$ and $m=\vert hcut\vert$, if the cake has no hole, the total number of pieces is $ s\equiv (m+1)\cdot (n+1)$. Now, let us see how the hole affects the result.

        Saturday, March 18, 2017 | 2 minutes Read
        Hero Image
        TeleportsNetwork topcoder SRM409 div2 level3

        Introduction If you have not tried to solve this problem by yourself, please do so. Otherwise, this post will make little sense to you. Solution to this problem is straightforward, which can be broke down into two parts: construct the graph; find the min-max inconvenience. Part-I: Graph Construction Let $G(V,E)$ be the graph, and we know the order of $G$ is $\vert V\vert = n$. Because each city, except the capital, is going to build one road, the total number of edges is $\vert E\vert = m = n-1$. The rule of building a road from a city $i$ can be restated as “find the closest city $j$, ${\arg\min}_{j\in V,\ j\neq i} d(i,j)$, such that $d(0,j) < d(0,i)$”, where $d(\cdot)$ is the Euclidean distance between two cities. If the situation is degenerate, use $x$ and $y$ coordinates to resolve it. This is done in the function of build_road().

          Wednesday, March 15, 2017 | 5 minutes Read
          Navigation
          • About
          • News
          • Publications
          • Education
          • Experiences
          Contact me:
          • yren@bnl.gov
          • yhren
          • Yihui (Ray) Ren

          Liability Notice: This blog is for informational and educational purposes only. The content provided here represents personal opinions and is not intended as professional advice. Readers should not rely solely on this information and are responsible for their own actions and decisions. This blog is not liable for any damages or consequences resulting from the use of its content. The views expressed here are my own and do not reflect those of my employer or any funding agencies. © 2017-2025 Yihui Ren. All rights reserved.


          Toha Theme Logo Toha
          © 2017-2025 Yihui Ren. All rights reserved.
          Powered by Hugo Logo