網頁

2014年4月22日 星期二

中州韻 fcitx-rime 嘸蝦米 配置 ~~用了我二十分鐘

安裝fcitx-rime

使用apt-get

sudo apt-get install fcitx-rime

"重新啟動fcitx"

這時己經可以使用rime的拼音

取得Rime schema與dict檔

由於有版權問題~~,所以請參考下面的連結

下載連結

接下來,複製壓縮檔內4個文件(liur.schema.yaml、liur.dict.yaml、Phonetic_tw.schema.yaml、Phonetic_tw.dict.yaml)
到 ~/.config/fcitx/rime/ 裡

編譯 (文件中似乎沒有提到,但不用不行)

cd ~/.config/fcitx/rime
rime_deployer --compile liur.schema.yaml .
rime_deployer --compile Phonetic_tw.schema.yaml .

修改 default.yaml

在schema_list選項中,加入 - schema: liur
"重新啟動fcitx"

完成

直接看影片教學

(尚未製作)

2014年4月2日 星期三

安裝最新版的 emacs ppa

第一步:

加入ubuntu-elisp ppa

sudo add-apt-repository ppa:ubuntu-elisp/ppa

第二步:

更新

sudo apt-get update

第三步:

安裝emacs-snapshot

sudo apt-get install emacs-snapshot

參考資料:

By my own

2014年3月20日 星期四

latex 使用 titlesec package 修改 section 標題時會影響 toc

解決方法

不使用titlesec,直接重新定義section 與 subsection

\makeatletter
\renewcommand{\section}{\@startsection
{section}%                   % the name
{1}%                         % the level
{\z@}%                       % the indent / 0mm
{-\baselineskip}%            % the before skip / -3.5ex \@plus -1ex \@minus -.2ex
{0.5\baselineskip}%          % the after skip / 2.3ex \@plus .2ex
{\hspace{25pt}\normalsize}} % the style
\makeatletter
\renewcommand{\subsection}{\@startsection
{subsection}%                   % the name
{1}%                         % the level
{\z@}%                       % the indent / 0mm
{-\baselineskip}%            % the before skip / -3.5ex \@plus -1ex \@minus -.2ex
{0.5\baselineskip}%          % the after skip / 2.3ex \@plus .2ex
{\hspace{50pt}\normalsize}} % the style

2014年3月18日 星期二

