2015年6月29日星期一

Setup Ubuntu 14.10 on Asus X205ta



因為X205的架構非常獨特,Linux對其硬體的支援度非常弱(據說kernel4.0之後有所改善,這倒還需要研究一番),目前的進度是將Ubuntu系統塞進32Gb的固態碟中,並設定能自動抓取開機磁區,之後可能還要針對WIFI、音效、快捷鍵和讀卡機等週邊設備進行設定。


1) 用Rufus製作開機磁碟,設定GPT partition scheme for UEFI computer,filesystem為fat32即可,將iso檔燒錄進去,並將bootia32.efi放進boot/efi/EFI底下

2) 進入BIOS,將Secure Boot Control關掉,USB Controller 改成EHCI

3) 重新開機,按Esc進入開機選單,選擇USB開機,安裝系統過程中因為mmcblk0rpmb會不斷有讀寫錯誤訊息,過程會停頓許久,需耐心等待

4) 到選擇安裝模式的畫面時,選擇將硬碟上所有資料清除,全部安裝為Ubuntu,記得選32Gb的那一塊,其他不要動

5) 安裝完成後重開機,請再次使用USB開機,進入Grub畫面,按下c進入指令行,輸入下列命令:

linux (hd1,gpt2)/boot/vmlinuz-3.16-0-23-generic root=/dev/mmcblk0p2 reboot=pci,force 
initrd (hd1,gpt2)/boot/initrd-3.16-0-23-generic 
boot

P.S. 安裝完系統後,分割區掛載分別為:
  • /boot = /dev/mmcblk0p1
  • / = /dev/mmcblk0p2

6) 初次進入系統後,在終端機進行bootia32.efi的建置(為了使EFI晶片能辨識硬碟內Ubuntu之開機磁區)

  • apt-get install git bison libopts25 libselinux1-dev autogen m4 autoconf help2man libopts25-dev flex libfont-freetype-perl automake autotools-dev libfreetype6-dev texinfo 
     # from http://www.gnu.org/software/grub/grub-download.html 
  • git clone git://git.savannah.gnu.org/grub.git 
  • cd grub 
  • ./autogen.sh 
  • ./configure --with-platform=efi --target=i386 --program-prefix="" 
  • make
  •  cd grub-core 
  • ../grub-install -d . --efi-directory /boot/efi/ --target=i386 
  • cd /boot/efi/EFI 
  • cp grub/grubia32.efi ubuntu/
目前這樣可以在開機後順利進入Ubuntu系統,至於週邊驅動的問題解決後再附上。



-------------6/30/2015
經資料查找,應該會先更新Kernel,參考連結如下:
http://magiclen.org/ubuntu-kernel-update/

一些硬體設定參考這兩篇:
http://magiclen.org/asus-x205ta-linux-mint-17/
https://wiki.debian.org/InstallingDebianOn/Asus/X205TA

Sound:
http://www.jfwhome.com/2014/03/07/perfect-ubuntu-or-other-linux-on-the-asus-transformer-book-t100/

成功再貼上

-------------7/4/2015-------------
讀卡機和WIFI設定OK,Kernel更新至4.1.0,Battery status恢復正常
聲音還未成功
觸控版手掌偵測未完成


關閉觸控板(加入至.bashrc)
xinput -disable 12
#可用xinput -list查看設備

修復於Compiz桌面下,Alt+Tab切換視窗無效

先安裝Compiz Config Setting Manager
$sudo apt-get install compizconfig-settings-manager

再裝Plugin
$sudo apt-get install compiz-plugin-main

運行ccsm,將static application switcher點選即可


-------------10/21/2015-------------
如果要修復開機時mmcblk0rpmb 的timeout問題
可以試試看這個:
https://linuxnorth.wordpress.com/2014/08/27/t100-timeout-issue-solved/

2015年6月23日星期二

Install linux on ASUS X205

website notes here:

DebianOn : https://wiki.debian.org/InstallingDebianOn/Asus/X205TA
Mint 17: http://magiclen.org/asus-x205ta-linux-mint-17/
Ubuntu : https://github.com/lopaka/instructions/blob/master/ubuntu-14.10-install-asus-x205ta.md

http://askubuntu.com/questions/610456/ubuntu-on-asus-eeebookx205-with-all-peripherals
https://help.ubuntu.com/community/EeePC/Fixes
https://wiki.debian.org/InstallingDebianOn/Asus/X205TA
http://ubuntuforums.org/showthread.php?t=2254322
http://brownbro.github.io/blog/2015/01/15/asus-x205ta-with-lubuntu/

