• <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>

            superman

            聚精會神搞建設 一心一意謀發展
            posts - 190, comments - 17, trackbacks - 0, articles - 0
               :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理

             1 /* Accepted 2050 C++ 00:00.02 920K */
             2 #include <queue>
             3 #include <stdio.h>
             4 #include <iostream>
             5 
             6 using namespace std;
             7 
             8 struct rec { int n, m; };
             9 
            10 int main()
            11 {
            12     int N;
            13     cin >> N;
            14     while(N--)
            15     {
            16         int n = 0char c;
            17         for(int i = 0; i < 16; i++)
            18         {
            19             cin.get(c);
            20             if(c == '\n')
            21             {
            22                 i--;
            23                 continue;
            24             }
            25             if(c == 'b')
            26                 n |= (1 << i);
            27         }
            28         
            29         rec cur = {n, 0};
            30         queue <rec> q;
            31         q.push(cur);
            32         
            33         bool repeat[65536= {false}, find = false;
            34         while(q.empty() == false)
            35         {
            36             cur = q.front(); q.pop();
            37             
            38             if(cur.n == 0 || cur.n == 65535)
            39             {
            40                 cout << cur.m << endl;
            41                 find = true;
            42                 break;
            43             }
            44             
            45             for(int i = 0; i < 16; i++)
            46             {
            47                 int t = cur.n;
            48                 
            49                 t ^= (1 << i);
            50                 if(i - 4 >= 0)
            51                     t ^= (1 << (i - 4));
            52                 if(i + 4 < 16)
            53                     t ^= (1 << (i + 4));
            54                 if(i % 4 - 1 >= 0)
            55                     t ^= (1 << (i - 1));
            56                 if(i % 4 + 1 < 4)
            57                     t ^= (1 << (i + 1));
            58                 
            59                 if(repeat[t] == false)
            60                 {
            61                     repeat[t] = true;
            62                     rec tmp = {t, cur.m + 1};
            63                     q.push(tmp);
            64                 }
            65             }
            66         }
            67         
            68         if(find == false)
            69             cout << "Impossible" << endl;
            70         if(N)
            71             cout << endl;
            72     }
            73     
            74     return 0;
            75 }
            76 

            posted @ 2008-05-20 14:20 superman 閱讀(252) | 評論 (0)編輯 收藏

             1 /* Accepted 816K 829MS G++ 899B */
             2 #include <iostream>
             3 
             4 using namespace std;
             5 
             6 int main()
             7 {
             8     int n, m, x[100000];
             9     
            10     cin >> n >> m;
            11     for(int i = 0; i < n; i++)
            12         cin >> x[i];
            13     
            14     int sum = 0;
            15     for(int i = 0; i < n; i++)
            16         sum += x[i];
            17     
            18     int l = 0, r = sum;
            19     while(l + 1 < r)
            20     {
            21         int mid = (l + r) / 2;
            22         
            23         int i, cnt = 0, left = mid;
            24         
            25         for(i = 0; i < n && cnt < m; i++)
            26         {
            27             if(x[i] > mid)
            28                 break;
            29             if(left - x[i] >= 0)
            30                 left -= x[i];
            31             else
            32             {
            33                 cnt++;
            34                 left = mid - x[i];
            35             }
            36         }
            37         
            38         if(i == n)
            39             r = mid;
            40         else
            41             l = mid;
            42     }
            43     
            44     cout << r << endl;
            45     
            46     return 0;
            47 }
            48 

            posted @ 2008-05-20 09:58 superman 閱讀(564) | 評論 (0)編輯 收藏

                 摘要:   1 /* Accepted 1190 C++ 00:00.48 28620K */  2 #include <iostream>  3   4 using namespace ...  閱讀全文

            posted @ 2008-05-19 15:53 superman 閱讀(448) | 評論 (0)編輯 收藏

             1 /* Accepted 1278 C++ 00:00.00 840K */
             2 #include <iostream>
             3 
             4 using namespace std;
             5 
             6 int main()
             7 {
             8     int z, i, m; bool x[10000];
             9     
            10     int last, next, cnt, n = 1;
            11     while(cin >> z >> i >> m >> last)
            12     {
            13         if(z == 0 && i == 0 && m == 0 && last == 0)
            14             break;
            15         
            16         memset(x, falsesizeof(x));
            17         
            18         cnt = 0;
            19         while(true)
            20         {
            21             next = (z * last + i) % m;
            22             
            23             if(x[next])
            24                 break;
            25             
            26             last = next;
            27             x[next] = true;
            28             
            29             cnt++;
            30         }
            31         
            32         cout << "Case " << n++ << ""  << cnt << endl; 
            33     }
            34     
            35     return 0;
            36 }
            37 

            posted @ 2008-05-14 20:10 superman 閱讀(473) | 評論 (0)編輯 收藏

              1 /* Accepted 1279 C++ 00:00.00 840K */
              2 #include <iostream>
              3 
              4 using namespace std;
              5 
              6 int main()
              7 {
              8     int N;
              9     cin >> N;
             10     
             11     cout << "COWCULATIONS OUTPUT" << endl;
             12     
             13     while(N--)
             14     {
             15         char a[8], b[8], d[8], op;
             16         char alen = 0, blen = 0, dlen = 0;
             17         
             18         memset(a, 0sizeof(a));
             19         memset(b, 0sizeof(b));
             20         memset(d, 0sizeof(d));
             21         
             22         string s;
             23         
             24         cin >> s;
             25         {
             26             int i = 0;
             27             while(s[i] == 'V')
             28                 i++;
             29             int p = 0;
             30             while(i < 5)
             31                 a[p++= s[i++];
             32             alen = p;
             33         }
             34         for(int i = 0; i < alen / 2; i++)
             35             swap(a[i], a[alen - i - 1]);
             36         for(int i = 0; i < alen; i++)
             37             switch(a[i])
             38             {
             39                 case 'V' : a[i] = 0break;
             40                 case 'U' : a[i] = 1break;
             41                 case 'C' : a[i] = 2break;
             42                 case 'D' : a[i] = 3break;
             43             }
             44         
             45         cin >> s;
             46         {
             47             int i = 0;
             48             while(s[i] == 'V')
             49                 i++;
             50             int p = 0;
             51             while(i < 5)
             52                 b[p++= s[i++];
             53             blen = p;
             54         }
             55         for(int i = 0; i < blen / 2; i++)
             56             swap(b[i], b[blen - i - 1]);
             57         for(int i = 0; i < blen; i++)
             58             switch(b[i])
             59             {
             60                 case 'V' : b[i] = 0break;
             61                 case 'U' : b[i] = 1break;
             62                 case 'C' : b[i] = 2break;
             63                 case 'D' : b[i] = 3break;
             64             }
             65         
             66         //compute
             67         for(int k = 0; k < 3; k++)
             68         {
             69             cin >> op;
             70             if(op == 'A')
             71             {
             72                 char c[6], clen;
             73                 memset(c, 0sizeof(c));
             74                 
             75                 clen = max(alen, blen);
             76                 for(int i = 0; i < clen; i++)
             77                     c[i] = a[i] + b[i];
             78                 for(int i = 0; i < clen; i++)
             79                     c[i + 1+= c[i] / 4, c[i] %= 4;
             80                 
             81                 if(c[clen])
             82                     clen++;
             83                 
             84                 blen = clen;
             85                 memcpy(b, c, sizeof(c));
             86             }
             87             if(op == 'L')
             88             {
             89                 for(int i = blen; i >= 1; i--)
             90                     b[i] = b[i - 1];
             91                 b[0= 0;
             92                 blen++;
             93             }
             94             if(op == 'R')
             95             {
             96                 for(int i = 0; i < blen - 1; i++)
             97                     b[i] = b[i + 1];
             98                 b[blen - 1= 0;
             99                 blen--;
            100             }
            101         }
            102         
            103         cin >> s;
            104         {
            105             int i = 0;
            106             while(s[i] == 'V')
            107                 i++;
            108             int p = 0;
            109             while(i < 8)
            110                 d[p++= s[i++];
            111             dlen = p;
            112         }
            113         for(int i = 0; i < dlen / 2; i++)
            114             swap(d[i], d[dlen - i - 1]);
            115         for(int i = 0; i < dlen; i++)
            116             switch(d[i])
            117             {
            118                 case 'V' : d[i] = 0break;
            119                 case 'U' : d[i] = 1break;
            120                 case 'C' : d[i] = 2break;
            121                 case 'D' : d[i] = 3break;
            122             }
            123         
            124         if(blen == dlen)
            125         {
            126             int i;
            127             for(i = 0; i < blen; i++)
            128                 if(b[i] != d[i])
            129                 {
            130                     cout << "NO" << endl; break;
            131                 }
            132             if(i == blen)
            133                 cout << "YES" << endl;
            134         }
            135         else
            136             cout << "NO" << endl;
            137     }
            138     
            139     cout << "END OF OUTPUT" << endl;
            140     
            141     return 0;
            142 }
            143 

            posted @ 2008-05-14 18:14 superman 閱讀(191) | 評論 (0)編輯 收藏

             1 /* Accepted 1293 C++ 00:00.00 836K */
             2 #include <iostream>
             3 
             4 using namespace std;
             5 
             6 int main()
             7 {
             8     int n, cnt = 0;
             9     while((cin >> n) && n)
            10     {
            11         n = int(n / 2.0 + 0.5);
            12         n = n + int(n / 2.0 + 0.5);
            13         
            14         if(n % 62 == 0)
            15             n /= 62;
            16         else
            17             n = n / 62 + 1;
            18         
            19         if(n % 30000 == 0)
            20             n /= 30000;
            21         else
            22             n = n / 30000 + 1;
            23         
            24         cnt++;
            25         cout << "File #" << cnt << endl;
            26         cout << "John needs " << n  << " floppies." << endl << endl;
            27     }
            28     
            29     return 0;
            30 }
            31 

            posted @ 2008-05-14 12:12 superman 閱讀(264) | 評論 (0)編輯 收藏

             1 /* Accepted 1290 C++ 00:00.01 2988K */
             2 #include <iostream>
             3 
             4 using namespace std;
             5 
             6 int n;
             7 char m[100][100];
             8 struct { int x, y; } dir[8= {
             9     {-10}, {-1+1}, {0+1}, {+1+1},
            10     {+10}, {+1-1}, {0-1}, {-1-1}
            11 };
            12 
            13 bool match(int x, int y, int d, string s)
            14 {
            15     if(d == 0 && x - s.size() + 1 < 0)
            16         return false;
            17     if(d == 1 && (x - s.size() + 1 < 0 || y + s.size() - 1 >= n))
            18         return false;
            19     if(d == 2 && y + s.size() - 1 >= n)
            20         return false;
            21     if(d == 3 && (x + s.size() - 1 >= n || y + s.size() - 1 >= n))
            22         return false;
            23     if(d == 4 && x + s.size() - 1 >= n)
            24         return false;
            25     if(d == 5 && (x + s.size() - 1 >= n || y - s.size() + 1 < 0))
            26         return false;
            27     if(d == 6 && y - s.size() + 1 < 0)
            28         return false;
            29     if(d == 7 && (x - s.size() + 1 < 0 || y - s.size() + 1 < 0))
            30         return false;
            31     
            32     for(int i = 1; i < s.size(); i++)
            33     {
            34         x += dir[d].x, y += dir[d].y;
            35         if(s[i] != m[x][y])
            36             return false;
            37     }
            38     return true;
            39 }
            40 
            41 int main()
            42 {
            43     int N;
            44     cin >> N;
            45     while(N--)
            46     {
            47         cin >> n;
            48         for(int i = 0; i < n; i++)
            49         for(int j = 0; j < n; j++)
            50             cin >> m[i][j];
            51 
            52         string word;
            53         while(cin >> word)
            54         {
            55             if(word == "0")
            56                 break;
            57             
            58             bool found = false;
            59             for(int i = 0; i < n; i++)
            60             for(int j = 0; j < n; j++)
            61                 if(word[0== m[i][j])
            62                     for(int k = 0; k < 8; k++)
            63                     {
            64                         if(match(i, j, k, word))
            65                         {
            66                             cout << i + 1 << ',' << j + 1 << ' ';
            67                             
            68                             if(k != 2 && k != 6)
            69                                 cout << i + 1 + dir[k].x * (word.size() - 1<< ',';
            70                             else cout << i + 1 << ',';
            71                             
            72                             if(k != 0 && k != 4)
            73                                 cout << j + 1 + dir[k].y * (word.size() - 1);
            74                             else cout << j + 1;
            75                             
            76                             found = true;
            77                             goto over;
            78                         }
            79                     }
            80             if(found == false)
            81                 cout << "Not found";
            82             over:
            83                 cout << endl;
            84         }
            85 
            86         if(N)
            87             cout << endl;
            88     }
            89     
            90     return 0;
            91 }
            92 

            posted @ 2008-05-14 11:57 superman 閱讀(191) | 評論 (0)編輯 收藏

             1 /* Accepted 1291 C++ 00:00.00 880K */
             2 #include <iostream>
             3 
             4 using namespace std;
             5 const int INF = 65535;
             6 
             7 int main()
             8 {
             9     int N;
            10     cin >> N;
            11     while(N--)
            12     {
            13         int n;
            14         cin >> n;
            15         
            16         int d[100][100];
            17         for(int i = 0; i < n; i++)
            18             for(int j = 0; j < n; j++)
            19                 d[i][j] = INF;
            20         for(int i = 1; i < n; i++)
            21             for(int j = 0; j < i; j++)
            22                 if(scanf("%d", d[i] + j) == 1)
            23                     d[j][i] = d[i][j];
            24                 else
            25                     getchar();
            26 
            27         for(int k = 0; k < n; k++)
            28         for(int i = 0; i < n; i++)
            29         for(int j = 0; j < n; j++)
            30             d[i][j] <?= (d[i][k] + d[k][j]);
            31         
            32         int ans = 0;
            33         for(int i = 1; i < n; i++)
            34             ans >?= d[0][i];
            35         
            36         cout << ans << endl;
            37         
            38         if(N)
            39             cout << endl;
            40     }
            41     
            42     return 0;
            43 }
            44 

            posted @ 2008-05-14 09:32 superman 閱讀(250) | 評論 (0)編輯 收藏

             1 /* Accepted 1292 C++ 00:00.02 844K */
             2 #include <iostream>
             3 
             4 using namespace std;
             5 
             6 int main()
             7 {
             8     int N; cin >> N;
             9     
            10     while(N--)
            11     {
            12         char a[200], alen = 0; memset(a, 0sizeof(a));
            13         char b[200], blen = 0; memset(b, 0sizeof(b));
            14         char c[200], clen = 0; memset(c, 0sizeof(c));
            15         
            16         while(scanf("%s", b) && strcmp(b, "0"!= 0)
            17         {
            18             memset(c, 0sizeof(c));
            19             
            20             blen = strlen(b);
            21             
            22             for(int i = 0; i < blen; i++)
            23                 b[i] -= '0';            
            24             for(int i = 0; i < blen / 2; i++)
            25                 swap(b[i], b[blen - i - 1]);
            26             
            27             clen = max(alen, blen);
            28             
            29             for(int i = 0; i < clen; i++)
            30                 c[i] = a[i] + b[i];
            31             for(int i = 0; i < clen; i++)
            32                 c[i + 1+= c[i] / 10, c[i] %= 10;
            33             
            34             if(c[clen])
            35                 clen++;
            36             
            37             alen = clen;
            38             memcpy(a, c, sizeof(c));
            39         }
            40         
            41         for(int i = clen - 1; i >= 0; i--)
            42             cout << int(c[i]);
            43         cout << endl;
            44         
            45         if(N)
            46             cout << endl;
            47     }
            48     
            49     return 0;
            50 }
            51 

            posted @ 2008-05-13 21:56 superman 閱讀(371) | 評論 (0)編輯 收藏

             1 /* Accepted 1244 C++ 00:00.00 836K */
             2 #include <iostream>
             3 
             4 using namespace std;
             5 
             6 int main()
             7 {
             8     int n, m = 1;
             9     while((cin >> n) && n)
            10     {
            11         getchar();
            12         bool x[26= { true };
            13         
            14         char v1, v2;
            15         for(int i = 0; i < n; i++)
            16         {
            17             scanf("%c = %c"&v1, &v2); getchar();
            18             v1 -= 'a', v2 -= 'a';
            19             if(x[v2])
            20                 x[v1] = true;
            21             else
            22                 x[v1] = false;
            23         }
            24         
            25         cout << "Program #" << m++ << endl;
            26         
            27         int cnt = 0;
            28         for(int i = 0; i < 26; i++)
            29             if(x[i])
            30             {
            31                 cnt++;
            32                 cout << char(i + 'a'<< ' ';
            33             }
            34         if(cnt == 0)
            35             cout << "none";
            36         cout << endl << endl;
            37     }
            38     
            39     return 0;
            40 }
            41 

            posted @ 2008-05-08 15:28 superman 閱讀(257) | 評論 (0)編輯 收藏

            僅列出標題
            共19頁: First 6 7 8 9 10 11 12 13 14 Last 
            中文字幕无码久久精品青草| 7国产欧美日韩综合天堂中文久久久久| 精品免费tv久久久久久久| 久久精品国产亚洲AV蜜臀色欲| 久久久亚洲精品蜜桃臀| 久久久精品国产亚洲成人满18免费网站| 亚洲欧美精品伊人久久| 四虎国产精品免费久久久| 成人精品一区二区久久| 久久久久亚洲精品天堂久久久久久 | 国产精品一区二区久久国产| 久久国语露脸国产精品电影| 一本一本久久a久久综合精品蜜桃 一本一道久久综合狠狠老 | 亚洲国产精品无码久久一线| 午夜天堂精品久久久久| 99久久成人国产精品免费| 国产成人久久久精品二区三区| 国产精品99久久久久久www| 午夜视频久久久久一区 | 久久综合中文字幕| 久久久久国色AV免费观看| 亚洲精品99久久久久中文字幕| 国内精品伊人久久久影院 | 久久久亚洲欧洲日产国码是AV| 亚洲欧洲日产国码无码久久99| 俺来也俺去啦久久综合网| 久久国产成人午夜AV影院| 久久久久av无码免费网| 久久青草国产精品一区| 一本色道久久综合| 久久国产高清字幕中文| 亚洲日韩欧美一区久久久久我| 97精品久久天干天天天按摩| 久久久久亚洲AV成人网人人软件| 久久亚洲精品国产亚洲老地址 | 性做久久久久久久久老女人| 日韩精品久久无码人妻中文字幕| 久久精品国产亚洲一区二区| 久久99热这里只有精品66| 久久综合中文字幕| 久久久一本精品99久久精品88|