APCS 考古題:小群體

題目

https://apcs.csie.ntnu.edu.tw/wp-content/uploads/2018/12/1060304APCSImplementation.pdf

解題思路

把data內的元素從某不為-1的data[idx]開始跑,跑到就把該元素改成-1,跑到有標-1(開始的那個)為止
回傳有幾個被marked

Code

main function

def mark(data,idx):
    count=0
    while(data[idx]!=-1):
        tmp=data[idx]
        data[idx]=-1 #mark
        idx=tmp #跑到好友編號,重複迴圈
        count+=1 #計算有幾個被標記
    return count

complete code

def mark(data,idx):
    count=0
    while(data[idx]!=-1):
        tmp=data[idx]
        data[idx]=-1 #mark
        idx=tmp #跑到好友編號,重複迴圈
        count+=1 #計算有幾個被標記
    return count
n=int(input())
data=list(map(int,input().split()))
marked=0
total=0 #群體總數
for i in range(n):
    if data[i]!=-1:
        marked+=mark(data,i)
        total+=1
    if marked==n:
        break #如果提早標記完就結束for迴圈
print(total)
Hugo 疑難雜症

POST SCSS failed:

  1. 到「沒空白」的資料夾下面(像 Natalie Lin 名字中間有空格就不行)
  2. 安裝本土npm, 不能是global
  3. 看README有沒有要求要複製 package.jsonnpm postcss 之類的或其他東西

網址/404 not found:

確定有沒有貼成repo的網址:(

有git submodule

怎麼看:
git clone 之後cd進去裡面會顯示(main)或(master)
解決方式:
直接Download Zip不要用clone

連結到<username.github.io/img>而不是<username.github.io/repo/img>

怎麼看:
Go to files 之後檢查 public裡面的網址
可以解決的方式:
😀在全域config.toml加上canonifyURLs = "true"
😐在path url前加 /repo (repo要換成專案名稱)
😥丟到主頁(username.github.io)下面

有功能不會動(這次是search function)

解方同上

“TOCSS … this feature is not available in your current Hugo version”

解決方式:
On the release page, look for archives with extended in the name.
如何確認是否安裝:
run hugo version and look for the word extended.

加入categories 頁面失敗

問題
解決方式:
第10行改成 {{range .Data.Pages}}

Hello World

Welcome to Hexo! This is your very first post. Check documentation for more info. If you get any problems when using Hexo, you can find the answer in troubleshooting or you can ask me on GitHub.

Quick Start

Create a new post

$ hexo new "My New Post"

More info: Writing

Run server

$ hexo server

More info: Server

Generate static files

$ hexo generate

More info: Generating

Deploy to remote sites

$ hexo deploy

More info: Deployment