锘??xml version="1.0" encoding="utf-8" standalone="yes"?>久久久久噜噜噜亚洲熟女综合,欧美精品九九99久久在观看,国产精品成人99久久久久 http://www.shnenglu.com/zqsand/category/12850.html鍟ユ槸瀛愭爣棰?/description>zh-cnWed, 20 Jan 2010 11:25:00 GMTWed, 20 Jan 2010 11:25:00 GMT60TC-Practice-Recordhttp://www.shnenglu.com/zqsand/archive/2009/12/26/104143.htmlrikisandrikisandSat, 26 Dec 2009 09:28:00 GMThttp://www.shnenglu.com/zqsand/archive/2009/12/26/104143.htmlhttp://www.shnenglu.com/zqsand/comments/104143.htmlhttp://www.shnenglu.com/zqsand/archive/2009/12/26/104143.html#Feedback0http://www.shnenglu.com/zqsand/comments/commentRss/104143.htmlhttp://www.shnenglu.com/zqsand/services/trackbacks/104143.htmltchs-1 none 1000pt DFS 鍒╃敤榪涘叆鐨勬柟鍚戝垝鍒嗗洓涓竟

tchs-2 250pt 鐩存帴綆楀氨琛?鎴戝啓浜?鍒?500pt 鏆村姏鍙互榪囷紝浣嗘槸鍒ゆ柇鏃跺欎笉鑳界敤stringstream 鐢ㄧ畻鏈垽鏂?涔熷彲浠ョ敤鏋勯犳硶 1000pt 姣忎竴浣嶆湁涓夌鍙兘鎬?/p>

           涓嶇敤錛屼繚鎸佷笉鍔紝鍙樺寲錛屽垎鍒掑綊璁$畻value騫舵洿鏂扮粨鏋滃嵆鍙紝鐢變簬閫掑綊娣卞害鏈澶氬彧鏈?3灞傛墍浠ヤ笉浼?xì)tle

           鍙﹀涔熷彲浠ュ啓鍑哄熀鏁頒負(fù)3鐨勫驚鐜潵閬嶅巻姣忎竴縐嶆儏鍐靛叿浣撶湅浠g爜

    for(i=0,A[0]++;A[i]>2;i++){
       A[i]=0;A[i+1]++;
  }

tchs-3 1000pt 瑕佹兂浣夸箻縐渶澶э紝闇瑕佹洿澶氱殑3鍗沖彲 500pt 鍙堢湅閿欓?shù)?~~~ft 瑕佹敞鎰忛鐩竴瀹氳鐪嬫竻妤?/p>

tchs-4 500pt 妯℃嫙棰橈紝濂介毦鎳?闊充箰鐨剘 鍙互閮戒箻?shù)?6 鐢ㄦ暣鏁版潵璁$畻 嫻偣浼?xì)寰堢儲(chǔ)~ 榪欑棰樻濊礬瑕佹竻鏅?涓姝ヤ竴姝ユ潵



rikisand 2009-12-26 17:28 鍙戣〃璇勮
]]>
TOPCODER-SRM455http://www.shnenglu.com/zqsand/archive/2009/12/19/103524.htmlrikisandrikisandSat, 19 Dec 2009 06:07:00 GMThttp://www.shnenglu.com/zqsand/archive/2009/12/19/103524.htmlhttp://www.shnenglu.com/zqsand/comments/103524.htmlhttp://www.shnenglu.com/zqsand/archive/2009/12/19/103524.html#Feedback0http://www.shnenglu.com/zqsand/comments/commentRss/103524.htmlhttp://www.shnenglu.com/zqsand/services/trackbacks/103524.html闃呰鍏ㄦ枃

rikisand 2009-12-19 14:07 鍙戣〃璇勮
]]>
USACO 0912 鏈堣禌http://www.shnenglu.com/zqsand/archive/2009/12/13/103138.htmlrikisandrikisandSun, 13 Dec 2009 13:14:00 GMThttp://www.shnenglu.com/zqsand/archive/2009/12/13/103138.htmlhttp://www.shnenglu.com/zqsand/comments/103138.htmlhttp://www.shnenglu.com/zqsand/archive/2009/12/13/103138.html#Feedback0http://www.shnenglu.com/zqsand/comments/commentRss/103138.htmlhttp://www.shnenglu.com/zqsand/services/trackbacks/103138.htmlsilver緇勶細(xì)

姣旇禌閭eぉ鎰熷啋錛岀涓棰樺氨寮勬檿浜?jiǎn)锛岀幇鍦ㄩ瑙e嚭鏉ヤ簡(jiǎn)锛岃ˉ涓婂惂~~

鏆傛椂鍙湁絎竴棰樼殑錛?/p>

Problem 6: Bobsledding [Brian Jacokes, 2009]

Bessie has entered a bobsled competition because she hopes her hefty
weight will give her an advantage over the L meter course (2 <= L
<= 1,000,000,000).

Bessie will push off the starting line at 1 meter per second, but
her speed can change while she rides along the course. Near the
middle of every meter Bessie travels, she can change her speed
either by using gravity to accelerate by one meter per second or
by braking to stay at the same speed or decrease her speed by one
meter per second.

Naturally, Bessie must negotiate N (1 <= N <= 100,000) turns on the
way down the hill. Turn i is located T_i meters from the course
start (1 <= T_i <= L-1), and she must be enter the corner meter at
a speed of at most S_i meters per second (1 <= S_i <= 1,000,000,000).
Bessie can cross the finish line at any speed she likes.

Help Bessie learn the fastest speed she can attain without exceeding
the speed limits on the turns.

Consider this course with the meter markers as integers and the
turn speed limits in brackets (e.g., '[3]'):

|   1   2   3   4   5   6   7[3]
|---+---+---+---+---+---+---+
|                            \
Start                         + 8    
                               \
                                + 9    
                                 \
                                  + 10       +++ 14 (finish)
                                   \         /
                              11[1] +---+---+
                                        12  13[8]

Below is a chart of Bessie's speeds at the beginning of each meter length
of the course:

Max:                              3               1       8
Mtrs: 0   1   2   3   4   5   6   7   8   9  10  11  12  13  14 
Spd:  1   2   3   4   5   5   4   3   4   3   2   1   2   3   4

Her maximum speed was 5 near the beginning of meter 4.

PROBLEM NAME: bobsled

INPUT FORMAT:

* Line 1: Two space-separated integers: L and N

* Lines 2..N+1: Line i+1 describes turn i with two space-separated
        integers: T_i and S_i

SAMPLE INPUT (file bobsled.in):

14 3
7 3
11 1
13 8

OUTPUT FORMAT:

* Line 1: A single integer, representing the maximum speed which
        Bessie can attain between the start and the finish line,
        inclusive.

SAMPLE OUTPUT (file bobsled.out):

5

 

棰樼洰鐪嬭搗鏉ユ尯澶嶆潅錛屽叾瀹炰富瑕佹槸姹傚嚭鍚勪釜turn澶勭殑鏈澶ч熷害錛屽垎鏋愬緱鍒版瘡涓猼urn鐨勬渶澶ч熷害闇瑕佹弧瓚充笁涓潯浠訛紝 M_i = min (S_i , t_i – t_{i-1} + M_{i-1} , S_k + t_k – t_i [for all k > i ] )

鍥犳澶勭悊姣忎竴涓猼urn閮借鏌ヨN涓猼urn N*N鐨勫鏉傚害鏄劇劧瀵逛簬澶ф暟鎹TLE鐨?/font>

閫嗗悜鎬濊冿紝濡傛灉鎴戜滑鍙嶈繃鏉ヨ冭檻錛屽浜庢瘡涓涓箣鍚庣殑turn鏉ヨ 濡傦細(xì)i  濡傛灉浠栨渶澶ч熷害涓?m_i

閭d箞 鍦╰urn i-1澶勶紝浠栦笉鑳借秴榪囩殑鏈澶ч熷害 m_{i-1} = min(S_i,m_i+t_i – t_{i-1});榪欐牱鎴愬姛鐨勬妸鍚庨潰涓や釜闄愬埗杞崲涓洪嗘帹鐨勭粨鏋滆屼笉鏄悜鍚庢煡璇?/font>

鍓╀笅鐨勯棶棰樹(shù)究鏄鏋滅煡閬撲袱涓猼urn涔嬮棿璺濈錛屼互鍙?qiáng)turn鐨勯熷害鏈澶у鹼紝濡備綍姹傚嚭涔嬮棿鐨勬渶澶у鹼紝鐢誨浘鏄劇劧鍙互寰楀埌涓縐嶇畻寮?maxspeed = min(s1,s2) + (dist2-dist1+abs(s1-s2))/2;

鎴栬?maxspeed = max(s1,s2) + (dist2 – dist1 – abs(s1-s2))/2;

娉ㄦ剰鍦ㄥ紑澶村拰緇撳熬鍔犲叆铏氭嫙鐨則urn灝卞彲浠ヤ簡(jiǎn)

 

Code Snippet
#define REP(i,n)  for(  int (i) = 0 ; i < (n) ; ++i)
using namespace std;
int L,N;
struct node{
    int dist;
    int speed;
};
vector<node> vec;
bool comp(const node& n1,const node& n2){
    return n1.dist<n2.dist;
}
vector<int> up,down;
#define inf 98765433
void solve()
{
    //freopen("e:\\usaco\\bobsled.11.in","r",stdin);
    freopen("bobsled.in","r",stdin);
    freopen("bobsled.out","w",stdout);
    cin>>L>>N;
    vec.resize(N+2); up.resize(N+2,0); down.resize(N+2,0);
    vec[0].dist =0;vec[0].speed =1;
    vec[N+1].dist =L;vec[N+1].speed=inf;
    REP(i,N) scanf("%d %d",&vec[i+1].dist,&vec[i+1].speed);
    sort(vec.begin(),vec.end(),comp);
    down[N+1] = inf;
    for(int i=N;i>0;i--)
        down[i] = min(vec[i].speed,vec[i+1].dist-vec[i].dist+down[i+1]);
    int maxspeed = 1;up[0]=1;
    for(int i=1;i<N+2;i++){
        up[i] = min(down[i],up[i-1]+vec[i].dist - vec[i-1].dist);
        maxspeed = max(maxspeed,min(up[i],up[i-1])+(vec[i].dist-vec[i-1].dist+abs(up[i]-up[i-1]))/2);
    }
    cout<<maxspeed<<endl;
}


int main()
{
    solve();
    return 0;
}

 

 



rikisand 2009-12-13 21:14 鍙戣〃璇勮
]]>
TC-SRM-454_div2http://www.shnenglu.com/zqsand/archive/2009/12/13/103088.htmlrikisandrikisandSun, 13 Dec 2009 02:18:00 GMThttp://www.shnenglu.com/zqsand/archive/2009/12/13/103088.htmlhttp://www.shnenglu.com/zqsand/comments/103088.htmlhttp://www.shnenglu.com/zqsand/archive/2009/12/13/103088.html#Feedback0http://www.shnenglu.com/zqsand/comments/commentRss/103088.htmlhttp://www.shnenglu.com/zqsand/services/trackbacks/103088.html闃呰鍏ㄦ枃

rikisand 2009-12-13 10:18 鍙戣〃璇勮
]]>
Topcoer SRM 453.5http://www.shnenglu.com/zqsand/archive/2009/12/11/103001.htmlrikisandrikisandFri, 11 Dec 2009 11:59:00 GMThttp://www.shnenglu.com/zqsand/archive/2009/12/11/103001.htmlhttp://www.shnenglu.com/zqsand/comments/103001.htmlhttp://www.shnenglu.com/zqsand/archive/2009/12/11/103001.html#Feedback0http://www.shnenglu.com/zqsand/comments/commentRss/103001.htmlhttp://www.shnenglu.com/zqsand/services/trackbacks/103001.html闃呰鍏ㄦ枃

rikisand 2009-12-11 19:59 鍙戣〃璇勮
]]>
TC-SRM-233-1000pt BFShttp://www.shnenglu.com/zqsand/archive/2009/11/25/101897.htmlrikisandrikisandWed, 25 Nov 2009 03:39:00 GMThttp://www.shnenglu.com/zqsand/archive/2009/11/25/101897.htmlhttp://www.shnenglu.com/zqsand/comments/101897.htmlhttp://www.shnenglu.com/zqsand/archive/2009/11/25/101897.html#Feedback0http://www.shnenglu.com/zqsand/comments/commentRss/101897.htmlhttp://www.shnenglu.com/zqsand/services/trackbacks/101897.html緇х畫(huà)鏄痬isof 鏁板瓧鏁欏閲岄潰鐨勪範(fàn)棰榽 絎竴綃囩殑鏈鍚庝竴閬撻?shù)簡(jiǎn)~
Problem Statement

