0%

緣起

在製作被審資料的時候字體遺失,結果我用Mac內建的 蘋方 ,因此趕快去找有沒有轉出字體的方法

安裝

Clone 一下 Adobe Font SDK

git clone https://github.com/adobe-type-tools/afdko
cd afdko

安裝他

python3 -m venv afdko_env
source afdko_env/bin/activate
pip3 install afdko

開始解壓縮 (file 改檔案名稱)

otc2otf <file>

轉換成Windows-capiticy

ttx -t cmap PingFangTC-Ultralight.otf
sed -i '' 's/platformID="0" platEncID="3"/platformID="3" platEncID="1"/g' PingFangTC-Ultralight.ttx
sed -i '' 's/platformID="0" platEncID="4"/platformID="3" platEncID="10"/g' PingFangTC-Ultralight.ttx
ttx -b -m PingFangTC-Ultralight.otf PingFangTC-Ultralight.ttx

重複幾次就好

如果以PingFang來說,可以直接用下面這段程式碼

# PingFangHK
ttx -t cmap PingFangHK-Light.otf
sed -i '' 's/platformID="0" platEncID="3"/platformID="3" platEncID="1"/g' PingFangHK-Light.ttx
sed -i '' 's/platformID="0" platEncID="4"/platformID="3" platEncID="10"/g' PingFangHK-Light.ttx
ttx -b -m PingFangHK-Light.otf PingFangHK-Light.ttx

ttx -t cmap PingFangHK-Medium.otf
sed -i '' 's/platformID="0" platEncID="3"/platformID="3" platEncID="1"/g' PingFangHK-Medium.ttx
sed -i '' 's/platformID="0" platEncID="4"/platformID="3" platEncID="10"/g' PingFangHK-Medium.ttx
ttx -b -m PingFangHK-Medium.otf PingFangHK-Medium.ttx

ttx -t cmap PingFangHK-Regular.otf
sed -i '' 's/platformID="0" platEncID="3"/platformID="3" platEncID="1"/g' PingFangHK-Regular.ttx
sed -i '' 's/platformID="0" platEncID="4"/platformID="3" platEncID="10"/g' PingFangHK-Regular.ttx
ttx -b -m PingFangHK-Regular.otf PingFangHK-Regular.ttx

ttx -t cmap PingFangHK-Semibold.otf
sed -i '' 's/platformID="0" platEncID="3"/platformID="3" platEncID="1"/g' PingFangHK-Semibold.ttx
sed -i '' 's/platformID="0" platEncID="4"/platformID="3" platEncID="10"/g' PingFangHK-Semibold.ttx
ttx -b -m PingFangHK-Semibold.otf PingFangHK-Semibold.ttx

ttx -t cmap PingFangHK-Thin.otf
sed -i '' 's/platformID="0" platEncID="3"/platformID="3" platEncID="1"/g' PingFangHK-Thin.ttx
sed -i '' 's/platformID="0" platEncID="4"/platformID="3" platEncID="10"/g' PingFangHK-Thin.ttx
ttx -b -m PingFangHK-Thin.otf PingFangHK-Thin.ttx

ttx -t cmap PingFangHK-Ultralight.otf
sed -i '' 's/platformID="0" platEncID="3"/platformID="3" platEncID="1"/g' PingFangHK-Ultralight.ttx
sed -i '' 's/platformID="0" platEncID="4"/platformID="3" platEncID="10"/g' PingFangHK-Ultralight.ttx
ttx -b -m PingFangHK-Ultralight.otf PingFangHK-Ultralight.ttx

# PingFangSC
ttx -t cmap PingFangSC-Light.otf
sed -i '' 's/platformID="0" platEncID="3"/platformID="3" platEncID="1"/g' PingFangSC-Light.ttx
sed -i '' 's/platformID="0" platEncID="4"/platformID="3" platEncID="10"/g' PingFangSC-Light.ttx
ttx -b -m PingFangSC-Light.otf PingFangSC-Light.ttx