MathJax -- JavaScript display math engine

  • This is an inline math use \( \backslash ( \) and \( \backslash ) \) example: \( sin^\theta + cos^\theta = 1 \)

  • This is an display math use \( \backslash[ \) and \( \backslash[ \) example: \[ e^{i\theta} = cos\theta + isin\theta \]

  • If you want to know about the TeX Command(if the formula write by TeX) or MathML code just right click the formula.
For more information, please check the website MathJax

2014年3月4日 星期二

UVA 10295 - Hay Points

 #include <iostream>
 #include <cstdio>
 #include <cmath>
 #include <cstring>
 #include <climits>
 #include <vector>
 #include <string>
 #include <sstream>
 #include <algorithm>
 #include <map>
 #include <bitset>
 #define MAX 10000
 using namespace std;
 typedef long long int lli;
 
 int main(int argc, char *argv[]){
   int m, n;
   string word;
   int value;
   map<string, int> dictionary;
   map<string, int>::iterator it;
   cin >> m >> n;
 
   for (int i=0; i<m; ++i){
     cin >> word >> value;
     dictionary[word]=value;
   }
 
   string s;
   while (n--){
    int salary = 0;
    while (cin >> s && s!="."){
      it = dictionary.find(s);
      if (it!=dictionary.end())
        salary += it->second;
    }
    cout << salary << endl;
  }
  return 0;
}

2014年2月24日 星期一

UVA 10127 - Ones

 #include <iostream>
 #include <cstdio>
 #include <cmath>
 #include <cstring>
 #include <vector>
 #include <string>
 #include <sstream>
 #include <algorithm>
 #include <map>
 #include <bitset>
 #define MAX 1000000
 using namespace std;
 typedef long long int lli;
 
 int main(int argc, char *argv[]){
   int n;
   while (cin >> n){
     int digit=1, number=1;
     for (int number=1; number%n!=0; number=number*10+1, number%=n)
       digit++;
     cout << digit << endl ;
   }
   return 0;
 }

c048: Ant on a Chessboard

 #include <stdio.h>
 #include <math.h> 
 
 int main(int argc, char *argv[])
 {
        int N ; 
        int layer ; 
        int base ; 
        int displace ; 
        int coor[2] ; 
        while(scanf("%d",&N) && N){
                N-- ; 
                layer = floor(sqrt(N))+1; 
                base = layer*(layer-1) ; 
                displace = N-base ; 
                coor[0] = coor[1] = layer ; 
 
                if(layer%2 == 1) 
                        if(displace > 0)
                                coor[0] -= displace ; 
                        else
                                coor[1] += displace ;
                else
                        if(displace > 0) 
                                coor[1] -= displace ; 
                        else
                                coor[0] += displace ; 
                printf("%d %d\n", coor[0], coor[1]) ;  
        }
        return 0;
 }

2014年2月14日 星期五

UVA 10340 - All in All

 #include <iostream>
 #include <cstdio>
 #include <cmath>
 #include <vector>
 #include <string>
 #include <sstream>
 #include <algorithm>
 #include <map>
 #include <bitset>
 #define MAX 1000000
 using namespace std;
 typedef long long int lli;
 
 int main(int argc, char *argv[]){
   string s, t;
   int i, j;
   while (cin >> s >> t){
     i=0, j=0;
     while (i!=t.length()){
       if (s[j]==t[i]) ++j;
       ++i;
     }
     cout << (j==s.length() ? "Yes" : "No") << endl;
   }
   return 0;
 }

UVA 10298 - Power Strings

 #include <iostream>
 #include <cstdio>
 #include <cmath>
 #include <vector>
 #include <string>
 #include <sstream>
 #include <algorithm>
 #include <map>
 #include <bitset>
 #define MAX 1000000
 using namespace std;
 typedef long long int lli;
 
 int main(int argc, char *argv[]){
   string s;
   bool isPowerString=true;
   while (getline(cin, s) && s!="."){
     for (int i=1; i<=s.length(); ++i){
       if (s.length()%i != 0) continue;
 
       isPowerString = true;
       for (int j=i; j<s.length(); j+=i){
         for (int k=0; k<i; ++k)
           if (s[k] != s[k+j]){
             isPowerString=false;
             break;
           }
         if (isPowerString==false) break;
       }
 
       if (isPowerString==true){
         cout << s.length()/i << endl;
         break;
      }
    }
      
  }
  return 0;
}

2014年2月7日 星期五

uva 11917 - Do Your Own Homework

 #include <iostream>
 #include <cstdio>
 #include <vector>
 #include <string>
 #include <sstream>
 #include <algorithm>
 #include <map>
 #include <bitset>
 #define MAX 1000000
 using namespace std;
 
 int main(int argc, char *argv[]){
   int t;
   int n;
   string subject;
   int days;
   int deadline;
   cin >> t;
   for (int i=1; i<=t; ++i){
     cin >> n;
     map<string, int> m;
     map<string, int>::iterator it;
     for (int j=0; j<n; ++j){
       cin >> subject >> days;
       m[subject] = days;
     }
     cin >> deadline >> subject;
 
     it = m.find(subject);
     if (it == m.end()){
       printf("Case %d: Do your own homework!\n", i);
     } else if (it->second <= deadline) {
       printf("Case %d: Yesss\n", i);
     } else if (it->second <= deadline+5) {
       printf("Case %d: Late\n", i);
     } else {
       printf("Case %d: Do your own homework!\n", i);
     }
   }
  return 0;
}

UVA 12602 - Nice Licence Plates

 #include <iostream>
 #include <cstdio>
 #include <vector>
 #include <string>
 #include <sstream>
 #include <algorithm>
 #include <bitset>
 #define MAX 1000000
 using namespace std;
 
 int main(int argc, char *argv[]){
   string line, subline;
   int t;
   cin >> t;
   getline(cin, line); // read new line
   while (t--){
       getline(cin, line);
       int sum=0;
       int number=0;
       for (int i=0; i<3; ++i){
         sum = sum*26+(line[i]-'A');
       }
       subline = line.substr(4,4);
       stringstream ss;
       ss << subline;
       ss >> number;
       if (abs(number-sum)<=100){
         puts("nice");
       } else {
         puts("not nice");
       }
   }
   return 0;
}

UVA 10235 - Simply Emirp

 #include <iostream>
 #include <cstdio>
 #include <vector>
 #include <sstream>
 #include <algorithm>
 #include <bitset>
 #define MAX 1000000
 using namespace std;
 
 bitset<MAX+1> bs;
 
 void seive(){
   bs.set();
   bs[0]=false, bs[1]=false;
   
   for (long long int i=2; i<=bs.size(); ++i){
     if (bs[i]==true){
       for (long long int j=i*i; j<bs.size(); j+=i) 
         bs[j]=false;
     }
   }
   return; 
 }
 
 int main(int argc, char *argv[]){
   seive();
   
   int num, renum, tmp;
   while(cin>>num){
     tmp = num;
     for (renum=0; tmp; tmp/=10){
       renum = renum*10+(tmp%10);
     }
    if (bs[num]==true){
      if (bs[renum]==true && num!=renum){
        printf("%d is emirp.\n", num);
      } else {
        printf("%d is prime.\n", num);
      }
    } else {
      printf("%d is not prime.\n", num);
    }
  }
  return 0;
}

2014年2月6日 星期四

UVA 11150 - Cola

#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

int main(int argc, char *argv[]){
  int n;
  while(cin>>n){
    int total=n;
    int empty=n;
    int remain;

    while (empty>=3){
      remain = empty/3; 
      empty = empty%3;
       total += remain;
       empty += remain;
     }
 
     if (empty==2){
       total++;
     } 
     
     cout << total << endl;
   }
   return 0;
 }

UVA 10057 - A mid-summer night's dream.

 #include <iostream>
 #include <algorithm>
 #include <vector>
 using namespace std;
 
 int main(int argc, char *argv[]){
   int n;
   int num[1000001];
   while(cin>>n){
     int min_median=0;
     int max_median=0;
     int Innum=0;
     int integers=0;
     for (int i=0; i<n; ++i){
       cin >> num[i];
     }
     sort(num, num+n);
     
     if (n%2==1){
       min_median=num[n/2];
       for (int i=0; i<n; ++i)
         if (num[i]==min_median)
           Innum++;
       integers=1;
     } else {
       max_median=num[n/2];
       min_median=num[n/2-1];
       for (int i=0; i<n; ++i)
         if (num[i]==min_median || num[i]==max_median)
           Innum++;
       integers=max_median-min_median+1;
     }
     cout << min_median << " " << Innum << " " << integers << endl;
   }
   return 0;
 }

UVA 299 - Train Swapping

 /* just like bubble sort swapping times */
 #include <iostream>
 #include <algorithm>
 using namespace std;
 
 int main(int argc, char *argv[]){
   int t;
   cin >> t;
   int train[51];
   while(t--){
     int length;
     int count=0;
     cin >> length;
     for (int i=0; i<length; ++i){
       cin >> train[i];
     }
 
     for (int i=0; i<length-1; ++i){
       for (int j=0; j<length-i-1; ++j){
         if (train[j]>train[j+1])
           swap(train[j], train[j+1]), count++;
       }
     }
     cout << "Optimal train swapping takes " << count << " swaps." << endl;
   }
   return 0;
 }

UVA 10062 - Tell me the frequencies!

 #include <iostream>
 #include <string>
 #include <vector>
 #include <map>
 #include <algorithm>
 
 using namespace std;
 
 class Freq{
  public:
   Freq(char ansii, int count){
     this->ansii = ansii;
     this->count = count;
   }
   char ansii;
   int count;
 };
 
 bool FreqCompare (const Freq &a, const Freq &b){
   if (a.count!=b.count){
     return a.count<b.count;
   } else {
     return a.ansii>b.ansii;
   }
 }
 
 int main(int argc, char *argv[]){
   map<char, int> m;
   map<char, int>::iterator it;
   vector<Freq> freq;
   string line;
   bool firstTime=true;
   while (getline(cin, line)){
     m.clear();
     freq.clear();
     
     for (int i=0; i<line.size(); ++i){
       it = m.find(line[i]);
       (it == m.end()) ? m[line[i]]=1 : m[line[i]]++;  
    }
    
    for (it=m.begin(); it!=m.end(); ++it){
      freq.push_back(Freq(it->first, it->second));
    }

    sort(freq.begin(), freq.end(), FreqCompare);
    firstTime ? firstTime=false : cout << endl ;
    for (int i=0; i<freq.size(); ++i){
      cout << (size_t) freq[i].ansii << " " << freq[i].count << endl;
    }
  }
  return 0;
}

UVA 543 - Goldbach's Conjecture

 /* use seive method to generate the table of prime number 
    reference: http://www.cnblogs.com/xiaobaibuhei/p/3329702.html
    http://maplewing.blogspot.tw/2011/02/uva543goldbachs-conjecture.html*/
  
 #include <iostream>
 #include <vector>
 #include <bitset>
 #define MAX 1000000
 using namespace std;
 
 bitset<MAX+1> bs;
 vector<int> primes;
   
 void seive(){
   bs.set(); // set all bit to 1
   bs[0]=false, bs[1]=false;
 
   for (long long int i=2; i<=MAX; ++i){
     if (bs[i]==true){
       for (long long int j=i*i; j<=MAX; j+=i)
         bs[j]=false;
       primes.push_back(i);
     }
   }
   return;
 }
 
 int main(int argc, char *argv[]){
   seive();
   int n;
   while(cin>>n && n){
     for (int i=0; i<primes.size(); ++i){
       if (bs[primes[i]]==true && bs[n-primes[i]]==true){
         cout << n << " = " << primes[i] << " + " << n-primes[i] << endl;
         break;
       }
     }
   }
   return 0;
}

2014年2月5日 星期三

UVA 10226 - Hardwood Species

 #include <iostream>
 #include <cstdio>
 #include <iomanip>
 #include <string> 
 #include <map>
 #include <algorithm>
 
 using namespace std;
 
 int main(int argc, char *argv[]){
   int t;
   string line;
   cin >> t;
   getline(cin, line); // read new line
   getline(cin, line); // read new line
   while (t--){
     map<string, int> m;
     map<string, int>::iterator it;
     int count=0 ;
     while (getline(cin, line)){
       if (line=="") break;
       it = m.find(line);
       if (it == m.end()){
         m[line] = 1;
       } else {
         it->second++;
       }
       count++;
     }
     
     for (it=m.begin(); it!=m.end(); ++it){
       float percent = 100.0*it->second/count;
       cout  << it->first << ' ' << fixed << setprecision(4) << percent << endl;
     }
 
     if (t>0) cout << endl ;
     
   }
   return 0;
}