You are in a maze containing revolving doors. The doors can be turned 90 degrees by pushing against them in either direction. You are to find a route from the start square to the end square that involves revolving as few doors as possible. Given a map of the maze, determine the fewest number of door revolutions necessary to get from the start to the end.

In the map:

   ' ': empty space
   '#': wall
   'O': center of a revolving door (letter "oh", not zero)
   '-': horizontal door (always adjacent to a 'O')
   '|': vertical door (always adjacent to a 'O')
   'S': start square
   'E': end square

Each revolving door will always be oriented horizontally (with two horizontal segments) or vertically (with two vertical segments):

    |
    O  or  -O-
    |

Doors can be revolved 90 degrees by moving onto a door segment from any of the 4 squares diagonally adjacent to the door center, i.e., the 'X' characters below:

   X|X     X X
    O  or  -O-
   X|X     X X

Here is an example map:

        ###
        #E#
       ## #
    ####  ##
    # S -O-#
    # ###  #
    #      #
    ########

In this example, 2 door revolutions are necessary to get from 'S' to 'E'. The first turn is shown here:

        ###         ###
        #E#         #E#
       ## #        ## #
    ####  ##    #### |##
    # S -O-#    # S  OX#
    # ### X#    # ###| #
    #      #    #      #
    ########    ########

And the second turn is shown here:

        ###         ###
        #E#         #E#
       ## #        ## #
    ####X|##    #### X##
    # S  O #    # S -O-#
    # ###| #    # ###  #
    #      #    #      #
    ########    ########

Your method should return an int, the minimum number of door revolutions necessary to get from the start square to the end square. If there is no way to reach the end square, return -1.

Definition

Class:
RevolvingDoors

Method:
turns

Parameters:
vector <string>

Returns:
int

Method signature:
int turns(vector <string> map)

(be sure your method is public)

Notes

-
Assume that all squares off the edge of the map are walls.

Constraints

-
map will contain between 3 and 50 elements, inclusive.

-
Each element of map will contain between 3 and 50 characters, inclusive.

-
Each element of map will contain the same number of characters.

-
Each character in map will be one of 'S', 'E', 'O', '-', '|', '#', and ' ' (space).

-
There will be exactly one 'S' and one 'E' in map.

-
There will be between 1 and 10 doors, inclusive, and they will be formatted in map as described in the problem statement.

-
No two doors will be close enough for any part of them to occupy the same square.

-
It is not allowed for a door to be blocked and unable to turn. There will not be any walls in any of the 4 squares immediately adjacent to the center of a door, nor will a door be on the edge of the map.

鍏抽敭鏄棬鐨勭姸鎬佽〃紺猴紝鍙傝冧簡(jiǎn)緗戠珯涓婄殑浠g爜錛屾寫(xiě)浜?jiǎn)涓涓瘮杈冪畝緇冪殑錛岀敤鐨勪紭鍏堢駭闃熷垪銆傚啓瀹岃皟濂藉彂鐜癟LE 鍥 copy鍑虹綉绔欎笂鐨勫啀run渚濈劧TLE``` ``` 鐪嬩簡(jiǎn)涓嬪彂鐜扮幇鍦ㄧ殑system testing 姣斿師鏉ュ鍔犱簡(jiǎn)鍑犱釜嫻嬭瘯鐢ㄤ緥~~~   浜庢槸鎵懼嚭misof澶х墰鐨勮В娉曪紝鍙戠幇瀵圭姸鎬佸鐞嗕竴鏍風(fēng)殑~~~鍙笉榪囩敤浜?jiǎn)memo鍜宒eque錛岀渷鍘諱簡(jiǎn)浼樺厛綰ч槦鍒楄皟鏁寸殑鏃墮棿寮閿錛屾敼濂戒簡(jiǎn)灝眕ass浜?jiǎn)~ 涓婁唬鐮亊~錛?/strong>
Code Snippet
using namespace std;
typedef long long int64;  
typedef vector<int> VI;
typedef vector<string> VS;
#define inf 1000000
#define REP(i,n) for(int (i)=(0);((i)<(n));++(i))
template<class T> inline void checkmin(T &a,const T &b) { if (b<a) a=b; }
template<class T> inline void checkmax(T &a,const T &b) { if (b>a) a=b; }
int dr[]={-1,0,1,0};
int dc[]={0,1,0,-1};
struct state{state(int x,int y,int z,int s):r(x),c(y),doorstate(z),best(s){}int r;int c;int doorstate;int best;};
int memo[56][56][1<<11];
class RevolvingDoors
{
        public:
        int turns(vector <string> mp)
        {
             int x=mp.size()+2;int y=mp[0].size()+2;
             int sr,sc,er,ec,cnt=0,doorInit=0;
             REP(i,x-2)mp[i]='#'+mp[i]+'#';                //trick:modify the pattern to make it easy to loop
             mp.insert(mp.begin(),string(58,'#'));
             mp.push_back(string(58,'#'));
             REP(i,x)REP(j,y)if(mp[i][j]=='S'){mp[i][j]=' ';sr=i;sc=j;}else if(mp[i][j]=='E'){mp[i][j]=' ';er=i;ec=j;}
             REP(i,x)REP(j,y)if(mp[i][j]=='O'){if(mp[i-1][j]=='|')doorInit|=(1<<cnt);
                mp[i-1][j]=mp[i+1][j] = 100 + cnt*2 +1;    //use the content in the box to identify the door number,and the door pos
                mp[i][j-1]=mp[i][j+1] = 100 + cnt*2 ;    //if pos==0 it means this box is on the left or right of the door
                cnt++; mp[i][j]='#';
             }
             REP(i,x)REP(j,y)REP(t,1<<cnt) memo[i][j][t] = inf;    //init the memo
             deque<state> Q; Q.push_back(state(sr,sc,doorInit,0));
             while(!Q.empty()){
                state now=Q.front();Q.pop_front();
                int r=now.r  , c=now.c  , door=now.doorstate , b=now.best;
                if( memo[r][c][door] < b)continue;    //no better ,no vist
                REP(dir,4){                            //try four direction
                    int nr=r+dr[dir],nc=c+dc[dir];
                    if(mp[nr][nc]==' '){
                        if(memo[nr][nc][door] > b){ memo[nr][nc][door]=b;Q.push_back(state(nr,nc,door,b));}
                    }
                    else if(mp[nr][nc]=='#')continue;
                    else{                            //if we come to a box near to the door-mid
                        int doornum=(mp[nr][nc]-100)/2;int open=(mp[nr][nc]-100)%2;    
                        if( ((door>>doornum)&1) != open){    //lucily,the box is empty
                            if(memo[nr][nc][door] > b){memo[nr][nc][door] = b;Q.push_back(state(nr,nc,door,b));}
                        }        
                        else {                                // the box has a door
                            if(open==0 && dr[dir]==0) continue;    //try to define the relative pos between the direction and the box
                            if(open==1 && dc[dir]==0) continue;    //also ~ if we cannot push the door we give up
                            int ndoor=door^(1<<doornum);    //we can go into the box if we push the door ~
                            if(memo[nr][nc][ndoor] > b+1 ){memo[nr][nc][ndoor] = b+1 ;Q.push_back(state(nr,nc,ndoor,b+1));}
                        }
                    }
                }
             }
             int ans=inf;
             REP(i,1<<cnt){ //loop to check the best ans~
                 if(memo[er][ec][i]<ans){ans=memo[er][ec][i];cout<<er<<" "<<ec<<" "<<hex<<i<<endl;}
             }
             if(ans == inf) return -1;
             else return ans;
        }

涓枃copy鏄貢鐮?#183;··鍥у晩~~ 淇虹殑鐮寸儌鑻辨枃娉ㄩ噴鍟妦~~



rikisand 2009-11-25 11:39 鍙戣〃璇勮
]]>
TCCC-05-1000pt-http://www.shnenglu.com/zqsand/archive/2009/11/23/101697.htmlrikisandrikisandMon, 23 Nov 2009 07:29:00 GMThttp://www.shnenglu.com/zqsand/archive/2009/11/23/101697.htmlhttp://www.shnenglu.com/zqsand/comments/101697.htmlhttp://www.shnenglu.com/zqsand/archive/2009/11/23/101697.html#Feedback0http://www.shnenglu.com/zqsand/comments/commentRss/101697.htmlhttp://www.shnenglu.com/zqsand/services/trackbacks/101697.htmlProblem Statement

Just before a chess match between two teams, each team's coach secretly determines an ordering of his team's players. The first players in each team then get to play against each other, the second players in each team play against each other, etc. The team with the most wins will win the match.

You are the coach for one of the teams, and you have somehow managed to find out the order of the players in the other team. Based on that, you want to order your players so that your team's expected score is maximized to your advantage. The expected score of a single game can be calculated by the following formula (which is directly derived from how the international chess rating system works):

EA = 1 / (1 + 10 (RB - RA)/400)

EB = 1 / (1 + 10 (RA - RB)/400)

where RA and RB are the ratings of player A and B, and EA and EB are the expected scores for each player. For instance, if RA is 2432 and RB is 2611, the expected score for player A is 1 / (1 + 10179/400) = 0.263005239459. The expected score for a team is the sum of the expected scores for the players in that team.

To make things a bit more complicated, the players in a team must be ordered such that a player with rating x plays before all players with rating strictly less than x - lim, where lim is a given non-negative integer. For example, if lim is 100, a player with rating 2437 must play before a player with rating 2336 but not necessarily before a player with rating 2337.

Create a class ChessMatch containing the method bestExpectedScore which takes a vector <int> teamA, the ratings of your players (in no particular order); a vector <int> teamB, the ratings of your opponent's players in the order they will play; and an int lim, the limit determining how freely you can order your players. You can assume that your opponent's players will be ordered in accordance with lim. The method should return a double, your team's expected score if you order your players optimally.

Definition

Class:
ChessMatch

Method:
bestExpectedScore

Parameters:
vector <int>, vector <int>, int

Returns:
double

Method signature:
double bestExpectedScore(vector <int> teamA, vector <int> teamB, int lim)

(be sure your method is public)

 

瑕佹眰鏈濂界殑寰楀垎錛岃閬嶅巻鎵鏈夌殑鎺掑垪鏂瑰紡鏄劇劧涓嶅彲鑳姐傚鏋滆漿鍖栭棶棰樹(shù)負(fù)渚濇鏀劇疆姣忎釜閫夋墜鍒版瘡涓涓綅緗紝閭d箞鍙姹傚嚭鍓╀笅閫夋墜鎺掑垪涓嬌寰楀緱鍒嗘渶澶х殑灝卞彲浠ヤ簡(jiǎn)錛屽彲浠ユ兂鍒癲p鏂規(guī)硶鐨勬渶鏈夊瓙闂瀹氫箟銆?/font>

鐢ㄦ瘡涓浣嶈褰曞綋鍓嶇殑閫夋墜鍒嗛厤鎯呭喌錛屽鏋滀負(fù)0錛屽垯宸茬粡鍒嗛厤錛屽鏋滀負(fù)1錛屽垯榪樻湭鍒嗛厤銆俻os鏉ヨ褰曞綋鍓嶈鍒嗛厤鐨勪綅緗傚浜庢瘡涓涓瓙闆嗭紝鑰冭檻姣忎竴涓負(fù)1鐨勪篃灝辨槸鏈垎閰嶇殑閫夋墜浣夸綅浜巔os浣嶇疆錛岀劧鍚巆heck 鏄惁婊¤凍鍦ㄤ粬涔嬪悗鐨勭悆鍛橈紙涔熷氨鏄墿涓嬬殑鏄?鐨勪綅錛夋槸鍚︽弧瓚蟲(chóng)潯浠剁殑涓嶇瓑寮忥紝婊¤凍鍒欐洿鏂板綋鍓嶅垎閰嶇殑鏈浼樻垚緇┿傛渶緇?2^N-1 鐨勬垚緇╁嵆涓烘墍姹傘?/font>

Code Snippet
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define two(X) (1<<(X))
#define contain(S,X) ((S&two(X))>0)
#define eps 1e-9
double p[20][20];
int N;
double memo[1<<20];
int lim;VI A;
bool check(int now,int pos){
    REP(i,N)if(now&two(i)){
        if(A[pos]+lim<A[i])return false;
    }
    return true;
}
double solve(int now,int pos){
    if(now==0) return 0;
    if(memo[now]>-eps)return memo[now];
    REP(i,N) if(contain(now,i)&&check(now^two(i),i)){
         double tmp=p[i][pos]+solve(now^two(i),pos+1);
         if(tmp>memo[now]+eps) memo[now]=tmp;
    }
    return memo[now];
}