ttx -t cmap PingFangSC-Medium.otf
sed -i '' 's/platformID="0" platEncID="3"/platformID="3" platEncID="1"/g' PingFangSC-Medium.ttx
sed -i '' 's/platformID="0" platEncID="4"/platformID="3" platEncID="10"/g' PingFangSC-Medium.ttx
ttx -b -m PingFangSC-Medium.otf PingFangSC-Medium.ttx

ttx -t cmap PingFangSC-Regular.otf
sed -i '' 's/platformID="0" platEncID="3"/platformID="3" platEncID="1"/g' PingFangSC-Regular.ttx
sed -i '' 's/platformID="0" platEncID="4"/platformID="3" platEncID="10"/g' PingFangSC-Regular.ttx
ttx -b -m PingFangSC-Regular.otf PingFangSC-Regular.ttx

ttx -t cmap PingFangSC-Semibold.otf
sed -i '' 's/platformID="0" platEncID="3"/platformID="3" platEncID="1"/g' PingFangSC-Semibold.ttx
sed -i '' 's/platformID="0" platEncID="4"/platformID="3" platEncID="10"/g' PingFangSC-Semibold.ttx
ttx -b -m PingFangSC-Semibold.otf PingFangSC-Semibold.ttx

ttx -t cmap PingFangSC-Thin.otf
sed -i '' 's/platformID="0" platEncID="3"/platformID="3" platEncID="1"/g' PingFangSC-Thin.ttx
sed -i '' 's/platformID="0" platEncID="4"/platformID="3" platEncID="10"/g' PingFangSC-Thin.ttx
ttx -b -m PingFangSC-Thin.otf PingFangSC-Thin.ttx

ttx -t cmap PingFangSC-Ultralight.otf
sed -i '' 's/platformID="0" platEncID="3"/platformID="3" platEncID="1"/g' PingFangSC-Ultralight.ttx
sed -i '' 's/platformID="0" platEncID="4"/platformID="3" platEncID="10"/g' PingFangSC-Ultralight.ttx
ttx -b -m PingFangSC-Ultralight.otf PingFangSC-Ultralight.ttx

# PingFangTC
ttx -t cmap PingFangTC-Light.otf
sed -i '' 's/platformID="0" platEncID="3"/platformID="3" platEncID="1"/g' PingFangTC-Light.ttx
sed -i '' 's/platformID="0" platEncID="4"/platformID="3" platEncID="10"/g' PingFangTC-Light.ttx
ttx -b -m PingFangTC-Light.otf PingFangTC-Light.ttx

ttx -t cmap PingFangTC-Medium.otf
sed -i '' 's/platformID="0" platEncID="3"/platformID="3" platEncID="1"/g' PingFangTC-Medium.ttx
sed -i '' 's/platformID="0" platEncID="4"/platformID="3" platEncID="10"/g' PingFangTC-Medium.ttx
ttx -b -m PingFangTC-Medium.otf PingFangTC-Medium.ttx

ttx -t cmap PingFangTC-Regular.otf
sed -i '' 's/platformID="0" platEncID="3"/platformID="3" platEncID="1"/g' PingFangTC-Regular.ttx
sed -i '' 's/platformID="0" platEncID="4"/platformID="3" platEncID="10"/g' PingFangTC-Regular.ttx
ttx -b -m PingFangTC-Regular.otf PingFangTC-Regular.ttx

ttx -t cmap PingFangTC-Semibold.otf
sed -i '' 's/platformID="0" platEncID="3"/platformID="3" platEncID="1"/g' PingFangTC-Semibold.ttx
sed -i '' 's/platformID="0" platEncID="4"/platformID="3" platEncID="10"/g' PingFangTC-Semibold.ttx
ttx -b -m PingFangTC-Semibold.otf PingFangTC-Semibold.ttx

