锘??xml version="1.0" encoding="utf-8" standalone="yes"?>久久精品国产一区二区三区日韩,欧美亚洲国产精品久久蜜芽,囯产精品久久久久久久久蜜桃http://www.shnenglu.com/zqsand/category/12847.html鍟ユ槸瀛愭爣棰?/description>zh-cnWed, 20 Jan 2010 11:25:10 GMTWed, 20 Jan 2010 11:25:10 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灞傛墍浠ヤ笉浼歵le

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

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

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

tchs-4 500pt 妯℃嫙棰橈紝濂介毦鎳?闊充箰鐨剘 鍙互閮戒箻浠?6 鐢ㄦ暣鏁版潵璁$畻 嫻偣浼氬緢鐑 榪欑棰樻濊礬瑕佹竻鏅?涓姝ヤ竴姝ユ潵



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 鍙戣〃璇勮
]]>
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緇х畫鏄痬isof 鏁板瓧鏁欏閲岄潰鐨勪範棰榽 絎竴綃囩殑鏈鍚庝竴閬撻浜唦
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.

鍏抽敭鏄棬鐨勭姸鎬佽〃紺猴紝鍙傝冧簡緗戠珯涓婄殑浠g爜錛屾寫浜嗕竴涓瘮杈冪畝緇冪殑錛岀敤鐨勪紭鍏堢駭闃熷垪銆傚啓瀹岃皟濂藉彂鐜癟LE 鍥 copy鍑虹綉绔欎笂鐨勫啀run渚濈劧TLE``` ``` 鐪嬩簡涓嬪彂鐜扮幇鍦ㄧ殑system testing 姣斿師鏉ュ鍔犱簡鍑犱釜嫻嬭瘯鐢ㄤ緥~~~   浜庢槸鎵懼嚭misof澶х墰鐨勮В娉曪紝鍙戠幇瀵圭姸鎬佸鐞嗕竴鏍風殑~~~鍙笉榪囩敤浜唌emo鍜宒eque錛岀渷鍘諱簡浼樺厛綰ч槦鍒楄皟鏁寸殑鏃墮棿寮閿錛屾敼濂戒簡灝眕ass浜唦 涓婁唬鐮亊~錛?/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)

 

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

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

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

娉ㄩ噴涓濊礬涓? 渚濇浠庡瓙闆嗛夊彇涓涓夋墜浣滀負褰撳墠瀛愰泦涓殑絎竴涓厓绱狅紝涔熷氨鏄暣浣撶殑絎琻-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'.

鎸夌収棰樼洰璇存槑鍙煡錛屾寜鐓ф壘鍒扮殑欏哄簭錛屾墍鏈変粠浣庣駭鍚戦珮綰у彂鐨勪俊寰楁暟鐩拰搴旇鏄渶灝忕殑銆傚張瑙傚療鍒幫紝鍙紜畾浜嗙涓涓紝涔熷氨鏄駭鍒渶楂樼殑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湇錛岀湅浜嗕細dota vod 錛岄噸鏂扮櫥鍏ワ紝姣旇禌绔熺劧緇х畫·····浜や簡500 寮濮嬬湅1000 娌℃濊礬錛屽喕姝諱簡銆?/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氨鍙互浜嗐傛垨鑰呭驚鐜?^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;
}

 

 

 