class ChessMatch
{
        public:
        double bestExpectedScore(vector <int> tA, vector <int> tB, int _lim)
        {
            N=tA.size(); lim=_lim;A=tA;
            REP(i,N)REP(j,N)  p[i][j]=1.0/(1.0+pow(10.0,double(tB[j]-tA[i])/400.0));
            REP(i,1<<N)memo[i]=-1;
            return solve(two(N)-1,0);  
        }

 

涓婇潰鐨勬柟娉曚嬌鐢ㄩ掑綊錛屼笅闈㈡槸浣跨敤閫掓帹鐨勭▼搴忋傚嵆浠庡瓙闆嗗嚭鍙戞渶緇堝埌杈?^n-1鐨勬濊礬銆傚湪榪欓噷鎶夾闃熶紞鍏堜粠澶у埌灝忔帓搴忋傚湪姣忎竴涓瓙闆嗚褰曟瘡涓涓湭鍒嗛厤閫夋墜鐨勫緱鍒嗗拰瑕佸垎閰嶇殑浣嶇疆銆?/font>

紼嬪簭涓濊礬涓猴細(xì)渚濇浠庡瓙闆嗕腑閫夊彇涓涓夋墜浣滀負(fù)絎琤its-1涓夋墜錛屼篃灝辨槸璇村瓙闆嗕腑鍓╀笅鐨勫厓绱犺鏀懼湪榪欎釜閫夋墜鍓嶉潰錛岀敱浜庨夋墜浠庡皬鍒板ぇ閬嶅巻錛屽彧闇瑕侀亶鍘嗗埌s[j]<=s[bits-1]+lim 涓烘錛屼篃灝辮婊¤凍榪欎釜瀛愰泦涓渶灝忕殑閫夋墜+lim >=閫変腑鐨?鍗沖彲錛岀劧鍚庢洿鏂板綋鍓嶅瓙闆嗙殑寰楀垎

娉ㄩ噴涓濊礬涓? 渚濇浠庡瓙闆嗛夊彇涓涓夋墜浣滀負(fù)褰撳墠瀛愰泦涓殑絎竴涓厓绱狅紝涔熷氨鏄暣浣撶殑絎琻-bits涓厓绱狅紝榪欐浠庡ぇ鍒板皬閬嶅巻錛岃繖鏍峰彧闇瑕佷繚璇侊紝浣嶄簬瀛愰泦絎竴涓殑鍏冪礌+lim>=瀛愰泦涓渶澶х殑鍏冪礌(s[0])錛屽嵆鍙紝鐒跺悗鏇存柊褰撳墠瀛愰泦寰楀垎

鏈緇堝叏闆?^n-1鐨勫嵆涓烘墍姹?/font>

Code Snippet
class ChessMatch
{
        public:
        double bestExpectedScore(vector <int> ta, vector <int> tb, int _lim)
        {
                int n=ta.size();a=ta;lim=_lim;N=n;
                sort(ta.begin(),ta.end(),greater<int>());int s[32],pos[32];
                REP(i,n)REP(j,n)p[i][j]=1./(1.+pow(10.,double(tb[j]-ta[i])/400.));
                REP(mask,1<<n){
                    int bits=0;
                    dp[mask]=0.;
                    if(!mask)continue;
                    REP(i,n) if(contain(mask,i)){
                        s[bits]=ta[i];pos[bits++]=i;
                    }
                    //for (int j = 0 ; j < bits  && s[j] + lim >= s[0]; j++){
                    //    if(dp[mask] < p[pos[j]][n-bits]+dp[mask^two(pos[j])])
                    //        dp[mask]= p[pos[j]][n-bits]+dp[mask^two(pos[j])] ;
                    
                    for (int j = bits-1; j >= 0 && s[j] <= s[bits-1] + lim; j--){
                    if(    dp[mask] <  p[pos[j]][bits-1] + dp[mask & ~(1 << pos[j])] )
                      dp[mask] = p[pos[j]][bits-1] + dp[mask & ~(1 << pos[j])];
                    }
                }
                return dp[two(n)-1];
        }


rikisand 2009-11-23 15:29 鍙戣〃璇勮
]]>
TC-05TCOR4-250 DPhttp://www.shnenglu.com/zqsand/archive/2009/11/22/101628.htmlrikisandrikisandSun, 22 Nov 2009 07:58:00 GMThttp://www.shnenglu.com/zqsand/archive/2009/11/22/101628.htmlhttp://www.shnenglu.com/zqsand/comments/101628.htmlhttp://www.shnenglu.com/zqsand/archive/2009/11/22/101628.html#Feedback0http://www.shnenglu.com/zqsand/comments/commentRss/101628.htmlhttp://www.shnenglu.com/zqsand/services/trackbacks/101628.html
roblem Statement

Character j in element i (both 0-based) of messages denotes how many messages employee i sent to employee j. You will return a vector <int> containing the hierarchy of the employees within the company. Element 0 is the highest ranked employee, and so forth. The returned ranking should minimize the number of messages sent from lower ranked employees to higher ranked employees. If multiple solutions are possible, return the one with element 0 minimal. If there are still ties, minimize element 1, etc.

Definition

Class:
CompanyMessages

Method:
getRank

Parameters:
vector <string>

Returns:
vector <int>

Method signature:
vector <int> getRank(vector <string> messages)

(be sure your method is public)

Constraints

-
messages will contain between 2 and 15 elements inclusive.

-
Each element of messages will contain exactly N characters, where N is the number of elements in messages.

-
Each character in messages will be a digit ('0'-'9').

-
Character i in element i of messages will be '0'.

鎸夌収棰樼洰璇存槑鍙煡錛屾寜鐓ф壘鍒扮殑欏哄簭錛屾墍鏈変粠浣庣駭鍚戦珮綰у彂鐨勪俊寰楁暟鐩拰搴旇鏄渶灝忕殑銆傚張瑙傚療鍒幫紝鍙紜畾浜?jiǎn)绗竴涓紝涔熷氨鏄駭鍒渶楂樼殑boss錛岄偅涔堝墿涓嬬殑鍛樺伐鎬庝箞鎺掑垪錛屼粬浠悜鏈楂榖oss 鍙戜俊鏁版槸涓嶅彉鐨勶紝浠庤屽瓙闂灝辨槸鍦ㄥ墿涓嬪憳宸ヤ腑鎵懼埌 浣庣駭鍚戦珮綰у彂淇℃暟鏈灝忕殑鎺掑垪 錛屾樉鐒惰繖絎﹀悎DP闂鏈浼樺瓙緇撴瀯鐨勯棶棰樸?/font>

T[1···N]=Min{sum(N <->{1-N-1},T[1-N-1] } 寰楀埌鐘舵佹柟紼嬪悗寰堝鏄撳啓鍑虹▼搴?錛屽彲浠ヤ嬌鐢ㄥ蹇樺綍dp

Code Snippet
#define REP(i, n) for (int i = 0; i < (n); ++i)

#define two(X) (1<<(X))
#define contain(S,X) ((S&two(X))>0)

int A[1<<15];
vector<vector<int> > vec(1<<15);
class CompanyMessages
{
        public:
        vector <int> getRank(vector <string> mes )
        {
            int n=mes.size();
            REP(mask,two(n)){
                if(!mask)continue;
                A[mask]=100000;
                REP(i,n)if(contain(mask,i)){
                    int now=mask^two(i); int tmp=A[now];
                    REP(j,n)if(contain(now,j))tmp+=(mes[j][i]-'0');
                    if(tmp<A[mask]){
                        vec[mask].clear();vec[mask].push_back(i);
                        for(int s=0;s<vec[now].size();s++)vec[mask].push_back(vec[now][s]);
                        A[mask]=tmp;
                    }
                }
            }
            return vec[two(n)-1];
        }

 

Code Snippet
int memo[two(15)],record[two(15)];
VS M;int N;VI ans;
int solve(int now){
    if( now == 0 ) return 0;
    if( memo[now]>=0 )return memo[now];
    memo[now] = 100000;
    REP(i,N)if(contain(now,i)){
        int mask = now ^ two(i);int tmp = solve(mask);
        REP(j,N)if(contain(mask,j))tmp += (M[j][i] - '0');
        if(tmp < memo[now]) {
            memo[now]=tmp ;
            record[now] = mask;
        }
    }
    return memo[now];
}
void cacl(){
    int mask = two(N)-1;
    ans.clear();
    REP(i,N){
        int k = mask ^ record[mask];
        int cnt = -1; while(k>0){k>>=1;cnt++;}
        ans.push_back(cnt);
        mask=record[mask];
    }
}
class CompanyMessages
{
        public:
        vector <int> getRank(vector <string> mes)
        {
               M=mes;N=mes.size();
               memset(memo,-1,sizeof(memo));
               solve(two(N)-1);
               cacl();
               return ans;
        }


rikisand 2009-11-22 15:58 鍙戣〃璇勮
]]>
SRM 453 div2http://www.shnenglu.com/zqsand/archive/2009/11/18/101316.htmlrikisandrikisandWed, 18 Nov 2009 07:24:00 GMThttp://www.shnenglu.com/zqsand/archive/2009/11/18/101316.htmlhttp://www.shnenglu.com/zqsand/comments/101316.htmlhttp://www.shnenglu.com/zqsand/archive/2009/11/18/101316.html#Feedback0http://www.shnenglu.com/zqsand/comments/commentRss/101316.htmlhttp://www.shnenglu.com/zqsand/services/trackbacks/101316.html鍗婂12錛?0鐨勬瘮璧涳紝寮濮嬪氨鍙戠幇緋葷粺寰堟參錛岀粨鏋滅涓棰樻病娉曟彁浜わ紝鐒跺悗閫鍑洪噸榪涢鍑洪噸榪?#183;····server down·····

鎯寵搗媧楃殑琛f湇榪樻病鎷匡紝浜庢槸璺戜笅鍘誨彇琛f湇錛岀湅浜?jiǎn)浼?xì)dota vod 錛岄噸鏂扮櫥鍏ワ紝姣旇禌绔熺劧緇х畫(huà)·····浜や簡(jiǎn)500 寮濮嬬湅1000 娌℃濊礬錛屽喕姝諱簡(jiǎn)銆?/font>

challenge娌″暐鎰忔濓紝閮芥病浜哄湪錛?50鐨勫お寮辨櫤閮藉鐨?#183;···鐢變簬涓棿鍑洪敊錛岃繖嬈rm not rated~~

250 pt 鐣ヨ繃

500 pt

John and Brus have an interest in team sports tournaments. They are currently investigating a basketball tournament. Basketball is a team sport in which two teams of five players try to score points against one another by placing a ball through a ten foot high hoop. Basketball is one of the most popular and widely viewed sports in the world.

There are n teams in the tournament. Each pair of teams plays exactly two games against each other. In the first of these games, one of the teams is the host, and in the second, the other team is the host. Each game results in one team winning. There are no draws. After the tournament is over, the team with the highest total number of wins is crowned the winner.

The tournament is currently in progress and the current results are described in the vector <string> table. For each pair of distinct indices, i and j, the j-th character of the i-th element of tableis the result of the game where team i hosted team j. The result is 'W' if team i won, 'L' if team i lost, and '?' if the game hasn't been played yet. Assuming that every possible outcome is possible for the games that haven't been played yet, return the minimal number of total wins the tournament winner can have at the end of the tournament.

Definition

Class:
TheBasketballDivTwo

Method:
find

Parameters:
vector <string>

Returns:
int

Method signature:
int find(vector <string> table)

(be sure your method is public)

Constraints

-
table will contain between 2 and 5 elements, inclusive.

-
Each element of table will contain exactly n characters, where n is the number of elements in table.

-
The j-th character of the i-th element of table, where i and j are different, will be 'W', 'L', or '?'.

-
The i-th character of the i-th element of table will be 'X'.

 

鏁版嵁閲忓緢灝忥紝鎵懼埌鏈瘮鐨勬瘮璧涘満嬈?錛岀劧鍚庢灇涓懼悇縐嶈緭璧㈡儏鍐碉紝鏇存柊瑙e氨鍙互浜?jiǎn)銆傛垨鑰呭驚鐜?^n嬈★紝鎴栬呴掑綊璋冪敤

1000 pt

n this tournament, each game results in either a victory for one team or a draw. If a team wins a game, it gains three points and its opponent gains no points. In case of a draw, each team gains one point. The score of a team is the sum of all the points it has gained from all its games. Each pair of teams can play against each other any number of times.

You are given a vector <int> points representing the current standings in the tournament. The i-th element of points is the score of the i-th team. You can assume that the points represent a valid state, i.e., intermediate standings that can be achieved in a tournament according to the rules described above.

Each team will play exactly one more game in the tournament, but it is not known what the matchups will be. After the tournament is over, the teams will be ranked by score. 1st place will go to the team with the highest score, 2nd place will go to the team with the second highest score, and so on. If two teams have the same score, the team with the lower number will place higher. For example, if team 0 and team 3 each have the highest score of 100 points, then team 0 will place 1st and team 3 will place 2nd.

John's favorite team is team 0, and he wants it to place as high as possible. Assuming that the remaining games can be scheduled arbitrarily and can end with any possible outcome, return the highest possible place for team 0 at the end of the tournament.

