青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品

coreBugZJ

此 blog 已棄。

ECNU 2011 Contest Three For Beginners,我的解題報告

題目鏈接:http://acm.hust.edu.cn:8080/judge/contest/viewContest.action?cid=1465


A - Number Sequence

模式匹配,KMP 算法。

 1#include <iostream>
 2#include <cstdio>
 3
 4using namespace std;
 5
 6template<class T>
 7void KMPinit( const T * pat, int patLen, int * flink ){
 8        int j, k;   flink[ 0 ] = -1;
 9        for( j = 1; j < patLen; ++j ){
10                k = flink[ j - 1 ];
11                while( ( k != -1 ) && ( pat[ j - 1 ] != pat[ k ] ) ){ k = flink[ k ];  }
12                flink[ j ] = k + 1;
13        }

14}

15template<class T>
16int KMPmatch( const T * txt, int txtLen, const T * pat, int patLen, const int * flink, int matBegin = 0 ){
17        int i = matBegin, j = 0;
18        while( ( i < txtLen ) && ( j < patLen ) ){
19                while( ( j != -1 ) && ( txt[ i ] != pat[ j ] ) ){ j = flink[ j ];  }
20                ++j;  ++i;
21        }

22        return ( j >= patLen ? i - patLen : -1 );
23}

24
25const int N = 1000009;
26const int M = 10009;
27
28int a[ N ], b[ M ], link[ M ], n, m;
29
30int main() {
31        int td, i;
32        scanf( "%d"&td );
33        while ( td-- > 0 ) {
34                scanf( "%d%d"&n, &m );
35                for ( i = 0; i < n; ++i )
36                        scanf( "%d", a+i );
37                for ( i = 0; i < m; ++i ) 
38                        scanf( "%d", b+i );
39                KMPinit( b, m, link );
40                i = KMPmatch( a, n, b, m, link, 0 );
41                printf( "%d\n", ( (i==(-1)) ? (-1) : (i+1) ) );
42        }

43        return 0;
44}

45




B - Big Number

模擬手工筆算就好了,不需要高精度。

 1#include <iostream>
 2#include <cstdio>
 3
 4using namespace std;
 5
 6const int L = 1009;
 7
 8char s[ L ];
 9
10int main() {
11        int a, b;
12        char *p;
13        while ( scanf( "%s%d", s, &b ) == 2 ) {
14                a = 0;
15                for ( p = s; *p; ++p ) {
16                        a = ( a*10 + (*p) - '0' ) % b;
17                }

18                printf( "%d\n", a );
19        }

20        return 0;
21}

22




C - A strange lift

最短路徑,寬度優(yōu)先搜索,動態(tài)規(guī)劃, 都可以。

我的最短路徑 SPFA 算法。

 1#include <iostream>
 2#include <cstdio>
 3#include <cstring>
 4
 5using namespace std;
 6
 7const int N   = 209;
 8const int INF = 0x3f3f3f3f;
 9const int QL  = N;
10
11int n, a, b, k[ N ];
12
13int solve() {
14        int que[ QL ], inq[ N ], qh, qt, f[ N ], i, j;
15        if ( a == b ) {
16                return 0;
17        }

18        qh = 0;
19        qt = 1;
20        memset( inq, 0sizeof(inq) );
21        que[ qh ] = a;
22        inq[ a ] = 1;
23        memset( f, 0x3fsizeof(f) );
24        f[ a ] = 0;
25        while ( qh != qt ) {
26                i = que[ qh ];
27                qh = ( qh + 1 ) % QL;
28                inq[ i ] = 0;
29                j = i + k[ i ];
30                if ( j <= n ) {
31                        if ( f[ i ] + 1 < f[ j ] ) {
32                                f[ j ] = f[ i ] + 1;
33                                if ( !inq[ j ] ) {
34                                        inq[ j ] = 1;
35                                        que[ qt ] = j;
36                                        qt = ( qt + 1 ) % QL;
37                                }

38                        }

39                }

40                j = i - k[ i ];
41                if ( j >= 1 ) {
42                        if ( f[ i ] + 1 < f[ j ] ) {
43                                f[ j ] = f[ i ] + 1;
44                                if ( !inq[ j ] ) {
45                                        inq[ j ] = 1;
46                                        que[ qt ] = j;
47                                        qt = ( qt + 1 ) % QL;
48                                }

49                        }

50                }

51        }

52        return ( (f[ b ] == INF) ? (-1) : f[ b ] );
53}