ttx -t cmap PingFangTC-Thin.otf
sed -i '' 's/platformID="0" platEncID="3"/platformID="3" platEncID="1"/g' PingFangTC-Thin.ttx
sed -i '' 's/platformID="0" platEncID="4"/platformID="3" platEncID="10"/g' PingFangTC-Thin.ttx
ttx -b -m PingFangTC-Thin.otf PingFangTC-Thin.ttx

ttx -t cmap PingFangTC-Ultralight.otf
sed -i '' 's/platformID="0" platEncID="3"/platformID="3" platEncID="1"/g' PingFangTC-Ultralight.ttx
sed -i '' 's/platformID="0" platEncID="4"/platformID="3" platEncID="10"/g' PingFangTC-Ultralight.ttx
ttx -b -m PingFangTC-Ultralight.otf PingFangTC-Ultralight.ttx

檔名帶有「#1」就是新生成的字型檔

[參考連結](蘋方移植 | by Toby Tso | 汚音屋 × UJAM | Medium)

模板

LCS模板

import bisect

# aaaccceeeee
# bbaccesssss
# acce
def LCS(a1, a2):
    # Location of char (0~127)
    idx = {}

    for i,x in enumerate(a2):
        if x in idx:
            idx[x].append(i)
        else:
            idx[x] = [i]
    r = [-1]
    # print(idx)
    for s1 in a1:
        if not s1 in idx: continue
        for n in reversed(idx[s1]):
            if n > r[-1]:
                r.append(n)
            else:
                r[bisect.bisect_left(r, n)] = n

    print(len(r)-1)

LCS(list(input().strip()), list(input().strip()))

第一次自己寫DP

題解

先把圖畫出來
接下來想到 dp[i] 會是第i階樓梯的最小花費
列一下轉移方程式
找說要算出這一階要怎麼算
dp[i] = min(dp[i-2] + stair[i], dp[i-1] + stair[i])
我的想法是 前一階+這一階 和 前面兩階+這一階 去找最小的(因為題目說以走一階或兩階)

Code

import sys

N = int(sys.stdin.readline().strip())
dp = [0 for x in range(N+5)]

all = list(map(int, sys.stdin.readline().strip().split(' ')))
# print(all)

dp[0] = 0

for i in range(N):
    dp[i+1] = min(dp[i-1] + all[i], dp[i] + all[i])

print(dp[N])

Intro

例題 P-2-1. 不同的數—排序

Code

#include <bits/stdc++.h>

using namespace std;
#define pb emplace_back
typedef pair<int, int> pii;

signed main() {
    ios::sync_with_stdio(0);cin.tie(0);
    set<int> a;
    int N;cin >>N;
    for(int i=0;i<N;i++){
        int x;cin >> x;
        a.insert(x);
    }
    cout << a.size() << endl;
    int i=0;
    for(auto &x: a){
        cout << x << " \n"[i==N-1];
        i++;
    }
    cout << endl;


    return 0;
}

Code

#include <bits/stdc++.h>
#define int long long
using namespace std;

int p[1000000];
int find(int idx){
    while(idx!=p[idx]){
        idx = p[idx];//cout  << "get " << idx << endl;
    }
    return idx;
}

signed main() {
    typedef pair<int, int> pp;
    // DSU
    int N,M,Q;cin >> N >> M >> Q;
    for(int i=1;i<=N;i++)p[i]=i;
    while(M--){
        int a,b;cin >> a >> b;
        int idx = min(find(a),find(b));
        p[find(a)] = idx;
        p[find(b)] = idx;
    }

    /*for(int i=1;i<=N;i++){
        cout << i << ": " << p[i] << endl;
    }*/
    while(Q--){
        int a,b;cin >> a >> b;
        if(find(a) == find(b)){
            cout << ":)" << endl;
        } else {
            cout << ":(" << endl;
        }
    }
    return 0;
}

Code

#include <bits/stdc++.h>

#define int long long
using namespace std;