Definition

Class:
TheSoccerDivTwo

Method:
find

Parameters:
vector <int>

Returns:
int

Method signature:
int find(vector <int> points)

(be sure your method is public)

Constraints

-
points will contain between 2 and 50 elements, inclusive.

-
points will contain an even number of elements.

-
Each element of points will be between 0 and 1,000,000, inclusive.

-
points will represent a valid state.

Examples

Code Snippet
int find(vector <int> p )
{
     int E3=0,A3=0,L3=0,L=0;
     int d=p[0];
     for(int i=1;i<p.size();i++){
        if(p[i]>d+3)A3++;
        else if(p[i]==d+3)E3++;
        else if (p[i]>d)L3++;
        else L++;
     }
     if(A3+L+1>=E3)
         return A3+1;
     return A3+1+(E3-A3-L)/2;
}

 

 

 

鍥犱負(fù)姣忛槦鍙墿涓嬩竴鍦烘瘮璧涳紝鎵浠ラ鐩彉寰楀緢綆鍗曘?闃熸渶鍚庝竴杞偗瀹氭槸鍙栧埌3鍒嗭紝姣?闃熷3鍦轟互涓婃瘮璧涚殑 鑲畾姣?闃熼潬鍓嶏紝姣?闃熷垎灝戞垨鑰呯浉絳夌殑涓瀹氬湪0闃熶箣鍚庯紝鍓╀笅鐨勫氨鏄垜浠鑰冭檻鐨勪簡(jiǎn)銆傚鏋淎3+L+1>=E3 涔熷氨鏄姣?闃熷鑳滀竴鍦虹殑闃熶紞錛屽鏋滆浠栦滑鍦ㄦ渶鍚庝竴杞兘杈擄紝閭d箞0闃熷彲浠ヨ幏寰楁渶濂芥垚緇?A3+1;

鐒惰屽鏋滀笉琛屽墿涓嬬殑榪欎簺E3瑕佹湁涓鍗?E3+1)/2涓寰楀埌3鍒嗕粠鑰屾瘮0闃熼珮錛宱ver~