鍥犱負姣忛槦鍙墿涓嬩竴鍦烘瘮璧涳紝鎵浠ラ鐩彉寰楀緢綆鍗曘?闃熸渶鍚庝竴杞偗瀹氭槸鍙栧埌3鍒嗭紝姣?闃熷3鍦轟互涓婃瘮璧涚殑 鑲畾姣?闃熼潬鍓嶏紝姣?闃熷垎灝戞垨鑰呯浉絳夌殑涓瀹氬湪0闃熶箣鍚庯紝鍓╀笅鐨勫氨鏄垜浠鑰冭檻鐨勪簡銆傚鏋淎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>鏄ㄥぉ鐪嬩簡sedgewick鐨刟lg in c 鐨勭涓绔狅紝涓昏浠嬬粛浜嗕釜find-union 鍒ゆ柇鑱旈氱殑綆楁硶錛屽叾瀹炵敤鍒頒簡騫舵煡闆嗙殑鐭ヨ瘑</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">榪樹互涓烘槸鏈綆鍗曠殑涓閬撳憿錛岃鍒楀湪鏈鍓嶉潰錛屽師鏉ユ槸鎵╁睍鐨勫簲鐢紝涓嶆槸閭d箞鐩存帴鍟妦</font></p> <p><font face="寰蔣闆呴粦" color="#83c13e" size="4">綰犵粨浜嗕竴浼氬効錛岀湅浜嗚В棰樻姤鍛婃墠鏈夋濊礬銆傚叧閿槸鍦ㄥ茍鏌ラ泦鐨勫熀紜涓婂鍔犱竴涓暟緇勶紝緇存姢鍏朵笌鏍硅妭鐐圭殑鍏崇郴錛?/font></p> <p><font face="寰蔣闆呴粦" color="#83c13e" size="4">璇︽儏鍐欏埌娉ㄩ噴閲岄潰鍚э細</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璁板綍鑺傜偣鎵灞炰簬鐨勬爲鏈╥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鏃墮棿錛屽噺灝忔爲鐨勯珮搴? 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">;//鐢辮嚜宸變笌鏍圭殑鍏崇郴浠ュ強鐖惰妭鐐逛笌鏍圭殑鍏崇郴鎺ㄦ柇鍑烘柊鐨勮嚜宸變笌鏍圭殑鍏崇郴錛屽疄闄呬笂鏄負浜嗚В鍐硊nion鍚庣殑鑺傜偣涓庢牴鐨勫叧緋?/span></font></font></pre><pre class="code"><font size="2"><font face="Comic Sans MS"><span style="background: #2b2b2b; color: white"> //鍥犱負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鎴愪負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鐨勫瓙鏍戯紝浠巃鍑哄彂錛屽埌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>涓嶈創浠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 鏁板瓧琛ㄨ揪鏁欑▼閲岀殑涔犻~ 棰樼洰澶ф剰 姹備嬌鐢ㄦ瀛愮殑鏈熸湜銆傜敱浜庡埌鏉roup鐨勪釜鏁頒笉瀹氾紝姣忎釜group闇瑕佺殑妗屽瓙涓嶅畾錛屼嬌紜畾鏈熸湜鍙樺緱鍥伴毦銆備絾鑰冭檻瀵逛簬numTables鏉ヨ,浣跨敤妗屽瓙鐨勭姸鎬佷粎浠呮湁 2^numTables縐嶏紝鍥犳鑰冭檻鍦ㄨ繖浜涚姸鎬佹敼鍙樼殑榪囩▼涓潵璁$畻鏈熸湜錛屼篃灝辨槸璁$畻鍦ㄦ瘡涓姸鎬佷笅闈㈢殑鏈熸湜妗屽瓙鏁扮洰銆傚湪姣忎釜鐘舵佸埌杈炬椂錛屼緷嬈¤冭檻鏉ヤ簡涓涓猤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">鐪嬫瘮璧涗腑鏈夊彟涓縐嶈В娉曪紝鍗蟲牴鎹鐩紝鍦ㄥ埌杈炬瘡嬈ail to serve a group 鐨勬椂鍊?鏍規嵁姝ゆ椂鐨勬瀛愭暟閲忥紝鍜屽埌杈捐繖縐嶇姸鎬佺殑姒傜巼 鏉ヨ綆楋細</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">浼樺厛綰у緢瀹規槗閿欙細</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></channel></rss> <footer> <div class="friendship-link"> <p>感谢您访问我们的网站,您可能还对以下资源感兴趣:</p> <a href="http://www.shnenglu.com/" title="精品视频久久久久">精品视频久久久久</a> <div class="friend-links"> </div> </div> </footer> <a href="http://www.xnrb.net.cn" target="_blank">久久精品国产免费观看</a>| <a href="http://www.0769zc.net.cn" target="_blank">亚洲午夜久久久久久久久电影网</a>| <a href="http://www.qdjzx.cn" target="_blank">久久久久av无码免费网</a>| <a href="http://www.888happy.cn" target="_blank">久久精品无码免费不卡</a>| <a href="http://www.bddp.com.cn" target="_blank">国产成人久久精品麻豆一区</a>| <a href="http://www.jiqirenedu.cn" target="_blank">久久水蜜桃亚洲av无码精品麻豆</a>| <a href="http://www.dm233.cn" target="_blank">久久久久久久久久久久久久</a>| <a href="http://www.dgchengxin.cn" target="_blank">精品国产一区二区三区久久蜜臀</a>| <a href="http://www.cext.cn" target="_blank">色噜噜狠狠先锋影音久久</a>| <a href="http://www.cnmere.cn" target="_blank">精品国产VA久久久久久久冰</a>| <a href="http://www.thelv.cn" target="_blank">日韩精品久久久肉伦网站</a>| <a href="http://www.tb901.cn" target="_blank">伊人久久大香线蕉AV一区二区</a>| <a href="http://www.ghoststory.cn" target="_blank">狠狠色丁香婷婷综合久久来来去</a>| <a href="http://www.giep.cn" target="_blank">国产福利电影一区二区三区久久久久成人精品综合 </a>| <a href="http://www.mmmbbb.cn" target="_blank">日本精品久久久久久久久免费</a>| <a href="http://www.rz2.com.cn" target="_blank">精品久久一区二区</a>| <a href="http://www.d8950.cn" target="_blank">久久91精品综合国产首页</a>| <a href="http://www.riseguide.com.cn" target="_blank">久久久久久噜噜精品免费直播</a>| <a href="http://www.gkdb.net.cn" target="_blank">久久久久久国产精品无码下载</a>| <a href="http://www.klzp.net.cn" target="_blank">久久久久久久久久免免费精品</a>| <a href="http://www.520jj.cn" target="_blank">2021国产精品久久精品</a>| <a href="http://www.leyuzhe.cn" target="_blank">久久人人添人人爽添人人片牛牛</a>| <a href="http://www.gfba.cn" target="_blank">久久国产欧美日韩精品免费</a>| <a href="http://www.aktg.com.cn" target="_blank">色综合久久88色综合天天 </a>| <a href="http://www.zingl.cn" target="_blank">久久久久亚洲av成人无码电影 </a>| <a href="http://www.goodleg.cn" target="_blank">国产99久久久久久免费看</a>| <a href="http://www.0475job.cn" target="_blank">精品久久久久久国产三级</a>| <a href="http://www.daemontools.org.cn" target="_blank">国产成人精品久久一区二区三区</a>| <a href="http://www.a88wx.cn" target="_blank">亚洲国产精品无码久久一区二区</a>| <a href="http://www.521mz.cn" target="_blank">久久久久久国产精品无码下载</a>| <a href="http://www.fa808.cn" target="_blank">亚洲人成无码www久久久</a>| <a href="http://www.mosphere.cn" target="_blank">色综合久久天天综线观看</a>| <a href="http://www.indmc.cn" target="_blank">亚洲国产精品成人AV无码久久综合影院 </a>| <a href="http://www.green-products.cn" target="_blank">久久国产精品视频</a>| <a href="http://www.sanxiangcn.cn" target="_blank">久久99精品国产99久久</a>| <a href="http://www.a-house.com.cn" target="_blank">精品国产一区二区三区久久久狼</a>| <a href="http://www.h6cpi0.cn" target="_blank">久久99国产综合精品女同</a>| <a href="http://www.sxmkw.cn" target="_blank">99热成人精品热久久669</a>| <a href="http://www.gnjb.net.cn" target="_blank">久久精品九九亚洲精品天堂</a>| <a href="http://www.mir802.cn" target="_blank">国产成人综合久久精品尤物</a>| <a href="http://www.fttyz.com.cn" target="_blank">久久综合色区</a>| <script> (function(){ var bp = document.createElement('script'); var curProtocol = window.location.protocol.split(':')[0]; if (curProtocol === 'https') { bp.src = 'https://zz.bdstatic.com/linksubmit/push.js'; } else { bp.src = 'http://push.zhanzhang.baidu.com/push.js'; } var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(bp, s); })(); </script> </body>