signed main() {
    ios::sync_with_stdio(0);cin.tie(0);
    unsigned long long N;
    cin >> N;

    bitset<10000000> bs;
    // bs.set();
    while (N--) {
        unsigned long long a, b;
        cin >> a >> b;
        for (unsigned long long i = a; i < b; i++) {
            bs.set(i);
        }
    }

    cout << bs.count() << endl;
    return 0;
}

題解

看起來就很DFS

Code

#include <bits/stdc++.h>
using namespace std;

bool vis[100000];
int  fri[100000];
int  cnt = 0;
void dfs(int x,int top, bool m =true){
    //cout << x << " " << top << endl;
    if(x == top && m) {
        cnt ++;
    }

    if(vis[x])return;

    vis[x] = true;
    return dfs(fri[x], top);
}

signed main() {
    int N;cin >> N;
    for(int i=0;i<N;i++)cin >> fri[i];

    for(int i=0;i<N;i++){
        dfs(i,i, false);
    }
    cout << cnt << endl;
    return 0;
}

Link

https://zerojudge.tw/ShowProblem?problemid=f605

Code

#include <bits/stdc++.h>
using namespace std;

int calc(int s,int e,int f){
    int total = 0;
    if(s==e){
        return f;
    } else {
        if(f<=1000) {
            return f*3;
        } else {
            return (f-1000)*2+3000;
        }
    }
}

int main() {
    int s,c,n;
    int Q[100][100];

    cin >> s >> c >> n;
    for(int i=0;i<s;i++){
        for(int j=0;j<c;j++){
            cin >> Q[i][j];
        }
    }
    vector<int>cc;
    for(int i=0;i<n;i++){
        int v[100][100];
        memset(v, 0, sizeof(v));
        set<pair <int, int>> se;

        for(int j=0;j<s;j++){
            int _c;cin >> _c;
            for(int k=0;k<c;k++){
                v[_c][k] += Q[j][k];
                //cout << "Start: " << _c << " End: " << k << " Flow: " << Q[j][k] << " Cnt: " << v[_c][k] <<  endl;
                se.emplace(make_pair(_c,k));
            }
        }

        int total =0;
        for(auto &x: se){
            total += calc(x.first, x.second, v[x.first][x.second]);
            //cout << "Start: " << x.first << " End: " << x.second << " Flow: " << v[x.first][x.second] << " Total: " << total <<  endl;
        }


        //cout << total << endl;
        cc.emplace_back(total);
        // end 方案
    }
    sort(cc.begin(), cc.end());
    cout << cc[0] << endl;


    return 0;
}

Code

#include <bits/stdc++.h>
using namespace std;


int main() {
    int a,b;cin >> a >> b;
    int n;cin >> n;
    int cnt=0;
    for(int i=0;i<n;i++){
        int x;
        int _a=0,_b=0;
        while(cin >> x){
            if(x==0)break;
            if(abs(x) == a || abs(x) == b){
                if(x == -a){
                    _a--;
                } else if(x == a){
                    _a++;
                } else if(x == b){
                    _b++;
                } else if(x == -b){
                    _b--;
                }
            }
        }
        if(_a > 0 && _b>0) cnt++;
    }

    cout << cnt << endl;


    return 0;
}

Link

https://zerojudge.tw/ShowProblem?problemid=c295

Code

#include <bits/stdc++.h>
using namespace std;

int all[100][100];
int slt[100] ;
int N,M ;

int main() {
    cin >> N >> M;
    int MM=0;
    for(int i=0;i<N;i++){
        int mm = -1;
        for(int j=0;j<M;j++){
            cin >> all[i][j];
            mm = max(all[i][j], mm);
        }
        MM += mm;
        slt[i] = mm;
    }
    // S = MM
    vector<int> a;
    for(int i=0;i<N;i++){
        if(MM % slt[i] == 0)a.emplace_back(slt[i]);
    }
    cout << MM << endl;

    if(a.size()==0){
        cout << -1 << endl;
        return 0;
    }

    for(int i=0;i<a.size();i++){
        cout << a[i] << " \n"[i==a.size()-1];
    }
    return 0;
}