[UVa] 11059 - Maximum Product

暴力求解可得


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <iostream>
#include <cstdio>
#include <sstream>
using namespace std;
int main(){
  int N, i, k, kase=0;;
  string line;
  while(scanf("%d",&N)!=EOF){
    kase++;
    long long int S[N];
    getchar();
    
//Input S[0]~S[N-1]
    getline(cin,line);
    i=0,k=0;
    long long int x;
    stringstream ss(line);
    while(ss>>x){
      S[i]=x;
      i++;
    }
    
    
    int ok=0;
    long long int max=0,tmp;

//count in brute-force    
    for(i=0;i<N;i++){
      tmp = 1;
      for(int j=i;j<N;j++){
        tmp = tmp * S[j];
        if(tmp > max) max = tmp;
      }
    }

    cout << "Case #" << kase << ": The maximum product is " 
         << max << "." ;
    printf("\n\n");
  }

  return 0;
}

2015年6月20日星期六

[UVa] 725 - Division

以Brute-force去求解
輸入N,求 N = abcde / fghij
而a~j為0~9的數字,互相不重複
每兩個輸出間要空行,而最後以0結束時又不能多空行

#include <stdio.h>
#include <stdlib.h>
#include <string>
using namespace std;

int N,a,b; // a / b
int main(){
  scanf("%d",&N);
  while(1){
    int ok=0;
    if(N==0)break;
    else {
      for(int k=0;k<100000;k++){
        int b1 = k/10000,
        b2 = k%10000/1000,
        b3 = k%10000%1000/100,
        b4 = k%10000%1000%100/10,
        b5 = k%10000%1000%100%10;
        //printf("%d %d %d %d\n",b1,b2,b3,b4);
        if(b1!=b2 && b1!=b3 && b1!=b4 && b1!=b5 && b2!=b3 && b2!=b4 && b2!=b5
        && b3!=b4 && b3!=b5 && b4!=b5){
          b = k;
          //printf("%d ",b);
          a = b*N;
          if(a/10000 >=10)break;
          else {
            int a1 = a/10000,
            a2 = a%10000/1000,
            a3 = a%10000%1000/100,
            a4 = a%10000%1000%100/10,
            a5 = a%10000%1000%100%10;
            if(   a1!=a2 && a1!=a3 && a1!=a4 && a1!=a5
               && a1!=b1 && a1!=b2 && a1!=b3 && a1!=b4 && a1!=b5
               && a2!=a3 && a2!=a4 && a2!=a5
               && a2!=b1 && a2!=b2 && a2!=b3 && a2!=b4 && a2!=b5
               && a3!=a4 && a3!=a5
               && a3!=b1 && a3!=b2 && a3!=b3 && a3!=b4 && a3!=b5
               && a4!=a5 && a4!=b1 && a4!=b2 && a4!=b3 && a4!=b4 && a4!=b5
               && a5!=b1 && a5!=b2 && a5!=b3 && a5!=b4 && a5!=b5
              )
            {
              printf("%05d / %05d = %d\n",a,b,N); 
              ok=1;
            }
          }
        }
      }
        if(ok==0)printf("There are no solutions for %d.\n",N);
    }
    scanf("%d",&N);
    if(N==0)break; else puts("");

  }
    return 0;
}





Ruija Liu 的神奇寫法
將運算式轉為字串
按照大小排序後,直接檢查0~9是否有缺數字
即可作為題目限制的判定


// UVa725 Division
// Rujia Liu
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;

int main() {
  int n, kase = 0;
  char buf[99];
  while(scanf("%d", &n) == 1 && n) {
    int cnt = 0;
    if(kase++) printf("\n");
    for(int fghij = 1234; ; fghij++) {
      int abcde = fghij * n;
      sprintf(buf, "%05d%05d", abcde, fghij);
      if(strlen(buf) > 10) break;
      sort(buf, buf+10);
      bool ok = true;
      for(int i = 0; i < 10; i++)
        if(buf[i] != '0' + i) ok = false;
      if(ok) {
        cnt++;
        printf("%05d / %05d = %d\n", abcde, fghij, n);
      }
    }
    if(!cnt) printf("There are no solutions for %d.\n", n);
  }
  return 0;
}





2015年5月29日星期五

[UVa] 10562 - Undraw the Tree

主要以深度優先搜尋DFS,遞迴整棵樹,邊遞迴邊輸出