rikisand 2009-11-18 15:24 鍙戣〃璇勮
]]>
騫舵煡闆?/title><link>http://www.shnenglu.com/zqsand/archive/2009/11/12/100838.html</link><dc:creator>rikisand</dc:creator><author>rikisand</author><pubDate>Thu, 12 Nov 2009 14:03:00 GMT</pubDate><guid>http://www.shnenglu.com/zqsand/archive/2009/11/12/100838.html</guid><wfw:comment>http://www.shnenglu.com/zqsand/comments/100838.html</wfw:comment><comments>http://www.shnenglu.com/zqsand/archive/2009/11/12/100838.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.shnenglu.com/zqsand/comments/commentRss/100838.html</wfw:commentRss><trackback:ping>http://www.shnenglu.com/zqsand/services/trackbacks/100838.html</trackback:ping><description><![CDATA[ <p><strong>鏄ㄥぉ鐪嬩簡(jiǎn)sedgewick鐨刟lg in c 鐨勭涓绔狅紝涓昏浠嬬粛浜?jiǎn)涓猣ind-union 鍒ゆ柇鑱旈氱殑綆楁硶錛屽叾瀹炵敤鍒頒簡(jiǎn)騫舵煡闆嗙殑鐭ヨ瘑</strong></p> <p><strong>鍒氭墠鍋剁劧鐪嬭poj騫舵煡闆嗙殑棰橀泦 灝眂opy榪囨潵鑷繁涔熷啓鍐欑湅~~·</strong></p> <p><strong>鎱㈡參鏉~ 鍐欏畬涓閬撲笂涓閬搤~</strong></p> <p><strong>       POJ 1182 椋熺墿閾?/strong><br><a >http://acm.pku.edu.cn/JudgeOnline/problem?id=1182</a></p> <p><font face="寰蔣闆呴粦" color="#83c13e" size="4">榪樹(shù)互涓烘槸鏈綆鍗曠殑涓閬撳憿錛岃鍒楀湪鏈鍓嶉潰錛屽師鏉ユ槸鎵╁睍鐨勫簲鐢紝涓嶆槸閭d箞鐩存帴鍟妦</font></p> <p><font face="寰蔣闆呴粦" color="#83c13e" size="4">綰犵粨浜?jiǎn)涓浼?xì)鍎垮Q岀湅浜?jiǎn)瑙i鎶ュ憡鎵嶆湁鎬濊礬銆傚叧閿槸鍦ㄥ茍鏌ラ泦鐨勫熀紜涓婂鍔犱竴涓暟緇勶紝緇存姢鍏朵笌鏍硅妭鐐圭殑鍏崇郴錛?/font></p> <p><font face="寰蔣闆呴粦" color="#83c13e" size="4">璇︽儏鍐欏埌娉ㄩ噴閲岄潰鍚э細(xì)</font></p><pre class="code"><font size="2"><font face="Comic Sans MS"><span style="background: #2b2b2b; color: #0080ff">int </span><span style="background: #2b2b2b; color: white">A[</span><span style="background: #2b2b2b; color: #ff8080">100003</span><span style="background: #2b2b2b; color: white">][</span><span style="background: #2b2b2b; color: #ff8080">3</span></font></font><font size="2"><font face="Comic Sans MS"><span style="background: #2b2b2b; color: white">]; </span><span style="background: #2b2b2b; color: #0080ff">int </span><span style="background: #2b2b2b; color: white">root[</span><span style="background: #2b2b2b; color: #ff8080">50005</span><span style="background: #2b2b2b; color: white">],k[</span><span style="background: #2b2b2b; color: #ff8080">50005</span><span style="background: #2b2b2b; color: white">];</span></font></font><font size="2"><font face="Comic Sans MS"><span style="background: #2b2b2b; color: #00ff40">//root璁板綍鑺傜偣鎵灞炰簬鐨勬爲(wèi)鏈╥d k璁板綍鑺傜偣涓庢牴鐨勫叧緋? 鍚岀被1瀛愭槸椋熺墿2瀛愭槸澶╂晫 </span><span style="background: #2b2b2b; color: #0080ff">int </span><span style="background: #2b2b2b; color: white">sz[</span><span style="background: #2b2b2b; color: #ff8080">50005</span></font></font><font size="2"><font face="Comic Sans MS"><span style="background: #2b2b2b; color: white">]; </span><span style="background: #2b2b2b; color: #0080ff">int </span><span style="background: #2b2b2b; color: white">find(</span><span style="background: #2b2b2b; color: #0080ff">int </span></font></font><font size="2"><font face="Comic Sans MS"><span style="background: #2b2b2b; color: white">x){ </span><span style="background: #2b2b2b; color: #0080ff">if</span><span style="background: #2b2b2b; color: white">(root[x]==x)</span><span style="background: #2b2b2b; color: #0080ff">return </span></font></font><font size="2"><font face="Comic Sans MS"><span style="background: #2b2b2b; color: white">x;//濡傛灉鏄牴鍒欒繑鍥? </span><span style="background: #2b2b2b; color: #0080ff">else if</span><span style="background: #2b2b2b; color: white">(root[root[x]]==root[x])</span><span style="background: #2b2b2b; color: #0080ff">return </span></font></font><font size="2"><font face="Comic Sans MS"><span style="background: #2b2b2b; color: white">root[x];//濡傛灉絎竴灞傦紝鍒欒繑鍥? </span><span style="background: #2b2b2b; color: #0080ff">int </span></font></font><font size="2"><font face="Comic Sans MS"><span style="background: #2b2b2b; color: white">father=root[x]; root[x]=find(father);//鏀懼埌絎竴灞傦紝鍑忓皯涓嬫find鏃墮棿錛屽噺灝忔爲(wèi)鐨勯珮搴? k[x]=(k[x]+k[father])%</span><span style="background: #2b2b2b; color: #ff8080">3</span></font></font><font size="2"><font face="Comic Sans MS"><span style="background: #2b2b2b; color: white">;//鐢辮嚜宸變笌鏍圭殑鍏崇郴浠ュ強(qiáng)鐖惰妭鐐逛笌鏍圭殑鍏崇郴鎺ㄦ柇鍑烘柊鐨勮嚜宸變笌鏍圭殑鍏崇郴錛屽疄闄呬笂鏄負(fù)浜?jiǎn)瑙e喅union鍚庣殑鑺傜偣涓庢牴鐨勫叧緋?/span></font></font></pre><pre class="code"><font size="2"><font face="Comic Sans MS"><span style="background: #2b2b2b; color: white"> //鍥犱負(fù)union鍚庯紝闈炴牴鑺傜偣騫舵病鏈夋洿鏂発錛屽洜姝ら渶瑕佸湪姝ゅ澶勭悊鏇存柊 </span><span style="background: #2b2b2b; color: #0080ff">return </span></font></font><font size="2"><font face="Comic Sans MS"><span style="background: #2b2b2b; color: white">root[x]; } </span><span style="background: #2b2b2b; color: #0080ff">inline void </span><span style="background: #2b2b2b; color: white">Union(</span><span style="background: #2b2b2b; color: #0080ff">int </span><span style="background: #2b2b2b; color: white">x,</span><span style="background: #2b2b2b; color: #0080ff">int </span><span style="background: #2b2b2b; color: white">y,</span><span style="background: #2b2b2b; color: #0080ff">int </span></font></font><font size="2"><font face="Comic Sans MS"><span style="background: #2b2b2b; color: white">kind){ </span><span style="background: #2b2b2b; color: #0080ff">int </span><span style="background: #2b2b2b; color: white">a=find(x);</span><span style="background: #2b2b2b; color: #0080ff">int </span></font></font><span style="background: #2b2b2b; color: white"><font face="Comic Sans MS" size="2">b=find(y); </font></span><font size="2"><font face="Comic Sans MS"><span style="background: #2b2b2b; color: #00ff40"> </span><span style="background: #2b2b2b; color: #0080ff">if</span></font></font><span style="background: #2b2b2b; color: white"><font face="Comic Sans MS" size="2">(sz[a]>sz[b]){//鍒ゆ柇鍚庡喅瀹氾紝瑕佹妸size灝忕殑鏀懼埌size澶х殑涓婂幓錛屼紭鍖栦綔鐢ㄤ笉澶? root[b]=a ; </font></span><font size="2"><font face="Comic Sans MS"><span style="background: #2b2b2b; color: #00ff40">//b鎴愪負(fù)a鐨勫瓙鏍? </span><span style="background: #2b2b2b; color: white">k[b]=(k[x]-k[y]+kind+</span><span style="background: #2b2b2b; color: #ff8080">3</span><span style="background: #2b2b2b; color: white">)%</span><span style="background: #2b2b2b; color: #ff8080">3</span></font></font><font size="2"><font face="Comic Sans MS"><span style="background: #2b2b2b; color: white">;//瑕佹妸b鍙樻垚a鐨勫瓙鏍?wèi)锛屼粠a鍑哄彂錛屽埌x錛岀粡榪噆ind錛屽埌y錛屽啀鍒癰 錛屽彲浠ュ緱鍒発b鐨勭姸鎬佹敼鍙樺叕寮? sz[a]+=sz[b];} </span><span style="background: #2b2b2b; color: #0080ff">else</span></font></font><font size="2"><font face="Comic Sans MS"><span style="background: #2b2b2b; color: white">{ </span><span style="background: #2b2b2b; color: #0080ff">if</span><span style="background: #2b2b2b; color: white">(kind==</span><span style="background: #2b2b2b; color: #ff8080">1</span><span style="background: #2b2b2b; color: white">)kind=</span><span style="background: #2b2b2b; color: #ff8080">2</span></font></font><font size="2"><font face="Comic Sans MS"><span style="background: #2b2b2b; color: white">; root[a]=b; k[a]=(k[y]-k[x]+kind+</span><span style="background: #2b2b2b; color: #ff8080">3</span><span style="background: #2b2b2b; color: white">)%</span><span style="background: #2b2b2b; color: #ff8080">3</span></font></font><font size="2"><font face="Comic Sans MS"><span style="background: #2b2b2b; color: white">; sz[b]+=sz[a]; } } </span><span style="background: #2b2b2b; color: #0080ff">int </span></font></font><font size="2"><font face="Comic Sans MS"><span style="background: #2b2b2b; color: white">main() { </span><span style="background: #2b2b2b; color: #0080ff">int </span></font></font><font size="2"><font face="Comic Sans MS"><span style="background: #2b2b2b; color: white">N,d; freopen(</span><span style="background: #2b2b2b; color: #ff8000">"d:\\input.txt"</span><span style="background: #2b2b2b; color: white">,</span><span style="background: #2b2b2b; color: #ff8000">"r"</span></font></font><font size="2"><font face="Comic Sans MS"><span style="background: #2b2b2b; color: white">,stdin); scanf(</span><span style="background: #2b2b2b; color: #ff8000">"%d %d"</span></font></font><font size="2"><font face="Comic Sans MS"><span style="background: #2b2b2b; color: white">,&N,&d); </span><span style="background: #2b2b2b; color: #0080ff">for</span><span style="background: #2b2b2b; color: white">(</span><span style="background: #2b2b2b; color: #0080ff">int </span><span style="background: #2b2b2b; color: white">i=</span><span style="background: #2b2b2b; color: #ff8080">1</span><span style="background: #2b2b2b; color: white">;i<=N;i++)sz[i]=</span><span style="background: #2b2b2b; color: #ff8080">1</span></font></font><font size="2"><font face="Comic Sans MS"><span style="background: #2b2b2b; color: white">; </span><span style="background: #2b2b2b; color: #0080ff">int </span><span style="background: #2b2b2b; color: white">cnt=</span><span style="background: #2b2b2b; color: #ff8080">0</span></font></font><font size="2"><font face="Comic Sans MS"><span style="background: #2b2b2b; color: white">; </span><span style="background: #2b2b2b; color: #0080ff">for</span><span style="background: #2b2b2b; color: white">(</span><span style="background: #2b2b2b; color: #0080ff">int </span><span style="background: #2b2b2b; color: white">s=</span><span style="background: #2b2b2b; color: #ff8080">1</span></font></font><font size="2"><font face="Comic Sans MS"><span style="background: #2b2b2b; color: white">;s<=N;s++)root[s]=s; </span><span style="background: #2b2b2b; color: #0080ff">int </span><span style="background: #2b2b2b; color: white">LIE=</span><span style="background: #2b2b2b; color: #ff8080">0</span></font></font><font size="2"><font face="Comic Sans MS"><span style="background: #2b2b2b; color: white">; </span><span style="background: #2b2b2b; color: #0080ff">int </span><span style="background: #2b2b2b; color: white">i=</span><span style="background: #2b2b2b; color: #ff8080">0</span></font></font><font size="2"><font face="Comic Sans MS"><span style="background: #2b2b2b; color: white">; </span><span style="background: #2b2b2b; color: #0080ff">while</span></font></font><font size="2"><font face="Comic Sans MS"><span style="background: #2b2b2b; color: white">(i !=d) { scanf(</span><span style="background: #2b2b2b; color: #ff8000">"%d %d %d"</span><span style="background: #2b2b2b; color: white">,&A[i][</span><span style="background: #2b2b2b; color: #ff8080">0</span><span style="background: #2b2b2b; color: white">],&A[i][</span><span style="background: #2b2b2b; color: #ff8080">1</span><span style="background: #2b2b2b; color: white">],&A[i][</span><span style="background: #2b2b2b; color: #ff8080">2</span></font></font><font size="2"><font face="Comic Sans MS"><span style="background: #2b2b2b; color: white">]); </span><span style="background: #2b2b2b; color: #0080ff">if</span><span style="background: #2b2b2b; color: white">(A[i][</span><span style="background: #2b2b2b; color: #ff8080">1</span><span style="background: #2b2b2b; color: white">]>N || A[i][</span><span style="background: #2b2b2b; color: #ff8080">2</span><span style="background: #2b2b2b; color: white">]>N ) {LIE++;i++;</span><span style="background: #2b2b2b; color: #0080ff">continue</span></font></font><font size="2"><font face="Comic Sans MS"><span style="background: #2b2b2b; color: white">;} </span><span style="background: #2b2b2b; color: #0080ff">if</span><span style="background: #2b2b2b; color: white">(A[i][</span><span style="background: #2b2b2b; color: #ff8080">0</span><span style="background: #2b2b2b; color: white">]==</span><span style="background: #2b2b2b; color: #ff8080">1</span></font></font><font size="2"><font face="Comic Sans MS"><span style="background: #2b2b2b; color: white">){ </span><span style="background: #2b2b2b; color: #0080ff">if</span><span style="background: #2b2b2b; color: white">(find(A[i][</span><span style="background: #2b2b2b; color: #ff8080">1</span><span style="background: #2b2b2b; color: white">]) == find(A[i][</span><span style="background: #2b2b2b; color: #ff8080">2</span></font></font><font size="2"><font face="Comic Sans MS"><span style="background: #2b2b2b; color: white">])){ </span><span style="background: #2b2b2b; color: #0080ff">if</span><span style="background: #2b2b2b; color: white">(k[A[i][</span><span style="background: #2b2b2b; color: #ff8080">1</span><span style="background: #2b2b2b; color: white">]]!=k[A[i][</span><span style="background: #2b2b2b; color: #ff8080">2</span></font></font><font size="2"><font face="Comic Sans MS"><span style="background: #2b2b2b; color: white">]]) LIE++; } </span><span style="background: #2b2b2b; color: #0080ff">else </span><span style="background: #2b2b2b; color: white">Union(A[i][</span><span style="background: #2b2b2b; color: #ff8080">1</span><span style="background: #2b2b2b; color: white">],A[i][</span><span style="background: #2b2b2b; color: #ff8080">2</span><span style="background: #2b2b2b; color: white">],</span><span style="background: #2b2b2b; color: #ff8080">0</span></font></font><font size="2"><font face="Comic Sans MS"><span style="background: #2b2b2b; color: white">); } </span><span style="background: #2b2b2b; color: #0080ff">else</span></font></font><font size="2"><font face="Comic Sans MS"><span style="background: #2b2b2b; color: white">{ </span><span style="background: #2b2b2b; color: #0080ff">if</span><span style="background: #2b2b2b; color: white">( find(A[i][</span><span style="background: #2b2b2b; color: #ff8080">1</span><span style="background: #2b2b2b; color: white">])==find(A[i][</span><span style="background: #2b2b2b; color: #ff8080">2</span><span style="background: #2b2b2b; color: white">]) ){</span><span style="background: #2b2b2b; color: #0080ff">if</span><span style="background: #2b2b2b; color: white">(k[A[i][</span><span style="background: #2b2b2b; color: #ff8080">2</span><span style="background: #2b2b2b; color: white">]] != ( k[A[i][</span><span style="background: #2b2b2b; color: #ff8080">1</span><span style="background: #2b2b2b; color: white">]]+</span><span style="background: #2b2b2b; color: #ff8080">1</span><span style="background: #2b2b2b; color: white">)%</span><span style="background: #2b2b2b; color: #ff8080">3</span></font></font><font size="2"><font face="Comic Sans MS"><span style="background: #2b2b2b; color: white">)LIE++;} </span><span style="background: #2b2b2b; color: #0080ff">else </span><span style="background: #2b2b2b; color: white">Union(A[i][</span><span style="background: #2b2b2b; color: #ff8080">1</span><span style="background: #2b2b2b; color: white">],A[i][</span><span style="background: #2b2b2b; color: #ff8080">2</span><span style="background: #2b2b2b; color: white">],</span><span style="background: #2b2b2b; color: #ff8080">1</span></font></font><font size="2"><font face="Comic Sans MS"><span style="background: #2b2b2b; color: white">); } i++; } cout<<LIE<<endl; </span><span style="background: #2b2b2b; color: #0080ff">return </span><span style="background: #2b2b2b; color: #ff8080">0</span></font></font><span style="background: #2b2b2b; color: white"><font face="Comic Sans MS" size="2">; }</font></span></pre><a ></a><strong>POJ 1611 The Suspects</strong><br> <p><a >http://acm.pku.edu.cn/JudgeOnline/problem?id=1611</a></p> <p><br></p><pre class="code"><span style="background: #2b2b2b; color: white"> </span><font size="4"><font face="Comic Sans MS"><span style="background: #2b2b2b; color: #0080ff">int </span><span style="background: #2b2b2b; color: white">G[</span><span style="background: #2b2b2b; color: #ff8080">30005</span></font></font><font size="4"><font face="Comic Sans MS"><span style="background: #2b2b2b; color: white">]; </span><span style="background: #2b2b2b; color: #0080ff">int </span><span style="background: #2b2b2b; color: white">sz[</span><span style="background: #2b2b2b; color: #ff8080">30005</span></font></font><font size="4"><font face="Comic Sans MS"><span style="background: #2b2b2b; color: white">]; </span><span style="background: #2b2b2b; color: #0080ff">int </span><span style="background: #2b2b2b; color: white">Find(</span><span style="background: #2b2b2b; color: #0080ff">int </span></font></font><font size="4"><font face="Comic Sans MS"><span style="background: #2b2b2b; color: white">x){ </span><span style="background: #2b2b2b; color: #0080ff">if</span><span style="background: #2b2b2b; color: white">(G[x]==x)</span><span style="background: #2b2b2b; color: #0080ff">return </span></font></font><font size="4"><font face="Comic Sans MS"><span style="background: #2b2b2b; color: white">x; </span><span style="background: #2b2b2b; color: #0080ff">else </span></font></font><font size="4"><font face="Comic Sans MS"><span style="background: #2b2b2b; color: white">{ </span><span style="background: #2b2b2b; color: #0080ff">while</span></font></font><font size="4"><font face="Comic Sans MS"><span style="background: #2b2b2b; color: white">(G[x]!=x){//half璺緞鍘嬬緝~絳変笅璇曡瘯鐪嬪叏鍘嬬緝鐨勬晥鐜噡閭f牱灝辨槸閫掑綊璋冪敤鍟? </span><span style="background: #2b2b2b; color: #0080ff">int </span></font></font><font size="4"><font face="Comic Sans MS"><span style="background: #2b2b2b; color: white">t=G[x]; G[x]=G[t]; x=t; } </span><span style="background: #2b2b2b; color: #0080ff">return </span></font></font><font size="4"><font face="Comic Sans MS"><span style="background: #2b2b2b; color: white">x; } } </span><span style="background: #2b2b2b; color: #0080ff">void </span><span style="background: #2b2b2b; color: white">Union(</span><span style="background: #2b2b2b; color: #0080ff">int </span><span style="background: #2b2b2b; color: white">x,</span><span style="background: #2b2b2b; color: #0080ff">int </span></font></font><font size="4"><font face="Comic Sans MS"><span style="background: #2b2b2b; color: white">y){ </span><span style="background: #2b2b2b; color: #0080ff">if</span></font></font><font size="4"><font face="Comic Sans MS"><span style="background: #2b2b2b; color: white">(sz[x]<sz[y])swap(x,y);//鎶妔ize灝忕殑寮勫埌澶х殑涓婇潰 G[y]=x; sz[x]+=sz[y]; } </span><span style="background: #2b2b2b; color: #0080ff">int </span></font></font><font size="4"><font face="Comic Sans MS"><span style="background: #2b2b2b; color: white">main() { freopen(</span><span style="background: #2b2b2b; color: #ff8000">"d:\\input.txt"</span><span style="background: #2b2b2b; color: white">,</span><span style="background: #2b2b2b; color: #ff8000">"r"</span></font></font><font size="4"><font face="Comic Sans MS"><span style="background: #2b2b2b; color: white">,stdin); </span><span style="background: #2b2b2b; color: #0080ff">int </span></font></font><font size="4"><font face="Comic Sans MS"><span style="background: #2b2b2b; color: white">N,M,num; </span><span style="background: #2b2b2b; color: #0080ff">while</span><span style="background: #2b2b2b; color: white">(</span><span style="background: #2b2b2b; color: #0080ff">true</span></font></font><font size="4"><font face="Comic Sans MS"><span style="background: #2b2b2b; color: white">){ scanf(</span><span style="background: #2b2b2b; color: #ff8000">"%d %d"</span></font></font><font size="4"><font face="Comic Sans MS"><span style="background: #2b2b2b; color: white">,&N,&M); </span><span style="background: #2b2b2b; color: #0080ff">if</span><span style="background: #2b2b2b; color: white">(N==</span><span style="background: #2b2b2b; color: #ff8080">0</span><span style="background: #2b2b2b; color: white">&&M==</span><span style="background: #2b2b2b; color: #ff8080">0</span><span style="background: #2b2b2b; color: white">)</span><span style="background: #2b2b2b; color: #0080ff">return </span><span style="background: #2b2b2b; color: #ff8080">0</span></font></font><font size="4"><font face="Comic Sans MS"><span style="background: #2b2b2b; color: white">; </span><span style="background: #2b2b2b; color: #0080ff">for</span><span style="background: #2b2b2b; color: white">(</span><span style="background: #2b2b2b; color: #0080ff">int </span><span style="background: #2b2b2b; color: white">i=</span><span style="background: #2b2b2b; color: #ff8080">0</span><span style="background: #2b2b2b; color: white">;i<N;i++)G[i]=i,sz[i]=</span><span style="background: #2b2b2b; color: #ff8080">1</span></font></font><font size="4"><font face="Comic Sans MS"><span style="background: #2b2b2b; color: white">; </span><span style="background: #2b2b2b; color: #0080ff">for</span><span style="background: #2b2b2b; color: white">(</span><span style="background: #2b2b2b; color: #0080ff">int </span><span style="background: #2b2b2b; color: white">i=</span><span style="background: #2b2b2b; color: #ff8080">0</span></font></font><font size="4"><font face="Comic Sans MS"><span style="background: #2b2b2b; color: white">;i<M;i++){ scanf(</span><span style="background: #2b2b2b; color: #ff8000">"%d"</span></font></font><font size="4"><font face="Comic Sans MS"><span style="background: #2b2b2b; color: white">,&num); </span><span style="background: #2b2b2b; color: #0080ff">int </span></font></font><font size="4"><font face="Comic Sans MS"><span style="background: #2b2b2b; color: white">root,stu,x,y; </span><span style="background: #2b2b2b; color: #0080ff">for</span><span style="background: #2b2b2b; color: white">(</span><span style="background: #2b2b2b; color: #0080ff">int </span><span style="background: #2b2b2b; color: white">j=</span><span style="background: #2b2b2b; color: #ff8080">0</span></font></font><font size="4"><font face="Comic Sans MS"><span style="background: #2b2b2b; color: white">;j<num;j++){ scanf(</span><span style="background: #2b2b2b; color: #ff8000">"%d"</span></font></font><font size="4"><font face="Comic Sans MS"><span style="background: #2b2b2b; color: white">,&stu); </span><span style="background: #2b2b2b; color: #0080ff">if</span><span style="background: #2b2b2b; color: white">(j==</span><span style="background: #2b2b2b; color: #ff8080">0</span></font></font><font size="4"><font face="Comic Sans MS"><span style="background: #2b2b2b; color: white">)root=Find(stu);//綆鍗曠殑閮藉拰絎竴涓悎騫? </span><span style="background: #2b2b2b; color: #0080ff">else</span></font></font><font size="4"><font face="Comic Sans MS"><span style="background: #2b2b2b; color: white">{ root=Find(root); x=Find(stu);</span><span style="background: #2b2b2b; color: #0080ff">if</span></font></font><font size="4"><font face="Comic Sans MS"><span style="background: #2b2b2b; color: white">(root!=x)Union(root,x); } } } printf(</span><span style="background: #2b2b2b; color: #ff8000">"%d\n"</span><span style="background: #2b2b2b; color: white">,sz[Find(</span><span style="background: #2b2b2b; color: #ff8080">0</span></font></font><span style="background: #2b2b2b; color: white"><font face="Comic Sans MS" size="4">)]); } }</font></span></pre> <p><a ></a><strong>POJ 2524 Ubiquitous Religions</strong></p> <p><strong>鍙堜竴閬撴按棰榽~ 鍛靛懙  </strong></p> <p><strong>涓嶈創(chuàng)浠g爜浜?鍜屼笂闈竴閬撳熀鏈竴鏍穨</strong><br><a >http://acm.pku.edu.cn/JudgeOnline/problem?id=2524</a></p> <p><font size="2"><strong>POJ 1861</strong></font></p> <p><a >http://acm.pku.edu.cn/JudgeOnline/problem?id=1861</a></p> <p><font size="2"><strong>kruskal+騫舵煡闆?half璺緞鍘嬬緝</strong></font></p> <p><strong><font size="2">姣旇緝鍩虹鐨勯</font></strong></p><pre class="code"><span style="background: #2b2b2b; color: #0080ff"><font face="Comic Sans MS" size="4"><em>struct </em></font></span><font size="4"><font face="Comic Sans MS"><em><span style="background: #2b2b2b; color: white">Edge{ </span><span style="background: #2b2b2b; color: #0080ff">int </span></em></font></font><font size="4"><font face="Comic Sans MS"><em><span style="background: #2b2b2b; color: white">from; </span><span style="background: #2b2b2b; color: #0080ff">int </span></em></font></font><font size="4"><font face="Comic Sans MS"><em><span style="background: #2b2b2b; color: white">to; </span><span style="background: #2b2b2b; color: #0080ff">int </span></em></font></font><font size="4"><font face="Comic Sans MS"><em><span style="background: #2b2b2b; color: white">value; }E[</span><span style="background: #2b2b2b; color: #ff8080">15000</span></em></font></font><font size="4"><font face="Comic Sans MS"><em><span style="background: #2b2b2b; color: white">]; </span><span style="background: #2b2b2b; color: #0080ff">int </span><span style="background: #2b2b2b; color: white">A[</span><span style="background: #2b2b2b; color: #ff8080">1005</span></em></font></font><font size="4"><font face="Comic Sans MS"><em><span style="background: #2b2b2b; color: white">]; </span><span style="background: #2b2b2b; color: #0080ff">int </span><span style="background: #2b2b2b; color: white">sz[</span><span style="background: #2b2b2b; color: #ff8080">2009</span></em></font></font><font size="4"><font face="Comic Sans MS"><em><span style="background: #2b2b2b; color: white">]; </span><span style="background: #2b2b2b; color: #0080ff">bool </span><span style="background: #2b2b2b; color: white">comp(</span><span style="background: #2b2b2b; color: #0080ff">const </span><span style="background: #2b2b2b; color: white">Edge& a,</span><span style="background: #2b2b2b; color: #0080ff">const </span></em></font></font><font size="4"><font face="Comic Sans MS"><em><span style="background: #2b2b2b; color: white">Edge& b){ </span><span style="background: #2b2b2b; color: #0080ff">return </span></em></font></font><font size="4"><font face="Comic Sans MS"><em><span style="background: #2b2b2b; color: white">a.value<b.value; } </span><span style="background: #2b2b2b; color: #0080ff">using namespace </span></em></font></font><font size="4"><font face="Comic Sans MS"><em><span style="background: #2b2b2b; color: white">std; </span><span style="background: #2b2b2b; color: #0080ff">int </span><span style="background: #2b2b2b; color: white">Find(</span><span style="background: #2b2b2b; color: #0080ff">int </span></em></font></font><font size="4"><font face="Comic Sans MS"><em><span style="background: #2b2b2b; color: white">x){ </span><span style="background: #2b2b2b; color: #0080ff">if</span><span style="background: #2b2b2b; color: white">(A[x]==x)</span><span style="background: #2b2b2b; color: #0080ff">return </span></em></font></font><font size="4"><font face="Comic Sans MS"><em><span style="background: #2b2b2b; color: white">x; </span><span style="background: #2b2b2b; color: #0080ff">else if</span><span style="background: #2b2b2b; color: white">(A[A[x]]==A[x]) </span><span style="background: #2b2b2b; color: #0080ff">return </span></em></font></font><font size="4"><font face="Comic Sans MS"><em><span style="background: #2b2b2b; color: white">A[x]; </span><span style="background: #2b2b2b; color: #0080ff">int </span></em></font></font><font size="4"><font face="Comic Sans MS"><em><span style="background: #2b2b2b; color: white">father; </span><span style="background: #2b2b2b; color: #0080ff">while</span></em></font></font><font size="4"><font face="Comic Sans MS"><em><span style="background: #2b2b2b; color: white">(A[x]!=x){ father=A[x]; A[x]=A[father];//鎶婃瘡涓涓礬榪囩殑鑺傜偣鏀懼埌紲栫埗涓嬮潰鍘? x=father; } </span><span style="background: #2b2b2b; color: #0080ff">return </span></em></font></font><font size="4"><font face="Comic Sans MS"><em><span style="background: #2b2b2b; color: white">x; } </span><span style="background: #2b2b2b; color: #0080ff">void </span><span style="background: #2b2b2b; color: white">Union(</span><span style="background: #2b2b2b; color: #0080ff">int </span><span style="background: #2b2b2b; color: white">x,</span><span style="background: #2b2b2b; color: #0080ff">int </span></em></font></font><font size="4"><font face="Comic Sans MS"><em><span style="background: #2b2b2b; color: white">y){ </span><span style="background: #2b2b2b; color: #0080ff">if</span></em></font></font><font size="4"><font face="Comic Sans MS"><em><span style="background: #2b2b2b; color: white">(sz[y]>sz[x])swap(x,y);//灝忕殑鏀懼埌澶х殑涓嬮潰 sz[x]+=sz[y]; A[y]=x; } </span><span style="background: #2b2b2b; color: #0080ff">int </span></em></font></font><font size="4"><font face="Comic Sans MS"><em><span style="background: #2b2b2b; color: white">main() { freopen(</span><span style="background: #2b2b2b; color: #ff8000">"d:\\input.txt"</span><span style="background: #2b2b2b; color: white">,</span><span style="background: #2b2b2b; color: #ff8000">"r"</span></em></font></font><font size="4"><font face="Comic Sans MS"><em><span style="background: #2b2b2b; color: white">,stdin); </span><span style="background: #2b2b2b; color: #0080ff">int </span></em></font></font><font size="4"><font face="Comic Sans MS"><em><span style="background: #2b2b2b; color: white">N,M,num,x,y; scanf(</span><span style="background: #2b2b2b; color: #ff8000">"%d %d"</span></em></font></font><font size="4"><font face="Comic Sans MS"><em><span style="background: #2b2b2b; color: white">,&N,&M); </span><span style="background: #2b2b2b; color: #0080ff">int </span><span style="background: #2b2b2b; color: white">cnt=</span><span style="background: #2b2b2b; color: #ff8080">0</span></em></font></font><font size="4"><font face="Comic Sans MS"><em><span style="background: #2b2b2b; color: white">; </span><span style="background: #2b2b2b; color: #0080ff">while</span><span style="background: #2b2b2b; color: white">(cnt<M) scanf(</span><span style="background: #2b2b2b; color: #ff8000">"%d %d %d"</span></em></font></font><font size="4"><font face="Comic Sans MS"><em><span style="background: #2b2b2b; color: white">,&E[cnt].from,&E[cnt].to,&E[cnt].value),cnt++; sort(E,E+M,comp);//浠庡皬鍒板ぇ閫塶-1鏉¤竟錛屽鏋滆搗鐐瑰拰緇堢偣鍦ㄤ竴涓泦鍚堝垯continue錛沞lse Union </span><span style="background: #2b2b2b; color: #0080ff">for</span><span style="background: #2b2b2b; color: white">(</span><span style="background: #2b2b2b; color: #0080ff">int </span><span style="background: #2b2b2b; color: white">i=</span><span style="background: #2b2b2b; color: #ff8080">0</span><span style="background: #2b2b2b; color: white">;i<=N;i++)sz[i]=</span><span style="background: #2b2b2b; color: #ff8080">1</span></em></font></font><font size="4"><font face="Comic Sans MS"><em><span style="background: #2b2b2b; color: white">,A[i]=i; vector<</span><span style="background: #2b2b2b; color: #0080ff">int</span><span style="background: #2b2b2b; color: white">> ans(N-</span><span style="background: #2b2b2b; color: #ff8080">1</span></em></font></font><font size="4"><font face="Comic Sans MS"><em><span style="background: #2b2b2b; color: white">); </span><span style="background: #2b2b2b; color: #0080ff">int </span><span style="background: #2b2b2b; color: white">mst=</span><span style="background: #2b2b2b; color: #ff8080">0</span><span style="background: #2b2b2b; color: white">,MX=</span><span style="background: #2b2b2b; color: #ff8080">0</span></em></font></font><font size="4"><font face="Comic Sans MS"><em><span style="background: #2b2b2b; color: white">; </span><span style="background: #2b2b2b; color: #0080ff">for</span><span style="background: #2b2b2b; color: white">(</span><span style="background: #2b2b2b; color: #0080ff">int </span><span style="background: #2b2b2b; color: white">i=</span><span style="background: #2b2b2b; color: #ff8080">0</span><span style="background: #2b2b2b; color: white">;mst!=N-</span><span style="background: #2b2b2b; color: #ff8080">1</span></em></font></font><font size="4"><font face="Comic Sans MS"><em><span style="background: #2b2b2b; color: white">;i++){ </span><span style="background: #2b2b2b; color: #0080ff">int </span><span style="background: #2b2b2b; color: white">x=Find(E[i].from);</span><span style="background: #2b2b2b; color: #0080ff">int </span></em></font></font><font size="4"><font face="Comic Sans MS"><em><span style="background: #2b2b2b; color: white">y=Find(E[i].to); </span><span style="background: #2b2b2b; color: #0080ff">if</span><span style="background: #2b2b2b; color: white">(x==y)</span><span style="background: #2b2b2b; color: #0080ff">continue</span></em></font></font><font size="4"><font face="Comic Sans MS"><em><span style="background: #2b2b2b; color: white">; Union(x,y); ans[mst]=i; mst++; </span><span style="background: #2b2b2b; color: #0080ff">if</span></em></font></font><font size="4"><font face="Comic Sans MS"><em><span style="background: #2b2b2b; color: white">(E[i].value>MX)MX=E[i].value; } printf(</span><span style="background: #2b2b2b; color: #ff8000">"%d\n%d\n"</span><span style="background: #2b2b2b; color: white">,MX,N-</span><span style="background: #2b2b2b; color: #ff8080">1</span></em></font></font><font size="4"><font face="Comic Sans MS"><em><span style="background: #2b2b2b; color: white">); </span><span style="background: #2b2b2b; color: #0080ff">for</span><span style="background: #2b2b2b; color: white">(</span><span style="background: #2b2b2b; color: #0080ff">int </span><span style="background: #2b2b2b; color: white">i=</span><span style="background: #2b2b2b; color: #ff8080">0</span><span style="background: #2b2b2b; color: white">;i<N-</span><span style="background: #2b2b2b; color: #ff8080">1</span></em></font></font><font size="4"><font face="Comic Sans MS"><em><span style="background: #2b2b2b; color: white">;i++) printf(</span><span style="background: #2b2b2b; color: #ff8000">"%d %d\n"</span></em></font></font><span style="background: #2b2b2b; color: white"><font face="Comic Sans MS" size="4"><em>,E[ans[i]].from,E[ans[i]].to); }</em></font></span></pre><a ></a> <p><br> <strong>       POJ 1456 Supermarket</strong><br><a >http://acm.pku.edu.cn/JudgeOnline/problem?id=1456</a><br> </p> <p><strong>       POJ 1733 Parity game</strong><br><a >http://acm.pku.edu.cn/JudgeOnline/problem?id=1733</a><br>  </p><p><strong>       hdu 3038 How Many Answers Are Wrong</strong><br><a >http://acm.hdu.edu.cn/showproblem.php?pid=3038</a><br>  </p><p><strong>     POJ 1417 True Liars(闅?</strong><br><a >http://acm.pku.edu.cn/JudgeOnline/problem?id=1417</a><br>  </p><p><strong>   POJ 2912 Rochambeau(闅?</strong> </p><p><a >http://acm.pku.edu.cn/JudgeOnline/problem?id=2912</a></p><img src ="http://www.shnenglu.com/zqsand/aggbug/100838.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.shnenglu.com/zqsand/" target="_blank">rikisand</a> 2009-11-12 22:03 <a href="http://www.shnenglu.com/zqsand/archive/2009/11/12/100838.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>TC-srm249-Tableseat-DP-鐘舵佹帓鍒?/title><link>http://www.shnenglu.com/zqsand/archive/2009/11/12/100835.html</link><dc:creator>rikisand</dc:creator><author>rikisand</author><pubDate>Thu, 12 Nov 2009 13:45:00 GMT</pubDate><guid>http://www.shnenglu.com/zqsand/archive/2009/11/12/100835.html</guid><wfw:comment>http://www.shnenglu.com/zqsand/comments/100835.html</wfw:comment><comments>http://www.shnenglu.com/zqsand/archive/2009/11/12/100835.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.shnenglu.com/zqsand/comments/commentRss/100835.html</wfw:commentRss><trackback:ping>http://www.shnenglu.com/zqsand/services/trackbacks/100835.html</trackback:ping><description><![CDATA[ <p>Your restaurant has <strong>numTables</strong> tables to seat customers. The tables are all arranged in a line. If a large party of customers comes in, a group of adjacent tables will be used. Which group of tables is entirely up to the customer. Since you cannot predict this, assume all possible choices occur with equal probability. What you can predict is the size of each group of customers that arrives. Element i of <strong>probs</strong> gives the probability, in percent, that an entering party will need i+1 tables. Assuming nobody leaves, return the expected number of tables you will use before a party must be turned away. This only occurs if there is no place to seat them. </p><h5>Method signature:<br>double getExpected(int numTables, vector <int> probs)</h5> <p><strong>numTables</strong> will be between 1 and 12 inclusive.<br><strong>probs</strong> will contain between 1 and 12 elements inclusive.<br>Each element of <strong>probs</strong> will be between 0 and 100 inclusive.<br>The elements of <strong>probs</strong> will sum to 100. </p><p>  </p><p><font face="寰蔣闆呴粦" color="#008080" size="4">misof 鏁板瓧琛ㄨ揪鏁欑▼閲岀殑涔?fàn)棰榽 棰樼洰澶ф剰 姹備嬌鐢ㄦ瀛愮殑鏈熸湜銆傜敱浜庡埌鏉roup鐨勪釜鏁頒笉瀹氾紝姣忎釜group闇瑕佺殑妗屽瓙涓嶅畾錛屼嬌紜畾鏈熸湜鍙樺緱鍥伴毦銆備絾鑰冭檻瀵逛簬numTables鏉ヨ,浣跨敤妗屽瓙鐨勭姸鎬佷粎浠呮湁 2^numTables縐嶏紝鍥犳鑰冭檻鍦ㄨ繖浜涚姸鎬佹敼鍙樼殑榪囩▼涓潵璁$畻鏈熸湜錛屼篃灝辨槸璁$畻鍦ㄦ瘡涓姸鎬佷笅闈㈢殑鏈熸湜妗屽瓙鏁扮洰銆傚湪姣忎釜鐘舵佸埌杈炬椂錛屼緷嬈¤冭檻鏉ヤ簡(jiǎn)涓涓猤roup闇瑕乲涓綅瀛愶紝濡傛灉r縐嶅畨鎺掑彲浠ユ弧瓚砶涓綅瀛愶紝閭d箞褰撳墠鐘舵佺殑鏈熸湜鍊艱鍔犱笂 鏉涓綅瀛愮殑姒傜巼 X 錛坮縐嶅畨鎺掑垎鍒殑鏈熸湜鍜?/ r錛?鍏朵腑姹俽涓畨鎺掓湡鏈涘拰鍒欓渶瑕?閫掑綊璋冪敤鍑芥暟銆傛樉鐒跺埄鐢╩emo鍙互鍑忓皯閲嶅璁$畻浜庢槸鏈変笅闈㈢殑瑙f硶錛?/font> </p><p><font face="Comic Sans MS" size="2">vector<double> p;<br>double dp[1<<13];    <br>int tb;<br>double solve(int cur){<br>    if(dp[cur]>-1.0)return dp[cur];    //memo available<br>    double ret=0;double sum;int kind;<br>    for(int i=0;i<p.size();i++){<br>        sum=0,kind=0;<br>        int mask=(1<<(i+1))-1;    //new group need i+1 adjacent tables<br>        for(int j=0;j+i+1<=tb;j++){<br>            if((cur&(mask<<j))==0){    //current pattern could meet the need<br>                sum+=solve(cur+(mask<<j))+i+1;    //total method ++<br>                kind++; <br>            }<br>        }<br>        if(kind!=0)sum/=kind; //caculate the average need<br>        ret+=sum*p[i];<br>    }<br>    dp[cur]=ret;<br>    return ret;<br>}</font> </p><p><font face="Comic Sans MS" size="2">        double getExpected(int numTables, vector <int> probs)<br>        {<br>                tb=numTables;<br>                REP(i,1<<13)dp[i]=-1.0;<br>                p.resize(probs.size());<br>                for(int i=0;i<probs.size();i++)p[i]=probs[i]*0.01;<br>                return solve(0);//the beginning pattern<br>        }</font> </p><p><font color="#ff8040" size="3">鐪嬫瘮璧涗腑鏈夊彟涓縐嶈В娉曪紝鍗蟲(chóng)牴鎹鐩紝鍦ㄥ埌杈炬瘡嬈ail to serve a group 鐨勬椂鍊?鏍規(guī)嵁姝ゆ椂鐨勬瀛愭暟閲忥紝鍜屽埌杈捐繖縐嶇姸鎬佺殑姒傜巼 鏉ヨ綆楋細(xì)</font></p> <p><font color="#ff8040" size="3">dp[1<<13][15];memset(dp,0,sizeof(dp));// :D lucily I can do this for 0 </font></p> <p><font color="#ff8040" size="3">double fails=0.0;bool flag ;</font></p> <p><font color="#ff8040" size="3">for(int i=1;i<=numTables+1;i++)  //寰幆鏈澶歯umTables+1 嬈?/font></p> <p><font color="#ff8040" size="3">{flag=true;</font></p> <blockquote> <p><font color="#ff8040" size="3">for(int j=0;j<p.size();j++){</font></p> <p><font color="#ff8040" size="3">     int mask=(1<<(j+1))-1;//娉ㄦ剰縐諱綅榪愮畻絎︾殑浼樺厛綰т綆,娉ㄦ剰鍔犳嫭鍙?/font></p> <p><font color="#ff8040" size="3">     for(int k=0;k<=(1<<numTables-1);k++){</font></p> <p><font color="#ff8040" size="3">          if(dp[k][i-1]<=0.0)continue;</font></p> <p><font color="#ff8040" size="3">          flag=false;</font></p> <p><font color="#ff8040" size="3">          int cnt=0;</font></p> <p><font color="#ff8040" size="3">          for(int m=0;m+j+1<=numTables;m++) if((mask<<m)&k==0)cnt++;</font></p> <p><font color="#ff8040" size="3">          if(cnt)for(int m=0;m+j+1<=numTables;m++)if((mask<<m)&k==0)dp[mask<<m|k][i]+=dp[k][i-1]*p[j]/cnt;</font></p> <p><font color="#ff8040" size="3">          if(!cnt){</font></p> <p><font color="#ff8040" size="3">                 int b=k,bn=0;while(b){if(b&1)bn++;b>>=1;}</font></p> <p><font color="#ff8040" size="3">                 fail+=dp[k][i-1]*bn;  </font></p> <p><font color="#ff8040" size="3">         }</font></p> <p><font color="#ff8040" size="3">    }</font></p> <p><font color="#ff8040" size="3">}</font></p> <p><font color="#ff8040" size="3">if(flag)return fail;//all dp[][k]==0.0</font></p></blockquote> <p><font color="#ff8040" size="3">}</font></p> <p><font color="#ff8040" size="3">return fail;</font></p> <p><font size="3"></font><font color="#ff8040"> </font></p> <p><font color="#ff8040" size="3">浼樺厛綰у緢瀹規(guī)槗閿欙細(xì)</font></p> <p><a ><font color="#ff8040">http://www.cppreference.com/wiki/operator_precedence</font></a><font color="#ff8040" size="3">~銆倊</font></p> <p><font color="#ff8040" size="3">鍏稿瀷鐨勫嚑涓?/font></p> <p><font color="#ff8040" size="3">++ -- <post-incre-decre></font></p> <p><font color="#ff8040" size="3">~ <bitwise complement> !<not>&<addresss> *<dereference>&<address></font></p> <p><font color="#ff8040" size="3">*  / % </font></p> <p><font color="#ff8040" size="3">+ -</font></p> <p><font color="#ff8040" size="3">>>  <<</font></p> <p><font color="#ff8040" size="3">< <= > >=</font></p> <p><font color="#ff8040" size="3">== !=</font></p> <p><font color="#ff8040" size="3">&</font></p> <p><font color="#ff8040" size="3">^ xor</font></p> <p><font color="#ff8040" size="3">|</font></p> <p><font color="#ff8040" size="3">&&</font></p> <p><font color="#ff8040" size="3">||</font></p> <p><font color="#ff8040" size="3">?=</font></p> <p><font color="#ff8040" size="3">= += –= <<= >>=</font></p> <p><font color="#ff8040" size="3">,</font></p> <p><font size="3"></font><font color="#ff8040"> </font></p> <p><font color="#ff8040" size="3">浠庝笂鍒頒笅渚濇闄嶄綆~~~~~~~~~~~~~~~~~~··</font></p> <p><font size="3"></font><font color="#ff8040"> </font></p> <p><font size="3"></font><font color="#ff8040"> </font></p> <p><font size="3"></font><font color="#ff8040"> </font></p> <p><font size="3"></font><font color="#ff8040"> </font></p> <p><font size="3"></font><font color="#ff8040"> </font></p> <p><font size="3"></font><font color="#ff8040"> </font></p> <p><font size="3"></font><font color="#800000"> </font></p> <p><font color="#0000ff" size="3"></font></p><img src ="http://www.shnenglu.com/zqsand/aggbug/100835.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.shnenglu.com/zqsand/" target="_blank">rikisand</a> 2009-11-12 21:45 <a href="http://www.shnenglu.com/zqsand/archive/2009/11/12/100835.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>[USACO 09NOV] silver xoinc [dp]http://www.shnenglu.com/zqsand/archive/2009/11/12/100754.htmlrikisandrikisandWed, 11 Nov 2009 16:20:00 GMThttp://www.shnenglu.com/zqsand/archive/2009/11/12/100754.htmlhttp://www.shnenglu.com/zqsand/comments/100754.htmlhttp://www.shnenglu.com/zqsand/archive/2009/11/12/100754.html#Feedback0http://www.shnenglu.com/zqsand/comments/commentRss/100754.htmlhttp://www.shnenglu.com/zqsand/services/trackbacks/100754.html鍛ㄥ叚絎竴嬈″仛usaco鐜╋紝bronze鐨勮交鏉懼垏鎺夛紝鐒跺悗鐢寵promote錛屼笅鍗堟壒鍑嗭紝璇濊rob 鏁堢巼濂介珮鍟妦 浜庢槸緇х畫(huà)鍋歴ilver 灝遍亣鍒拌繖涓- -錛佺籂緇撲簡(jiǎn)鍗婂ぉ鏀懼純····鐭ラ亾鏄痙p 涔熻冭檻浜?jiǎn)鏂规硶灏辨?鐞嗕笉娓呮錛涗笉鐭ラ亾鏄笉鏄竴澶╂病鍚冮キ鐨勭紭鏁?#183;····