54
55int main() {
56        int i;
57        for ( ; ; ) {
58                scanf( "%d"&n );
59                if ( n == 0 ) {
60                        break;
61                }

62                scanf( "%d%d"&a, &b );
63                for ( i = 1; i <= n; ++i ) {
64                        scanf( "%d", k+i );
65                }

66                printf( "%d\n", solve() );
67        }

68        return 0;
69}

70




D - Intersecting Lines

計算幾何入門題,用向量叉積判斷直線關(guān)系,對于交點,我是用向量推出二元一次方程組,解得交點。

 1#include <iostream>
 2#include <iomanip>
 3
 4using namespace std;
 5
 6typedef long long Lint;
 7
 8Lint cross( Lint ax, Lint ay, Lint bx, Lint by ) {
 9        return ax*by - ay*bx;
10}

11
12int point_in_line( Lint px, Lint py, Lint ax, Lint ay, Lint bx, Lint by ) {
13        return ( cross( ax-bx, ay-by, px-bx, py-by ) == 0 );
14}

15
16int solve( Lint a, Lint b, Lint c, Lint e, Lint f, Lint g, double *x, double *y ) {
17        *= (double)(c*e-a*g) / (a*f-b*e);
18        *= (double)(c*f-b*g) / (b*e-a*f);
19        return 1;
20}

21
22#define  LINE_ONE  0
23#define  LINE_PAR  1
24#define  LINE_INS  2
25
26double ix, iy;
27
28int type( Lint ax, Lint ay, Lint bx, Lint by, Lint cx, Lint cy, Lint dx, Lint dy ) {
29        if ( point_in_line(ax,ay,cx,cy,dx,dy) && point_in_line(bx,by,cx,cy,dx,dy) ) {
30                return LINE_ONE;
31        }

32        if ( cross( ax-bx, ay-by, cx-dx, cy-dy ) == 0 ) {
33                return LINE_PAR;
34        }

35        solve( by-ay, ax-bx, ay*(bx-ax)-ax*(by-ay), dy-cy, cx-dx, cy*(dx-cx)-cx*(dy-cy), &ix, &iy );
36        return LINE_INS;
37}