#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <cctype>
char tree[300][300];
int k=0; //the high of the input tree
void dfs(int r,int c){
 printf("%c(",tree[r][c]);
 if(r+1<k && tree[r+1][c]=='|'){ //邊界要注意
  int i=c;
  while(i-1>=0 && tree[r+2][i-1]=='-')i--;
  while(tree[r+2][i]=='-' && tree[r+3][i]!='\0'){
   if(tree[r+3][i]!=' ' && tree[r+3][i]!='\n')dfs(r+3,i); 
   //上面這邊一定要判斷換行和空白
   i++;
  }
 }
 printf(")");
}
int main(){
 freopen("input.txt","r",stdin);
 int T;
 scanf("%d",&T);
 getchar();
 while(T--){
  memset(tree,0,sizeof(tree));
  k=0;
  while(fgets(tree[k],sizeof(tree[k]),stdin)){
   //printf("%s",tree[k]);
   if(tree[k][0]=='#')break;
   else k++;
  }
  printf("(");
  if(k){
   for(int i=0;i<strlen(tree[0]);i++){
    if(tree[0][i]!=' '){ //這邊也是要以空白為判斷
     //printf("%c\n",tree[0][i]);
     dfs(0,i);
     break;
    }
   }
  }
  printf(")\n");
 }
 return 0;
}

2015年5月8日星期五

Raspberry 安裝簡記

為了架設VPN伺服器

買了一張 Raspberry Pi II Model B

效能上比起第一代好多了

記憶卡要移植最新的系統,不然無法開機

網路設定檔如下:

/etc/network/interfaces : 

allow-hotplug wlan0 #熱插拔

iface wlan0 inet manual #手動設定
wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf #使用 wpa_supplicant 設定網路參數

/etc/wpa_supplicant/wpa_supplicant.conf :

network={
  ssid="xxxxxxx"                  # SSID
  psk="xxxxxx"                    # Password
  proto=RSN                       # WPA2 加密協定
  pairwise=CCMP                   # WPA2 加密協定
  key_mgmt=WPA-PSK                # WPA2 金鑰管理協定
  auth_alg=OPEN                   # WPA2 認證演算法
}



這樣開機就能用無線網卡找到基地台了

2015年5月2日星期六

[UVA] 10129 - Play on words

本題的要求是確認是否為有向的連通圖
運用了尤拉圖概念
先判定各字母節點的入度與出度
僅有兩個節點的入度會不等於出度(起點和終點)
DFS確認是否連通

程式碼參考《入門經典》一書,及CSDN網友shuangde800 的部落格

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <iostream>
using namespace std;
int N;
int G[100][100];
int in[100];
int out[100];
int visit[100];    //visited or not
int dfs(int a);
int main(){
    freopen("input.txt","r",stdin);
    int T;
    scanf("%d",&T);
    while(T--){
      memset(in,0,sizeof(in));
      memset(out,0,sizeof(out));
      memset(G,0,sizeof(G));
      scanf("%d",&N);
      while(N--){
        string input;
        cin >> input;
        out[input[0]-'a']++;
        in[input[input.size()-1]-'a']++;
        G[input[0]-'a'][input[input.size()-1]-'a']++;
      }
      int cnt1=0,cnt2=0;
      int ok=1;
      //找出入度不等於出度的節點
      for(int i=0;i<100;i++){
        if(!ok)break;
        if(in[i]!=out[i]){
          if(in[i]==out[i]+1)cnt1++;
          else if(out[i]==in[i]+1)cnt2++;
          else {
            ok=0; break;
          }
        }
      }
      //判別是否只有兩個節點入度與出度不同
      if(cnt1 && cnt2 && cnt1+cnt2>2)ok=0;
  
      if(ok){
        memset(visit,0,sizeof(visit));
        for(int i=0;i<100;i++)
          if(out[i]){ //找到出發點,開始DFS
            dfs(i);
            break;
          }
        int ok2=1;
        for(int i=0;i<100;i++){
          if(in[i] && !visit[i]){ok2=0; break;}
          if(out[i] && !visit[i]){ok2=0; break;}
        }
        if(ok2){
          printf("Ordering is possible.\n");
        }
        else printf("The door cannot be opened.\n");
      }
      else printf("The door cannot be opened.\n");
                   
    }
    return 0;
}

//DFS確認是否連通
int dfs(int a){
    visit[a]=1;
    for(int i=0;i<100;i++){
        if(G[a][i] && !visit[i]){
          dfs(i);
        }
    }
}