浠婂ぉ棰樿В鍑烘潵浜?jiǎn)~ 鍏堢湅浜?jiǎn)澶ф鎬濊礬 鐒跺悗鑷繁鍐欏嚭鏉ヤ簡(jiǎn)~

棰樼洰錛?/font>

Farmer John's cows like to play coin games so FJ has invented with
a new two-player coin game called Xoinc for them.

Initially a stack of N (5 <= N <= 2,000) coins sits on the ground;
coin i from the top has integer value C_i (1 <= C_i <= 100,000).

The first player starts the game by taking the top one or two coins
(C_1 and maybe C_2) from the stack. If the first player takes just
the top coin, the second player may take the following one or two
coins in the next turn. If the first player takes two coins then
the second player may take the top one, two, three or four coins
from the stack. In each turn, the current player must take at least
one coin and at most two times the amount of coins last taken by
the opposing player. The game is over when there are no more coins
to take.

Afterwards, they can use the value of the coins they have taken
from the stack to buy treats from FJ, so naturally, their purpose
in the game is to maximize the total value of the coins they take.
Assuming the second player plays optimally to maximize his own
winnings, what is the highest total value that the first player can
have when the game is over?

MEMORY LIMIT: 20 MB

PROBLEM NAME: xoinc

INPUT FORMAT:

