Codeforces 🔵 CF83B. Doctor
題目的難度顏色使用 Luogu 上的分級,由簡單到困難分別為 🔴🟠🟡🟢🔵🟣⚫。
🔗 CF83B. Doctor
tags: 二分搜尋(Binary Search)
模擬(Simulation)
題意
有 個編號 到 的對象排成一列,每個對象需要被處理 次。
每次操作時,處理隊伍最前面的對象一次:
如果這個對象還沒被處理完(次數未達 ),就會回到隊伍最後面。
如果已經處理滿 次,就離開隊伍。
總共會進行 次操作。請輸出第 次操作結束後,隊伍中剩下的對象編號,按照順序輸出。
如果在第 次操作之前,所有對象都已經離開隊伍,輸出 -1。
約束條件
思路:二分搜尋
本題的目標是,在操作 次後,確定隊伍中剩餘對象的順序。由於 可能高達 ,若逐次模擬每次看診,效率極低。因此需要優化,可以從總共循環了幾輪來思考。
假設進行了完整的 輪,也就是每隻對象最多被處理 次。對於第 個對象,實際處理次數為 ,其中 是該對象的需求次數。因此,完成 輪後的總處理次數為:
我們希望找到最大的 ,使得總次數不超過 ,即滿足 ,這可以用二分搜尋來找到。
確定此最大 後,剩餘的操作次數(未完成的處理)最多只會少於一整輪,也就是少於 次,可以直接模擬即可。
複雜度分析
- 時間複雜度:
- 空間複雜度:
1 | from collections import deque |
寫在最後
PROMPT
masterpiece, best quality, high quality, highres, extremely detailed CG unity 8k wallpaper, extremely detailed, High Detail, vibrant colors, anime style, cover art,
1girl, solo, Koyori, Hakui Koyori, Hakui Koyori (hololive), pink hair, long hair, braids in hair, purple eyes, fox ears, fox tail, black choker, white short-sleeved blouse, pink bow, pink trim on blouse, pink and purple plaid pleated skirt, white thigh garter on left leg, white knee-high socks, lace-trimmed socks, brown loafers,
reaching up to touch cherry blossoms, sitting on stone wall, spring season, cherry blossom trees in full bloom, soft dreamy lighting, urban background with buildings, gentle breeze, sakura petals falling, peaceful atmosphere, outdoors, clear spring day, looking up with wonder
In this enchanting spring scene, Hakui Koyori sits gracefully on a stone wall beneath a canopy of blooming cherry trees. The soft pink petals create a dreamlike atmosphere around her as she reaches up with one hand to gently touch the blossoms. Her expression captures a moment of serene wonder as she gazes upward at the beautiful sakura, with delicate petals occasionally drifting down in the gentle spring breeze.
新系列?