• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            Why so serious? --[NKU]schindlerlee

            #

            pku2367 拓撲排序,做的人很少的簡單題。

            schindlerlee原創,禁止轉載和用于商業用途

            邊看 見過大爺 邊寫竟然5分鐘不到秒了~
            拓撲排序有兩種做法,一種是不斷找入度為0的點,然后刪點和關聯的邊,一種是利用dfs退棧的順序
            如下:
             1 /* 
             2  * SOUR:pku 2367
             3  * ALGO:top sort
             4  * DATE: Mon, 12 Oct 2009 00:56:07 +0800
             5  * COMM:2
             6  * */
             7 #include<iostream>
             8 #include<cstdio>
             9 #include<cstdlib>
            10 #include<cstring>
            11 #include<algorithm>
            12 #include<vector>
            13 using namespace std;
            14 typedef long long LL;
            15 const int maxint = 0x7fffffff;
            16 const long long max64 = 0x7fffffffffffffffll;
            17 #define pr(x) fprintf(stderr, x)
            18 /* #define pr(x) for(;0;) */
            19 const int N = 128;
            20 vector < int >g[N];
            21 int dfn[N], n, vis[N], st[N], top;
            22 
            23 void dfs(int u)
            24 {
            25     if (vis[u]) return;
            26     vis[u] = true;
            27     for (int i = 0; i < g[u].size(); i++) {
            28         dfs(g[u][i]);
            29     }
            30     st[top++= u;
            31 }
            32 
            33 int main()
            34 {
            35     int i, j, k, u, v;
            36     scanf("%d"&n);
            37     for (u = 1; u <= n; u++) {
            38         while (1) {
            39             scanf("%d"&v);
            40             if (0 == v)
            41                 break;
            42             g[u].push_back(v);
            43         }
            44     }
            45     for (u = 1; u <= n; u++) {
            46         if (!vis[u]) {
            47             dfs(u);
            48         }
            49     }
            50     for (i = top - 1; i > 0; i--) {
            51         printf("%d ", st[i]);
            52     }
            53     printf("%d\n", st[i]);
            54     return 0;
            55 }
            56 

            當出現環時,找入度為0的方法顯然當不能找到入度為0的點時且還有剩余點則有環
            利用dfs的方法就是找搜索樹種的回邊,利用染色的方法,算法導論上有介紹
            我寫的代碼如下:

            初始化:memset(vis,0,sizeof(vis));
            對所有vis[i] == 0,調用dfs
            bool dfs(int u)
            {
                if(vis[u] == 1) return false;
                if(vis[u] == 2) return true;
                vis[u] = 1;
                for(i = 0;i < g[u].size();i++) {
                    if(false == dfs(g[u][i])) {
                        return false;
                    }
                }
                vis[u] = 2;
                stack[top++] = u;
                return true;
            }
            下圖描述了dfs的過程,建議仔細體會一下,求圖的割點,橋,LCA的 tarjen算法主要過程基本和此dfs過程非常相似
            圖中白色是還未訪問的,黑色是已經完全訪問過的,藍色的是正在訪問的


            posted @ 2009-10-13 15:41 schindlerlee 閱讀(1290) | 評論 (1)編輯 收藏

            pku1696 點積叉積基礎應用

            又有好長時間沒寫了解題報告了,保研總算搞定了,月底去武漢,磨槍中....
              1 /* 
              2  * SOUR:pku 1696
              3  * ALGO:computional geometry
              4  * DATE: Tue, 13 Oct 2009 10:42:25 +0800
              5  * COMM:3
              6  * 叉積點積轉啊轉啊
              7  * */
              8 #include<iostream>
              9 #include<cstdio>
             10 #include<cstdlib>
             11 #include<cstring>
             12 #include<algorithm>
             13 #include<cmath>
             14 using namespace std;
             15 typedef long long LL;
             16 const int maxint = 0x7fffffff;
             17 const long long max64 = 0x7fffffffffffffffll;
             18 #define pr(x) fprintf(stderr, x)
             19 /* #define pr(x) for(;0;) */
             20 const int N = 128;
             21 struct point_t {
             22     int x, y, idx;
             23      point_t() {
             24     } point_t(int a, int b) {
             25         x = a, y = b;
             26     }
             27 } p[N], st[N];
             28 
             29 bool vis[N];
             30 
             31 #define sqr(x) ((x)*(x))
             32 double dist(point_t a)
             33 return sqrt(sqr(a.x) + sqr(a.y)); } 
             34 double dist(point_t a, point_t b)
             35 return sqrt(sqr(a.x - b.x) + sqr(a.y - b.y)); } 
             36 
             37 point_t operator +(point_t a, point_t b)
             38 return point_t(a.x + b.x, a.y + b.y); } 
             39 point_t operator -(point_t a, point_t b)
             40 return point_t(a.x - b.x, a.y - b.y); } 
             41 
             42 int cross_mul(point_t a, point_t b)
             43 return a.x * b.y - a.y * b.x; } 
             44 int cross_mul(point_t a, point_t b, point_t c)
             45 return cross_mul(a - c, b - c); } 
             46 int dot_mul(point_t a, point_t b)
             47 return a.x * b.x + a.y * b.y; } 
             48 int dot_mul(point_t a, point_t b, point_t c)
             49 return dot_mul(a - c, b - c); } 
             50 
             51 double angle(point_t a, point_t b)
             52 {
             53     double val = dot_mul(a, b);
             54     val /= dist(a);
             55     val /= dist(b);
             56     return val;
             57 }
             58 
             59 int n, idx, top;
             60 const int inf = (1 << 29);
             61 void graham()
             62 {
             63     int i, j, k;
             64     memset(vis, 0sizeof(vis));
             65     top = 2, st[0= p[0], st[1= p[1];
             66     vis[0= vis[1= true;
             67     for (i = 2; i <= n; i++) {
             68         double val = -inf;
             69         int idx;
             70         for (j = 2; j <= n; j++) {
             71             if (!vis[j]) {
             72                 int c = cross_mul(st[top - 1], p[j], st[top - 2]);
             73                 double d = angle(st[top - 1- st[top - 2], p[j] - st[top - 1]);
             74                 if (c > 0) {
             75                     if ((d > val) || (d == val && dist(p[j], st[top - 1]) < dist(p[idx], st[top - 1]))) {
             76                         idx = j;
             77                         val = d;
             78                     }
             79                 }
             80             }
             81         }
             82         if (val == -inf)
             83             break;
             84         st[top++= p[idx], vis[idx] = true;
             85     }
             86 }
             87 
             88 int main()
             89 {
             90     int i, j, k, testid;
             91     scanf("%d"&testid);
             92     while (testid-- > 0) {
             93         scanf("%d"&n);
             94         idx = 1;
             95         scanf("%d%d%d"&p[1].idx, &p[1].x, &p[1].y);
             96         for (i = 2; i <= n; i++) {
             97             scanf("%d%d%d"&p[i].idx, &p[i].x, &p[i].y);
             98             if ((p[i].y < p[idx].y) || (p[i].y == p[idx].y && p[i].x < p[idx].x)) {
             99                 idx = i;
            100             }
            101         }
            102         swap(p[1], p[idx]);
            103         p[0].idx = 0, p[0].x = 0, p[0].y = p[1].y;
            104         graham();
            105         printf("%d", top - 1);
            106         for (i = 1; i < top - 1; i++) {
            107             printf(" %d", st[i].idx);
            108         }
            109         printf(" %d\n", st[i].idx);
            110     }
            111     return 0;
            112 }
            113 

            posted @ 2009-10-13 15:15 schindlerlee 閱讀(1198) | 評論 (0)編輯 收藏

            pku1505 AC此題分4步

            國家集訓隊2000論文集/方奇論文中的一題
            1.dp ,算最小完成時間, 論文中貌似把max寫成min了。。
            二分求最小完成時間亦可,而且更快,誰讓咱們看了論文了呢
            for(i = 1;i <= n;i++) {
                dp[1][i] = sum[1][i];
            }
            for(i = 2;i <= m;i++) {
                for(j = 1;j <= n;j++) {
                    dp[i][j] = inf;
                }
            }

            for(i = 2;i <= m;i++) {
                for(j = i;j <= n;j++) {
                    for(k = 1;k < j;k++) { // 至少抄一本
                        int t = max( dp[i-1][k] , sum[k+1][j]);
                        if(dp[i][j] > t) {
                            dp[i][j] = min(dp[i][j] ,t);
                        }
                    }
                }
            }
            2.從后向前推把更大的工作量留給后面的人,標記'/'出現的位置

            int limit = dp[m][n],sum,cnt;
            pre[n] = 0,cnt = 1;
            for(i = n-1,sum = num[n];i > 0;i--) {
                if(sum + num[i] > limit) {
                    pre[i] = 1;
                    cnt ++;
                    sum = num[i];
                }else {
                    pre[i] = 0;
                    sum += num[i];
                }
            }
            3.如果'/'的數量小于題目給出的,從頭尋找第一個不是'/'的位置,標記之
            for(i = 1,j = cnt;j < m && i <= n;i++) {
                if(pre[i] == 0) {
                    pre[i] = 1;
                    j++;
                }
            }
            4.輸出
            for(i = 1;i < n;i++) {
                printf("%d ",num[i]);
                if(pre[i])
                    printf("/ ");
            }
            printf("%d\n",num[i]);

            注意:不要嘗試再dp轉移的時候標記轉移方向,試圖得出標記‘/’的位置,這個想法是錯的,仔細想一下就知道了,
            再不濟AC以后再試試

            posted @ 2009-09-16 01:32 schindlerlee 閱讀(1238) | 評論 (0)編輯 收藏

            pku1220

            schindlerlee原創,禁止轉載和用于商業用途

            此題意思很明顯
            把一個數從進制a轉化到進制b
            用C/C++寫實在是太麻煩了,用java搞了一下,還是不熟啊,寫了好久
             1 //java catalan 數
             2 import java.math.*;
             3 import java.util.*;
             4 import java.io.*;
             5 
             6 public class Main {
             7 
             8     public static void main(String[] args) {
             9         Scanner cin = new Scanner(
            10                 new BufferedReader(
            11                 new InputStreamReader(System.in)));
            12         //That is (in decimal) A = 10, B = 11, , Z = 35, a = 36, b = 37, , z = 61
            13         int c = cin.nextInt();
            14         while (c-- > 0) {
            15             int a = cin.nextInt();
            16             int b = cin.nextInt();
            17             BigInteger r = BigInteger.valueOf(0);
            18             BigInteger idx = BigInteger.valueOf(1);
            19             String s = cin.next();
            20             System.out.println(a + " " + s);
            21             for (int i = s.length() - 1; i >= 0; i--, idx = idx.multiply(BigInteger.valueOf(a))) {
            22                 char t = s.charAt(i);
            23                 //8 62 2 abcdefghiz  System.out.println("char t = " + t);
            24                 int add;
            25                 if (t >= '0' && t <= '9') {
            26                     add = t - '0';
            27                 } else if (t >= 'A' && t <= 'Z') {
            28                     add = t - 'A' + 10;
            29                 } else {
            30                     add = t - 'a' + 36;
            31                 }
            32                 r = r.add(idx.multiply(BigInteger.valueOf(add)));
            33             }
            34 
            35             //  System.out.println(r.toString());
            36             String res = "";
            37             idx = BigInteger.valueOf(b);
            38             if (s.equals("0")) {
            39                 System.out.println(b + " 0");
            40             } else {
            41                 while (r.compareTo(BigInteger.ZERO) > 0) {
            42                     BigInteger ad[];
            43                     ad = r.divideAndRemainder(idx);
            44                     r = ad[0];
            45                     int t = ad[1].intValue();
            46                     char ch;
            47                     if (t >= 0 && t <= 9) {
            48                         ch = (char) (t + '0');
            49                     } else if (t >= 10 && t <= 35) {
            50                         ch = (char) (t - 10 + 'A');
            51                     } else {
            52                         ch = (char) (t - 36 + 'a');
            53                     }
            54                     res = ch + res;
            55                 //     System.out.println("ad[0]= "+ad[0]);
            56                 //     System.out.println("ad[1]= "+ad[1]);
            57                 }
            58                 System.out.println(b + " " + res);
            59             }
            60             System.out.print('\n');
            61         //System.out.println("res = "+res);
            62         }
            63     }
            64 }
            65 
            66 


            posted @ 2009-09-10 21:32 schindlerlee 閱讀(1079) | 評論 (0)編輯 收藏

            pku2111 Millenium Leapcow

            schindlerlee原創,禁止轉載和用于商業用途

            題目描述:

            給定一個矩陣,找一個起始點,由該點開始不斷馬跳,要求跳到的后一節點比前一節點的值大,問最多可以跳多少步,并且輸出跳躍的序列,如果兩個跳躍序列步數相同,給出字典序較小的

            1 2 4

            1 2 3

            兩個序列當然是后一個較小

             

            第一感覺可以求出每個節點的跳躍序列,比較長度得出結果。但是我們發現其中有很多重復的路徑,由此想到dp。

             

            本來此題如果只要求最長的跳躍步數的話,就是一道比較簡單的dp了。但是題目要求輸出最小的序列,需要稍微復雜一點的處理。

            可以考慮為每個點增加一個pre坐標,指向前一個點,但是這就帶來一個問題,要尋找最小的序列,如果有兩個相同長度的序列可供當前點選擇的話,直接貪心是錯誤的,下圖為反例


            可以發現,如果只比較前一點的話,左邊的路線是正確的,但是實際上右邊的是正確的。注意這一點基本就沒問題了。

              1 /* 
              2  * SOUR:pku 2111
              3  * ALGO:dp or search
              4  * DATE: 2009年 08月 29日 星期六 04:16:26 CST
              5  * COMM:
              6  * */
              7 #include<iostream>
              8 #include<cstdio>
              9 #include<cstdlib>
             10 #include<cstring>
             11 #include<algorithm>
             12 using namespace std;
             13 const int maxint = 0x7fffffff;
             14 const long long max64 = 0x7fffffffffffffffll;
             15 #define debug 1
             16 const int N = 410;
             17 int mov[8][2= { {12}, {21}, {-12}, {2-1},    //
             18 {1-2}, {-21}, {-1-2}, {-2-1}
             19 };
             20 
             21 int g[N][N], pre[N][N][2], n, dp[N][N], out[N], on;
             22 struct L {
             23     int x, y;
             24     int val;
             25 } query[N * N];
             26 bool operator <(L a, L b)
             27 {
             28     return a.val < b.val;
             29 }
             30 int a[N*N],b[N*N];
             31 bool judge(int tx,int ty,int px,int py) 
             32 {
             33     int sp = 0,ta,tb,i;
             34     while(tx != -1) {
             35         a[sp] = g[tx][ty];
             36         b[sp] = g[px][py];
             37         sp ++;
             38         ta = pre[tx][ty][0];
             39         tb = pre[tx][ty][1];
             40         tx = ta,ty = tb;
             41 
             42         ta = pre[px][py][0];
             43         tb = pre[px][py][1];
             44         px = ta,py = tb;
             45     }
             46     for(i = sp - 1;i >= 0 && a[i] == b[i];i--);
             47     if(a[i] < b[i])
             48         return true;
             49     return false;
             50 }
             51 
             52 int main()
             53 {
             54     int i, j, k, x, y, big, tx, ty;
             55     scanf("%d"&n);
             56     for (i = 0; i < n; i++) {
             57         for (j = 0; j < n; j++) {
             58             scanf("%d"&g[i][j]);
             59             query[i * n + j].val = g[i][j];
             60             query[i * n + j].x = i;
             61             query[i * n + j].y = j;
             62             pre[i][j][0= pre[i][j][1= -1;
             63         }
             64     }
             65 
             66     sort(query, query + n * n);
             67     for (i = 0; i < n * n; i++) {
             68         x = query[i].x;
             69         y = query[i].y;
             70         for (j = 0; j < 8; j++) {
             71             int tx = x + mov[j][0];
             72             int ty = y + mov[j][1];
             73             if (tx >= 0 && tx < n && ty >= 0 && ty < n
             74                 && g[x][y] > g[tx][ty]) {
             75                 if (dp[x][y] < dp[tx][ty] + 1) {
             76                     dp[x][y] = dp[tx][ty] + 1;
             77                     pre[x][y][0= tx;
             78                     pre[x][y][1= ty;
             79                 } else if (dp[x][y] == dp[tx][ty] + 1) {
             80                     int px = pre[x][y][0];
             81                     int py = pre[x][y][1];
             82                     if (judge(tx,ty,px,py)) {
             83                         pre[x][y][0= tx;
             84                         pre[x][y][1= ty;
             85                     }
             86                 }
             87             }
             88         }
             89     }
             90     on = 0, big = 0;
             91     for (i = 0; i < n; i++) {
             92         for (j = 0; j < n; j++) {
             93             if (dp[i][j] > big) {
             94                 big = dp[i][j];
             95                 x = i, y = j;
             96             }
             97         }
             98     }
             99     while (x != -1 && y != -1) {
            100         out[on++= g[x][y];
            101         tx = pre[x][y][0];
            102         ty = pre[x][y][1];
            103         x = tx, y = ty;
            104     }
            105     printf("%d\n", on);
            106     for (i = on - 1; i >= 0; i--) {
            107         printf("%d\n"out[i]);
            108     }
            109     return 0;
            110 }
            111 

             

            posted @ 2009-08-29 23:02 schindlerlee 閱讀(1210) | 評論 (0)編輯 收藏

            pku3744

            schindlerlee原創,禁止轉載和用于商業用途
            剛比賽完,先貼代碼
              1 /* 
              2  * SOUR:pku 3744
              3  * ALGO:compulicted
              4  * DATE: 2009年 08月 23日 星期日 12:37:44 CST
              5  * COMM:3
              6  * */
              7 #include<iostream>
              8 #include<cstdio>
              9 #include<cstdlib>
             10 #include<cstring>
             11 #include<algorithm>
             12 using namespace std;
             13 #define inf 0x7fffffff
             14 #define debug 1
             15 double p;
             16 int mine[26], n;
             17 
             18 struct M {
             19     double v11, v12, v21, v22;
             20     M operator*( M b)
             21     {
             22         M c;
             23         c.v11 = v11 * b.v11 + v12 * b.v21;
             24         c.v12 = v11 * b.v12 + v12 * b.v22;
             25         c.v21 = v21 * b.v11 + v22 * b.v21;
             26         c.v22 = v21 * b.v12 + v22 * b.v22;
             27         return c;
             28     }
             29 
             30     M operator*double c)
             31     {
             32         v11 *= c, v12 *= c;
             33         v21 *= c, v22 *= c;
             34         return *this;
             35     }
             36 } unit,self;
             37 
             38 
             39 M f(int t)
             40 {
             41     if (t == 0) {
             42         M a;
             43         a.v11 = 1, a.v12 = 0;
             44         a.v21 = 0, a.v22 = 1;
             45         return a;
             46     }
             47     if (t == 1) {
             48         return unit;
             49     }
             50     if (t % 2 == 0) {
             51         M tmp = f(t / 2);
             52         return tmp * tmp;
             53     }
             54     M tmp = f(t / 2);
             55     return tmp * tmp * unit;
             56 }
             57 
             58 /*
             59  f(n)      { p ,1-p }    f(n-1)   
             60  f(n-1) =  { 1 , 0  } *  f(n-2)
             61  * */
             62 int main()
             63 {
             64     int i, j;
             65     while (scanf("%d %lf"&n, &p) == 2) {
             66         unit.v11 = p, unit.v12 = 1 - p;
             67         unit.v21 = 1, unit.v22 = 0;
             68 
             69         self.v11 = 1, self.v12 = 0;
             70         self.v21 = 0, self.v22 = 1;
             71 
             72         bool flag = false;
             73         for (i = 0; i < n; i++) {
             74             scanf("%d", mine + i);
             75         }
             76         sort(mine, mine + n);
             77         n = unique(mine, mine + n) - mine;
             78         for (i = 1; i < n; i++) {
             79             if (mine[i] - mine[i - 1== 1) {
             80                 flag = true;
             81                 break;
             82             }
             83         }
             84         if (flag || mine[0== 1) {
             85             printf("%.7f\n"0.0);
             86             continue;
             87         }
             88         int t = 1;
             89         M res = self, tmp;
             90         for (i = 0; i < n; i++) {
             91             tmp = f(mine[i] - 1 - t);
             92             t = mine[i] + 1;
             93             res = res * tmp * (1 - p);
             94             res.v12 = 0//跳地雷
             95         }
             96         if(res.v11 <= 0) {
             97             printf("%.7f\n"0.0);
             98         }else {
             99             printf("%.7f\n", res.v11);
            100         }
            101     }
            102     return 0;
            103 }
            104 

            posted @ 2009-08-23 18:50 schindlerlee 閱讀(1296) | 評論 (0)編輯 收藏

            pku1451 trie樹

            很久沒更新了,題刷了不少,但是一直沒怎么總結先貼一篇
              1
             /* 
              2  * SOUR:pku 1451
              3  * ALGO:trie
              4  * DATE: 2009年 08月 17日 星期一 13:29:46 CST
              5  * COMM:3
              6  * */
              7 #include<iostream>
              8 #include<cstdio>
              9 #include<cstdlib>
             10 #include<cstring>
             11 #include<algorithm>
             12 using namespace std;
             13 #define inf 0x7fffffff
             14 #define debug 1
             15 const int N = 1000 * 11;
             16 int mov[10][5=
             17     { {-1}, {-1}, {012-1}, {345-1}, {678-1}, {91011-1},
             18 {121314-1}, {15161718-1}, {192021-1}, {22232425-1}
             19 };
             20 
             21 struct Trie {
             22     int c;
             23     Trie *next[26];
             24      Trie() {
             25         c = 0;
             26         memset(next, 0sizeof(next));
             27     }
             28     void insert(char *s, int f);
             29     void getMax(char *s, int step, int len);
             30 *root, pool[N];
             31 int pt;
             32 void Trie::insert(char *s, int f)
             33 {
             34     c += f;
             35     if (*== 0)
             36         return;
             37     if (next[*- 'a'== NULL) {
             38         next[*- 'a'= &pool[pt++];
             39     }
             40     next[*- 'a']->insert(s + 1, f);
             41 }
             42 
             43 char tmp[61], res[61];
             44 int freq;
             45 void Trie::getMax(char *s, int step, int len)
             46 {
             47     if (step >= len) {
             48         tmp[len] = 0;
             49         if (c > freq) {
             50             //strcpy(res, tmp);
             51             for (int i = 0; i <= len; i++) {
             52                 res[i] = tmp[i];
             53             }
             54             freq = c;
             55         }
             56         return;
             57     }
             58 
             59     int idx;
             60     for (int i = 0; mov[*- '0'][i] >= 0; i++) {
             61         idx = mov[*- '0'][i];
             62         if (next[idx] != NULL) {
             63             tmp[step] = idx + 'a';
             64             next[idx]->getMax(s + 1, step + 1, len);
             65         }
             66     }
             67 }
             68 
             69 int main()
             70 {
             71     int i, k, C, D, f;
             72     char buf[30];
             73     scanf("%d"&C);
             74     for (k = 1; k <= C; k++) {
             75         root = &pool[0];
             76         pt = 1, memset(pool, 0sizeof(pool));
             77         printf("Scenario #%d:\n", k);
             78         scanf("%d"&D);
             79         while (D-- > 0) {
             80             scanf("%s %d", buf, &f); //哥一開始buf開小了,報了stack smashing 。。。。。。。。
             81             root->insert(buf, f);
             82         }
             83         scanf("%d"&D), getchar();
             84         while (D-- > 0) {
             85             scanf("%s", buf);
             86             buf[strlen(buf) - 1= 0;
             87 
             88             int len = strlen(buf);
             89             for (i = 1; i <= len; i++) {
             90                 freq = 0;
             91                 root->getMax(buf, 0, i);
             92                 if (freq > 0) {
             93                     printf("%s\n", res);
             94                 } else {
             95                     puts("MANUALLY");
             96                 }
             97             }
             98             printf("\n");
             99         }
            100         printf("\n");
            101     }
            102     return 0;
            103 }
            104 

            posted @ 2009-08-17 22:26 schindlerlee 閱讀(1565) | 評論 (2)編輯 收藏

            發現一個超好用的vim 插件

            autocomplpop.vim
            http://www.vim.org/scripts/script.php?script_id=1879

            把omnicomplete 裝上,再裝上這個,加上兩個不去分大小寫的選項
            let g:AutoComplPop_IgnoreCaseOption=1
            set ignorecase



            哇,邊打字,邊補全

            posted @ 2009-06-13 22:47 schindlerlee 閱讀(3285) | 評論 (2)編輯 收藏

            一個高精度乘法的例子

            文本是schindlerlee原創,查看原文請訪問
            m.shnenglu.com/schindlerlee
            轉載請保留此信息,本人保留關于本文的一切信息
            const int PRECISION = 525;
            const int SENTINAL = 0x7fffffff;

            struct bignum {
                
            int s[PRECISION];
                
            int len;
                
            void reset() {
                    
            for (int i = 0; i < PRECISION; i++) {
                        s[i] 
            = SENTINAL;
                    } len 
            = 0;
                }
            };

            void justify(bignum & a, int step)
                
            /*
                 * 調整乘法產生的結果
                 * 例如將:
                 *-------------------------------------------------------------
                 *| 64 | 64 |SENT|SENT|SENT|SENT|SENT|SENT|SENT|SENT|SENT|SENT|
                 *-------------------------------------------------------------
                 *調整為
                 *-------------------------------------------------------------
                 *| 4  | 0  | 7  |SENT|SENT|SENT|SENT|SENT|SENT|SENT|SENT|SENT|
                 *-------------------------------------------------------------
                 * 
            */
            {
                
            if (step < PRECISION && a.s[step] != SENTINAL) {
                    
            if (a.s[step] > 9) {
                        
            if (a.s[step + 1== SENTINAL)
                            a.s[step 
            + 1= 0;
                        a.s[step 
            + 1+= a.s[step] / 10;
                        a.s[step] 
            = a.s[step] % 10;
                    }
                    justify(a, step 
            + 1);
                } 
            else {
                    a.len 
            = step;
                    
            for (int i = step; i < PRECISION; i++) {
                        a.s[i] 
            = SENTINAL;
                    }
                }
            }

            void mul(bignum a, bignum b, bignum & c)    //a b result
            {
                
            int i, j;
                c.reset();
                
            for (i = 0; i < a.len; i++) {
                    
            for (j = 0; j < b.len; j++) {
                        
            if(i+< PRECISION) {
                            
            if (c.s[i + j] == SENTINAL) c.s[i + j] = 0;
                            c.s[i 
            + j] += a.s[i] * b.s[j];
                        }
                    }
                }
                justify(c, 
            0);
            }

            posted @ 2009-05-28 11:08 schindlerlee 閱讀(330) | 評論 (0)編輯 收藏

            筆記本ubuntu掛起后無法啟動


            看到網上寫的很多說裝pm-utils之類的。但是我的情況是,休眠以后系統根本就啟動不了,直接黑屏在那里了。

            也有人寫把主板電池扣下來放電,我是筆記本,也不太現實。

            想進windows試試,無意中發現grub菜單中有recovery mode ,選進去,一切解決。。。。。。。。。。。

            原來一切是如此簡單,反正我是重啟了n次。。。。

            posted @ 2009-04-27 13:47 schindlerlee 閱讀(1401) | 評論 (3)編輯 收藏

            自己寫的貪食蛇

                 摘要: ubuntu下寫的,在linux shell可運行 ,想編譯請安裝  libncurses5-dbg libncurses5-dev使用參數 : g++ -lcurses  snake.c 編譯方向鍵使用vim 默認的hjkl進行移動,可以熟悉vim的方向鍵菜單中  L 是確定  ,游戲中q是退出 Code highlighting produced by...  閱讀全文

            posted @ 2009-04-05 18:29 schindlerlee 閱讀(1445) | 評論 (0)編輯 收藏

            使用emerald

            切換使用emerald的主題

            按alt-f2

            執行

            emerald --replace

            切換回原來的主題

            按alt-f2

            執行

            metacity --replace

            posted @ 2009-03-10 01:24 schindlerlee 閱讀(165) | 評論 (0)編輯 收藏

            ubuntu把ape文件轉換成mp3文件

            在ubuntu把ape文件轉換成mp3文件一直都是一個問題。
            昨天第一次使用linux進行這項工作,現在將方法記錄如下。

            # 安裝soundconverter和mp3splt
            # 使用soundconverter將ape文件轉換成一個mp3文件
            # 使用mp3splt 分割生成的單個mp3文件
            使用命令
             mp3splt -c CDImage.cue -o @n.@t a.mp3

             @n是音軌號
             @t是音軌標題

             其中的信息都是根據CDImage.cue文件中來的。
             還有其他參數可選,具體參見
             man mp3splt



            posted @ 2009-03-02 00:33 schindlerlee 閱讀(1236) | 評論 (0)編輯 收藏

            linux下使用at命令定時關機

            首先創建一個文件
            寫入

            #!/bin/sh

            shutdown -h  now

            保存為power文件
            之后
            chmod +x power
            之后就能使用定時關機了
            但是需要有root權限才能關機
            所以需要輸入的命令如下
            sudo at 02:00 tomorrow -f power
            之后使用
            sudo atq
            可以查選定時執行的任務
            sudo atrm
            可以刪除已經預定好的任務

            posted @ 2009-02-27 22:39 schindlerlee 閱讀(634) | 評論 (0)編輯 收藏

            linux下使用indent整理代碼


            indent是linux下一個能力極強的代碼整理軟件,使用他,可以輕松的寫出代碼風格十分精良的代碼。
            但是indent的參數太多,使用起來不是很容易,怎么辦呢?

            查看
            /usr/src/linux-headers-<版本>/scripts/Lindent
            文件 ,可以看到一行代碼:

            indent -npro -kr -i8 -ts8 -sob -l80 -ss -ncs -cp1


            這一行就是linux內核使用indent整理代碼的格式,使用這條命令就可以實現風格十分良好的C或C++代碼

            其中-l80是每一行最多80個字母,超出會拆行,如果不喜歡可以使用更長的行字數


            posted @ 2009-02-27 22:22 schindlerlee 閱讀(1179) | 評論 (0)編輯 收藏

            僅列出標題
            共7頁: 1 2 3 4 5 6 7 
            久久99国产精品99久久| 久久久久人妻精品一区二区三区| 久久久精品2019免费观看| 精品国产91久久久久久久a | 久久w5ww成w人免费| 色婷婷综合久久久久中文字幕 | 久久精品国产99久久久古代 | 国产三级久久久精品麻豆三级| 久久久久久免费视频| 精品久久久久久久中文字幕| 狠狠色丁香久久婷婷综合五月| 99精品国产综合久久久久五月天 | 精品久久久久久久国产潘金莲 | 欧美一级久久久久久久大| 婷婷久久综合| 久久婷婷五月综合国产尤物app| 欧美午夜精品久久久久免费视| 国产99精品久久| 无码AV中文字幕久久专区| 久久免费精品视频| 色狠狠久久AV五月综合| 国产亚洲婷婷香蕉久久精品| 国内精品久久久久久不卡影院 | 亚洲美日韩Av中文字幕无码久久久妻妇 | 久久这里只精品国产99热| 777午夜精品久久av蜜臀 | 久久精品视频一| 久久无码av三级| 国产一区二区精品久久岳| 亚洲国产成人精品女人久久久 | 久久伊人色| 精品一区二区久久| 人妻无码精品久久亚瑟影视| 久久精品成人| 欧美日韩精品久久免费| 精品综合久久久久久98| 亚洲精品美女久久久久99小说| 久久精品国产亚洲av麻豆图片| 久久国产精品久久| 一极黄色视频久久网站| 无码伊人66久久大杳蕉网站谷歌 |