* Line 1: A single integer: N

* Lines 2..N+1: Line i+1 contains a single integer: C_i

SAMPLE INPUT (file xoinc.in):

5
1
3
1
7
2
綆鍗曟潵璇村氨鏄袱涓漢杞祦鍙朿oins錛屾瘡涓漢姣忔鍙栧緱涓暟涓?- 2*n;n涓轟笂涓杞鏂瑰彇寰楁暟鐩紝
姹備袱涓漢閮芥槸鐢ㄦ渶浣崇瓥鐣ワ紝鍏堝彇寰楅偅涓浼欐渶澶氳兘鎷垮埌澶氬皯紜竵銆傝矊浼煎彲浠ョ畻鏄畝鍗曞崥寮堣鐨勬濇兂
鎬濊礬錛?/font>
        coins[1···N] 浠庝笅鍒頒笂 sum[1···N] 鍓╀笅 i涓殑鍜?/font>
        鎵懼埌鏃犲悗鏁堟х殑瀛愰棶棰樸傝冭檻鍦ㄨ繕鍓╀笅p涓挶甯佹椂鍊欑殑鎯呭喌錛屾鏃跺彲浠ユ嬁k涓挶
鐢變簬鏉′歡錛宬鐨勫ぇ灝忓彈涓婁竴杞嬁鐨勪釜鏁癷鐨勯檺鍒?錛屾墍浠ユ垜浠鍔犱笂涓涓彉閲廼銆傚緱鍒?/font>
dp[p][i]榪欎釜瀛愰棶棰樸傞偅涔堝鏄撳緱鍒?/font>
dp[p][i]=max(1=<k<=i*2){SuM(p to p-k+1)+SuM(p-k to 1)-dp[p-k][k]}
            =max(1=<k<=i*2){sum[p]-dp[p-k][k]}