38
39int main() {
40        int td;
41        Lint ax, ay, bx, by, cx, cy, dx, dy;
42        cout << "INTERSECTING LINES OUTPUT\n";
43        cin >> td;
44        while ( td-- > 0 ) {
45                cin >> ax >> ay >> bx >> by >> cx >> cy >> dx >> dy;
46                switch ( type( ax, ay, bx, by, cx, cy, dx, dy ) ) {
47                case LINE_ONE : 
48                        cout << "LINE\n";
49                        break;
50                case LINE_PAR : 
51                        cout << "NONE\n";
52                        break;
53                case LINE_INS : 
54                        cout << fixed << setprecision(2<< "POINT " << ix << " " << iy << "\n";
55                        break;
56                }

57        }

58        cout << "END OF OUTPUT\n";
59        return 0;
60}

61




E - Hat’s Words

字符串查找,可以字典樹,可以 map 等等。

 1#include <iostream>
 2#include <string>
 3#include <set>
 4#include <list>
 5
 6using namespace std;
 7
 8int main() {
 9        set< string >  dict;
10        list< string > book;
11        string word;
12        int i;
13        while ( cin >> word ) {
14                book.push_back( word );
15                dict.insert( word );
16        }

17        for ( list< string >::const_iterator  ite = book.begin();  ite != book.end(); ++ite ) {
18                word = (*ite);
19                for ( i = 1; i+1 < word.length(); ++i ) {
20                        if ( (dict.find(word.substr(0,i))!=dict.end()) && (dict.find(word.substr(i))!=dict.end()) ) {
21                                cout << word << "\n";
22                                break;
23                        }

24                }

25        }

26        // system( "pause" );
27        return 0;
28}

29




F - KILLER

HUST Monthly 2011.04.09的B題,我比賽時沒做出來的水題,wbw 告訴我的解法,想想群的知識。

 1#include <iostream>
 2#include <cstdio>
 3
 4using namespace std;
 5
 6int main() {
 7        int td, a, b, n, ans;
 8        scanf( "%d"&td );
 9        while ( td-- > 0 ) {
10                scanf( "%d"&n );
11                ans = n;
12                while ( n-- > 0 ) {
13                        scanf( "%d%d"&a, &b );
14                        if ( a == b ) {
15                                --ans;
16                        }

17                }

18                printf( "%d\n", ans );
19        }

20        return 0;
21}

22




G - Conference Call

連接三點的路徑中必有一點為三岔口(也許為三點之一),若以此三岔口與三點的最近距離的和為此三岔口的價值,枚舉所有三岔口,找出最大的價值,即為答案。補(bǔ)充:賽后和CY討論,知道枚舉所有點即可,不必為三岔口,因為若此點不是三岔口,則價值必定不是最小。

  1#include <iostream>
  2#include <cstdio>
  3#include <cstring>
  4#include <map>
  5
  6using namespace std;
  7
  8const int N   = 10009;
  9const int M   = 509;
 10const int INF = 0x2f2f2f2f;
 11
 12int disA[ M ], disB[ M ], disC[ M ];
 13int preA[ M ], preB[ M ], preC[ M ];
 14
 15int w[ M ][ M ], m, n, t[ N ];
 16
 17int nosame( int v ) {
 18        map< intint > cnt;
 19        map< intint >::const_iterator  ite;
 20        int i;
 21        cnt[ v ] = 1;
 22        for ( i = preA[ v ]; i && preA[ i ]; i = preA[ i ] ) {
 23                ++cnt[ i ];
 24        }

 25        for ( i = preB[ v ]; i && preB[ i ]; i = preB[ i ] ) {
 26                ++cnt[ i ];
 27        }

 28        for ( i = preC[ v ]; i && preC[ i ]; i = preC[ i ] ) {
 29                ++cnt[ i ];
 30        }

 31        for ( ite = cnt.begin(); ite != cnt.end(); ++ite ) {
 32                if ( ite->second > 1 ) {
 33                        return 0;
 34                }

 35        }

 36        return 1;
 37}

 38
 39void spfa( int s, int dis[], int pre[] ) {
 40        const int QL = M;
 41        int que[ QL ], inq[ M ], qh = 0, qt = 1, i, j;
 42
 43        memset( dis, 0x2fsizeof(int)*M );
 44        memset( pre, 0,    sizeof(int)*M );
 45        memset( inq, 0,    sizeof(inq)   );
 46        dis[ s ] = 0;
 47        que[ qh ] = s;
 48        inq[ s ] = 1;
 49        while ( qh != qt ) {
 50                i = que[ qh ];
 51                qh = ( qh + 1 ) % QL;
 52                inq[ i ] = 0;
 53                for ( j = 1; j <= m; ++j ) {
 54                        if ( dis[ i ] + w[ i ][ j ] < dis[ j ] ) {
 55                                dis[ j ] = dis[ i ] + w[ i ][ j ];
 56                                pre[ j ] = i;
 57                                if ( ! inq[ j ] ) {
 58                                        inq[ j ] = 1;
 59                                        que[ qt ] = j;
 60                                        qt = ( qt + 1 ) % QL;
 61                                }

 62                        }

 63                }

 64        }

 65}

 66
 67// INF <==> no answer
 68int solve( int a, int b, int c ) {
 69        int i, ans = INF;
 70        spfa( a, disA, preA );
 71        spfa( b, disB, preB );
 72        spfa( c, disC, preC );
 73        for ( i = 1; i <= m; ++i ) {
 74                if ( nosame(i) && (disA[i]+disB[i]+disC[i]<ans) ) {
 75                        ans = disA[ i ] + disB[ i ] + disC[ i ];
 76                }

 77        }

 78        return ans;
 79}

 80
 81int main() {
 82        int lw, i, j, k, a, b, c, cc = 0, cl, ans;
 83        while ( scanf( "%d%d%d"&n, &m, &lw ) == 3 ) {
 84                printf( "Case #%d\n"++cc );
 85                memset( w, 0x2fsizeof(w) );
 86                for ( i = 1; i <= n; ++i ) {
 87                        scanf( "%d", t+i );
 88                }

 89                while ( lw-- > 0 ) {
 90                        scanf( "%d%d%d"&i, &j, &k );
 91                        if ( w[ i ][ j ] > k ) {
 92                                w[ j ][ i ] = w[ i ][ j ] = k;
 93                        }

 94                }

 95                for ( i = 1; i <= m; ++i ) {
 96                        w[ i ][ i ] = 0;
 97                }

 98                scanf( "%d"&lw );
 99                cl = 0;
100                while ( lw-- > 0 ) {
101                        scanf( "%d%d%d"&a, &b, &c );
102                        ans = solve( t[a], t[b], t[c] );
103                        if ( ans == INF ) {
104                                printf( "Line %d: Impossible to connect!\n"++cl );
105                        }

106                        else {
107                                printf( "Line %d: The minimum cost for this line is %d.\n"++cl, ans );
108                        }

109                }

110        }

111        return 0;
112}

113




H - How to Type

動態(tài)規(guī)劃,f[ 0 ][ i ] 表示輸入前 i  個字符后沒有大寫鎖定的最少擊鍵次數(shù),
f[ 1 ][ i ] 表示輸入前 i 個字符后大寫鎖定的最少擊鍵次數(shù)。

 1#include <iostream>
 2#include <cstdio>
 3#include <cstring>
 4
 5using namespace std;
 6
 7const int L = 109;
 8
 9int main() {
10        char str[ L ];
11        int td, f[ 2 ][ L ], i, tmp;
12        scanf( "%d"&td );
13        while ( td-- > 0 ) {
14                scanf( "%s", str+1 );
15                memset( f, 0x3fsizeof(f) );
16                f[ 0 ][ 0 ] = 0;
17                for ( i = 1; str[i]; ++i ) {
18                        if ( ('a'<=str[i])&&(str[i]<='z') ) {
19                                tmp = 1 + f[ 0 ][ i - 1 ];
20                                if ( tmp < f[ 0 ][ i ] )  f[ 0 ][ i ] = tmp;
21
22                                tmp = 2 + f[ 1 ][ i - 1 ];
23                                if ( tmp < f[ 0 ][ i ] )  f[ 0 ][ i ] = tmp;
24
25                                tmp = 2 + f[ 0 ][ i - 1 ];
26                                if ( tmp < f[ 1 ][ i ] )  f[ 1 ][ i ] = tmp;
27
28                                tmp = 2 + f[ 1 ][ i - 1 ];
29                                if ( tmp < f[ 1 ][ i ] )  f[ 1 ][ i ] = tmp;
30                        }

31                        else {
32                                tmp = 2 + f[ 0 ][ i - 1 ];
33                                if ( tmp < f[ 0 ][ i ] )  f[ 0 ][ i ] = tmp;
34
35                                tmp = 2 + f[ 1 ][ i - 1 ];
36                                if ( tmp < f[ 0 ][ i ] )  f[ 0 ][ i ] = tmp;
37
38                                tmp = 2 + f[ 0 ][ i - 1 ];
39                                if ( tmp < f[ 1 ][ i ] )  f[ 1 ][ i ] = tmp;
40
41                                tmp = 1 + f[ 1 ][ i - 1 ];
42                                if ( tmp < f[ 1 ][ i ] )  f[ 1 ][ i ] = tmp;
43                        }

44                }

45                printf( "%d\n", f[ 0 ][ i-1 ] );
46        }

47        return 0;
48}

49





比賽時間倉促,自己的做法并非最優(yōu)。。。

posted on 2011-04-10 18:14 coreBugZJ 閱讀(1121) 評論(0)  編輯 收藏 引用 所屬分類: ACM

青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <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>
            亚洲视频碰碰| 精品99视频| 午夜电影亚洲| 午夜精品偷拍| 久久久久久久网| 欧美**人妖| 欧美视频在线观看视频极品| 欧美日韩中文在线| 国产精品久久久久久久久久妞妞 | 欧美日韩调教| 国产精品毛片在线看| 看片网站欧美日韩| 国产精品影院在线观看| 国模 一区 二区 三区| 亚洲电影在线免费观看| 一区二区三区免费看| 欧美在线一二三四区| 蜜臀av一级做a爰片久久| 亚洲欧洲偷拍精品| 一区二区三区日韩在线观看| 性一交一乱一区二区洋洋av| 欧美国产第二页| 国产色综合久久| 99在线精品视频在线观看| 午夜日韩av| 亚洲国产精品成人| 亚洲欧美一区二区原创| 欧美成人精品在线| 国产欧美一区在线| 99re热精品| 老鸭窝91久久精品色噜噜导演| 亚洲日本aⅴ片在线观看香蕉| 西西人体一区二区| 欧美日韩精品国产| 亚洲激情在线播放| 久久在线视频在线| 亚洲欧美日韩一区二区三区在线| 欧美福利一区| 亚洲第一二三四五区| 欧美一区二区三区的| 日韩视频中文字幕| 男女视频一区二区| 一区二区三区我不卡| 午夜在线精品偷拍| 一本久久知道综合久久| 欧美精品成人一区二区在线观看| 激情文学综合丁香| 久久久av水蜜桃| 亚洲一区二区黄色| 国产精品magnet| 在线一区欧美| 日韩视频永久免费观看| 精品69视频一区二区三区| 国产精品久久| 日韩亚洲精品在线| 欧美福利视频在线观看| 久久精品视频在线| 国产一区二区三区在线观看视频 | 亚洲二区在线视频| 久久日韩粉嫩一区二区三区| 亚洲欧美国产精品专区久久| 欧美性大战xxxxx久久久| 一本久久综合亚洲鲁鲁五月天| 欧美激情视频免费观看| 欧美大片免费观看在线观看网站推荐| 精品91免费| 欧美国产日韩一区二区| 欧美a级片网| 中国亚洲黄色| 亚洲一区国产一区| 国产香蕉97碰碰久久人人| 久久婷婷丁香| 免费在线亚洲| 亚洲视频精选| 亚洲在线视频网站| 狠狠色综合色综合网络| 欧美国产综合一区二区| 欧美精品一区二区久久婷婷| 亚洲乱码精品一二三四区日韩在线| 亚洲国产精品久久91精品| 欧美日韩免费一区| 欧美一区深夜视频| 久久久久网站| 一区二区三区四区五区精品| 一本色道88久久加勒比精品| 国产精品一区在线观看| 免费视频亚洲| 国产精品高潮粉嫩av| 久久久久免费观看| 欧美+亚洲+精品+三区| 在线午夜精品自拍| 欧美在线视频观看免费网站| 在线免费观看一区二区三区| 日韩视频二区| 韩日成人av| 亚洲美女少妇无套啪啪呻吟| 国产麻豆精品视频| 亚洲黄色成人网| 国产欧美综合一区二区三区| 亚洲国产成人不卡| 国产一区二区三区av电影| 91久久精品日日躁夜夜躁欧美 | 久久男人av资源网站| 中文久久精品| 久久综合999| 午夜视频精品| 欧美剧在线免费观看网站| 久久激情视频久久| 久久精品国产亚洲一区二区| 久久久久国产精品麻豆ai换脸| 久久久久国产精品麻豆ai换脸| 亚洲国产日韩欧美| 亚洲午夜日本在线观看| 亚洲精品国产精品国产自| 亚洲欧美影院| 中文av字幕一区| 蜜臀a∨国产成人精品| 欧美一区二区三区啪啪| 欧美三级韩国三级日本三斤| 欧美电影免费观看高清| 国产一区二区三区在线播放免费观看| 一本大道av伊人久久综合| 亚洲深夜av| 亚洲精品欧美极品| 久久久视频精品| 亚洲午夜激情免费视频| 久久精品中文字幕一区| 久久精品视频免费观看| 国产精品一区二区三区免费观看| 9色国产精品| 中文日韩欧美| 欧美性色aⅴ视频一区日韩精品| 欧美96在线丨欧| 在线观看精品视频| 麻豆精品视频在线观看视频| 国产精品一区二区黑丝| 亚洲小视频在线观看| 久久午夜电影| 看片网站欧美日韩| 欧美大胆a视频| 亚洲激情午夜| 欧美日韩国产bt| 日韩亚洲精品视频| 亚洲手机成人高清视频| 欧美日韩视频一区二区三区| 一本色道久久综合亚洲精品不| 一区二区激情| 国产精品视频你懂的| 欧美一区免费视频| 狼人天天伊人久久| 亚洲国内自拍| 欧美日精品一区视频| 一本久久青青| 久久久久亚洲综合| 亚洲精品日韩在线| 国产精品福利在线观看网址| 亚洲欧美日韩在线不卡| 久久夜色精品国产亚洲aⅴ| 亚洲国产福利在线| 欧美三级电影网| 久久精品免费| 亚洲三级视频| 久久精品欧洲| 亚洲每日更新| 国产亚洲精品久久久久动| 美女黄网久久| 亚洲一区二区三区午夜| 美女视频一区免费观看| 99综合在线| 黄色成人av网| 欧美日韩一区二区三区在线视频| 亚洲欧美日韩在线| 亚洲人成人99网站| 久久精品亚洲精品| 一区二区三区精密机械公司 | 欧美日韩久久| 99成人精品| 久久日韩精品| 亚洲午夜电影| 亚洲电影成人| 国产精品尤物福利片在线观看| 久久综合九色99| 亚洲字幕一区二区| 亚洲欧洲日本在线| 久久久美女艺术照精彩视频福利播放 | 久久精品视频免费播放| 宅男66日本亚洲欧美视频| 国产一区在线视频| 欧美日韩精品中文字幕| 久久性天堂网| 欧美亚洲视频在线观看| 日韩午夜视频在线观看| 免费欧美网站| 久久精品一区二区三区四区 | 国产精品人人做人人爽| 欧美日本在线视频| 久久一二三区| 久久久久国产一区二区| 午夜精品久久久久久久99热浪潮| 99视频一区二区|