鎸夌収榪欎釜鍙互寰楀埌涓涓狾錛圢^3錛夌殑綆楁硶

oidsolve(){
  
for(inti=1;i<=N;i++)//鍓╀笅i涓?br>        for(intj=1;j<=N;j++)//涓婁竴浜烘嬁浜?jiǎn)j 涓?br>            for(intk=1;k<=j*2&&i-k>=0;k++){
                dp[i][j]=max(dp[i][j],sum[
1]-sum[i+1]-dp[i-k][k]);
            }
    ret=dp[N][
1];
}

 涓夐噸閫掑綊 錛屾渶澶氬彲浠ヨ繃500鐨勬暟鎹噺  瑙傚療鍙互寰楀嚭 dp[p][j] 鍜?dp[p][j+1] 鐨勮綆楁湁寰堝鐨勯噸鍙?br>鍥犱負(fù) 涓婃鎷夸簡(jiǎn)j+1 鍒欏彲浠ユ瘮 dp[p][j] 澶氭嬁 2 涓?nbsp;

鐒跺悗錛岀敱浜庤冭檻j鐨勮寖鍥?搴旇涓?N-i+1

榪欐牱寰楀埌浜?jiǎn)鏈緇堜唬鐮侊細(xì)

    scanf("%d",&N); 
    for(int i=1;i<=N;i++)    scanf("%d",coins+i);//{fin>>coins[i]; }
    sum[0]=0;
    for(int i=1;i<=N;i++)     sum[i]=sum[i-1]+coins[N-i+1];  
    for(int i=1;i<=N;i++)        //鍓?涓?i 涓?
    for(int j=1;j<= N-i +1;j++){ // 涓?嬈?鎷?浜?j 涓?
    if(dp[i][j]<dp[i][j-1])dp[i][j]=dp[i][j-1];
    if(2*j-1<=i&&dp[i][j]<sum[i]-dp[i-2*j+1][2*j-1]) dp[i][j]=sum[i]-dp[i-2*j+1][2*j-1];
    if(2*j<=i&&dp[i][j]<sum[i]-dp[i-2*j][2*j]) dp[i][j]= sum[i]-dp[i-2*j][2*j];
    } 
    printf("%d\n",dp[N][1]);

寰堟櫄浜?錛屽厛鍐欒繖涔堝 錛屾湁絀烘妸bronze鐨勫啓浜?/strong>



rikisand 2009-11-12 00:20 鍙戣〃璇勮
]]>
ALGORITHM IN C (1)http://www.shnenglu.com/zqsand/archive/2009/11/11/100725.htmlrikisandrikisandWed, 11 Nov 2009 12:18:00 GMThttp://www.shnenglu.com/zqsand/archive/2009/11/11/100725.htmlhttp://www.shnenglu.com/zqsand/comments/100725.htmlhttp://www.shnenglu.com/zqsand/archive/2009/11/11/100725.html#Feedback0http://www.shnenglu.com/zqsand/comments/commentRss/100725.htmlhttp://www.shnenglu.com/zqsand/services/trackbacks/100725.htmlSteps to developing a usable algorithm.
• Define the problem.
• Find an algorithm to solve it.
• Fast enough?
• If not, figure out why.
• Find a way to address the problem.
• Iterate until satisfied.

 

涓昏鍐呭 FIND-UNION ALGORITHM

灝辨槸鍒╃敤騫舵煡闆嗘潵鑰冨療榪為氭х殑綆楁硶 銆傛潯浠禢涓妭鐐癸紝M瀵硅妭鐐癸紝杈撳叆姣忎竴瀵硅妭鐐規(guī)椂鍊欙紝濡傛灉宸茬粡榪為氾紝鍒欏拷鐣ワ紝鍚﹀垯杈撳嚭鎺ョ偣騫舵洿鏂?

涓昏浠嬬粛涓夌綆楁硶錛氱涓縐嶏紝QUCK-FIND 鍒╃敤鏁扮粍璁板綍姣忎竴涓仈閫氬瓙鍥撅紝鍚屼竴涓仈閫氬瓙鍥劇殑鑺傜偣鏁扮粍鍙橀噺鏄浉鍚岀殑銆傚洜姝ゆ瘡璇誨叆涓瀵瑰氨闇瑕侀亶鍘哊涓暟緇勫彉閲忚冨療鏄惁闇瑕佹洿鏂幫紝鏈鍧忔椂闂碝N錛屽疄闄呬笂姣忎釜瀛愬浘涓洪珮搴︿負(fù)2鐨勬爲(wèi);絎簩縐嶏紝QUICK-UNION 鑱旈氬瓙鍥鵑渶瑕乽nion鏃?浠呬粎闇瑕佸皢涓や釜root union 鍥犳姣忎釜鑱旈氬瓙鍥鵑珮搴﹀彉楂橈紝鎵鏈塮ind root 浼?xì)娑堣椾竴瀹氭椂闂達(dá)紝褰撶劧鏃犻渶閬嶅巻N浜?錛屾渶鍧忔椂闂達(dá)紝涔熷氨鏄瘡嬈″潎闇瑕佷粠鍙跺瓙鑺傜偣鍘誨洖婧眰鏍癸紙榪欓噷涔︿腑涓懼緱渚嬪瓙濂藉儚鏈夐棶棰橈級(jí)涔熸槸MN錛涚涓夌涔熷氨鏄?QUICK WEIGHT UNION 榪欑鏂規(guī)硶鍦ㄤ袱涓瓙鏍?wèi)鍚堯q剁殑鏃跺欙紝涓嶆槸綆鍗曠殑鎸囧畾鍚堝茍絳栫暐錛岃屾槸緇忚繃鍒ゆ柇鐨勶紝鎶妔ize灝忥紙鐩稿簲楂樺害涔熷皬錛夌殑鍚堝茍鍒皊ize澶х殑閲岄潰錛涘疄闄呬笂寰堝鏄撶悊瑙e氨鏄敖閲忓噺灝戞爲(wèi)鐨勯珮搴︽潵榪芥眰quick-find鐨勬晥鐜囷紱

榪涜屼綔鑰呭啓閬撹礬寰勫帇緙╋紝涔熸槸榪欑鎬濇兂銆傛垨鑰呭疄鐜頒負(fù)鍏ㄩ儴鍘嬬緝錛屼篃灝辨槸璇村湪榪涜union鎿嶄綔鐨勬椂鍊欙紝鎵鏈塩heck鐨勮妭鐐歸兘鐩存帴閾炬帴鍒皍nion鍚庣殑鏂皉oot涓嬮潰錛屾垨鑰卙alf union 錛堝鏄撳疄鐜頒笖鎬ц兘濂斤級(jí)姣忔check鏃跺欙紝濡傛灉娌℃湁鍋滄loop綆鍗曠殑浠?id[i]=id[id[i]];鍗沖彲杈懼埌鍑忓皯鍒版牴璺濈鐨勬晥鏋溿?

half union 鐨勪富瑕佷唬鐮侊細(xì)

int i,j;
for(i=p;id[i]!=i;i=id[i]) id[i]=id[id[i]];
for(j=p;id[j]!=j;j=id[j]) id[j]=id[id[j]];
if(i==j)continue;
if(size[i]>size[j]) id[j]=i,size[i]+=size[j];
else        id[i]=j,size[j]+=size[i];

 

絎竴嬈$敤windows live writer 璇曡瘯鏁堟灉鍝~

 

 

 

 

 

 

 

 



rikisand 2009-11-11 20:18 鍙戣〃璇勮
]]>
欧美激情精品久久久久久久| 国产精品久久久久9999| 国产精品一区二区久久精品无码 | 久久精品国产99久久丝袜| 久久国产V一级毛多内射| 亚洲国产精品综合久久一线 | 久久久久人妻一区二区三区vr| 老色鬼久久亚洲AV综合| 亚洲国产成人久久精品动漫| 日批日出水久久亚洲精品tv| 日本人妻丰满熟妇久久久久久| 国产精品18久久久久久vr| 亚洲精品97久久中文字幕无码| 亚洲αv久久久噜噜噜噜噜| 青青草原综合久久| 久久久久se色偷偷亚洲精品av| 精品久久久久久无码中文野结衣 | 超级97碰碰碰碰久久久久最新| 久久人人爽人人爽人人AV东京热| 久久久精品久久久久久 | yellow中文字幕久久网| 久久久久99精品成人片欧美| 久久性生大片免费观看性| 香蕉久久夜色精品国产小说| 久久综合九色综合网站| 亚洲伊人久久综合影院| 久久99精品久久久久久秒播| 久久99热精品| 97久久精品国产精品青草| 欧美熟妇另类久久久久久不卡| 亚洲伊人久久综合中文成人网| 久久久久亚洲精品天堂久久久久久 | 国产伊人久久| 日韩亚洲欧美久久久www综合网 | 亚洲精品无码久久久久AV麻豆| 国产成人综合久久精品尤物| 久久免费美女视频| 91精品国产91久久久久久| 999久久久免费国产精品播放| 国产精品成人久久久久久久| 精品一区二区久久|