锘??xml version="1.0" encoding="utf-8" standalone="yes"?>久久久亚洲国产美女国产盗摄,欧美a级片一区,在线午夜精品自拍http://www.shnenglu.com/ACM-Boy/category/5700.htmlzh-cnSat, 16 Aug 2008 13:31:49 GMTSat, 16 Aug 2008 13:31:49 GMT60PKU 1733 Parity gamehttp://www.shnenglu.com/ACM-Boy/archive/2008/08/15/58919.htmlACM-BoyACM-BoyFri, 15 Aug 2008 03:23:00 GMThttp://www.shnenglu.com/ACM-Boy/archive/2008/08/15/58919.htmlhttp://www.shnenglu.com/ACM-Boy/comments/58919.htmlhttp://www.shnenglu.com/ACM-Boy/archive/2008/08/15/58919.html#Feedback0http://www.shnenglu.com/ACM-Boy/comments/commentRss/58919.htmlhttp://www.shnenglu.com/ACM-Boy/services/trackbacks/58919.html
鎬濊礬錛?br>    鍛婅瘔浣燵a,b]涔嬮棿1涓暟鐨勫鍋舵儏鍐碉紝閭d箞浣犲氨鍙互鍦╝-1鍜宐涔嬮棿榪炰竴鏉¤竟錛屾潈鍊煎氨鏄叾濂囧伓鎯呭喌銆傝繖鏍蜂竴鏉ワ紝姣斿[1,2]鍜孾3,4]鐨勬儏鍐靛凡鐭ワ紝[1,4]鐨勬儏鍐典篃灝辯煡閬撲簡(jiǎn)銆傚綋棰樼洰緇欏嚭[a,b]鐨勬儏鍐墊椂錛岄鍏堝垎鍒粠a鍜宐寰涓婃壘錛屾壘鍒頒粬浠殑鏍箁1鍜宺2錛屽鏋渞1 !=  r2錛岃〃紺篴,b涔嬮棿鐨勫鍋舵儏鍐佃繕?shù)笉纭畾锛尀灏唕1鍜宺2涔嬮棿榪炶搗鏉ワ紝鏍規(guī)嵁a(chǎn)鍒皉1鐨勬潈鍊箋乥鍒皉2鐨勬潈鍊煎拰棰樼洰鎵緇欑殑濂囧伓鎯呭喌錛岃緗畆1鍜宺2涔嬮棿鐨勬潈鍊鹼紝浠ョ鍚堥鐩姹傘傝嫢r1 == r2錛屽垯琛ㄧず[a,b]涔嬮棿鎯呭喌宸茬‘瀹氾紝鏍規(guī)嵁a(chǎn)鍒皉1鐨勬潈鍊煎拰b鍒皉2鐨勬潈鍊鹼紝灝卞彲浠ュ垽鏂鐩墍緇欑殑[a,b]鐨勬儏鍐墊槸鍚︿負(fù)鐪熴?br>    鍏跺疄褰撴椂鍋氱殑鏃跺欙紝榪樹(shù)笉鏄緢鎳傦紝浣嗘病鎯沖埌紼閲岀硦娑傜殑灝盇C浜?jiǎn)銆傛帹鑽愪竴涓嬭繖涓綉欏碉細(xì)http://hi.baidu.com/fandywang_jlu/blog/item/b49e40893ddbb0b00f244485.html錛岃繖閲岄潰浠嬬粛騫舵煡闆嗘尯璇︾粏鐨勶紝榪樻湁涓嶅皯鎺ㄨ崘棰樼洰錛屾湁浜涜繕?shù)笉浼?xì)鍋氥傦細(xì)P

浠g爜錛?br>
#include <iostream>
#include <map>
using namespace std;

const int MAX = 10005;

int n, p;
int pre[MAX];
int parity[MAX];        //i鍒扮洰鍓嶉泦鍚堢殑鏍圭殑濂囧伓鎯呭喌
map<int, int> numIndex;        //鐢ㄤ簬紱繪暎鍖?br>
int Find (int x)
{
    if ( pre[x] == -1 )
        return x;
    int f;
    f = Find(pre[x]);
    parity[x] = (parity[x] + parity[pre[x]]) % 2;    //姝ゆ椂pre[x]宸叉寚鍚戞渶緇堢殑闆嗗悎鐨勬牴
    pre[x] = f;
    return f;
}

bool Query (int x, int y, int odd)
{
    int r1, r2;
    r1 = Find(x);
    r2 = Find(y);
    if ( r1 == r2 )
    {
        if ( (parity[x] + parity[y]) % 2 == odd )
            return true;
        else
            return false;
    }
    else            //鍙槸灝唕1鎺ュ埌r2涓嬮潰錛岃繖杈硅繕鍙互浼樺寲
    {
        pre[r1] = r2;
        parity[r1] = (parity[x] + parity[y] + odd) % 2;
        return true;
    }
}

void Solve ()
{
    int i, x, y, index, idx1, idx2, odd;
    char s[10];
    scanf("%d%d", &n, &p);
    index = 0;
    for (i=0; i<p; i++)
    {
        scanf("%d%d%s", &x, &y, &s);
        x --;
        if ( numIndex.find(x) == numIndex.end() )
            numIndex[x] = index ++;
        idx1 = numIndex[x];
        if ( numIndex.find(y) == numIndex.end() )
            numIndex[y] = index ++;
        idx2 = numIndex[y];
        if ( strcmp(s, "odd") == 0 )
            odd = 1;
        else
            odd = 0;
        if ( Query(idx1, idx2, odd) == false )
        {
            break;
        }
    }
   
    printf("%d\n", i);
}

void Init ()
{
    memset(pre, -1, sizeof(pre));
}

int main ()
{
    Init();
    Solve();

    return 0;
}


ACM-Boy 2008-08-15 11:23 鍙戣〃璇勮
]]>
PKU 1639 Picnic Planninghttp://www.shnenglu.com/ACM-Boy/archive/2008/07/30/57547.htmlACM-BoyACM-BoyWed, 30 Jul 2008 11:10:00 GMThttp://www.shnenglu.com/ACM-Boy/archive/2008/07/30/57547.htmlhttp://www.shnenglu.com/ACM-Boy/comments/57547.htmlhttp://www.shnenglu.com/ACM-Boy/archive/2008/07/30/57547.html#Feedback0http://www.shnenglu.com/ACM-Boy/comments/commentRss/57547.htmlhttp://www.shnenglu.com/ACM-Boy/services/trackbacks/57547.html闃呰鍏ㄦ枃

ACM-Boy 2008-07-30 19:10 鍙戣〃璇勮
]]>
PKU 1037 A decorative fencehttp://www.shnenglu.com/ACM-Boy/archive/2008/05/20/50507.htmlACM-BoyACM-BoyTue, 20 May 2008 04:45:00 GMThttp://www.shnenglu.com/ACM-Boy/archive/2008/05/20/50507.htmlhttp://www.shnenglu.com/ACM-Boy/comments/50507.htmlhttp://www.shnenglu.com/ACM-Boy/archive/2008/05/20/50507.html#Feedback2http://www.shnenglu.com/ACM-Boy/comments/commentRss/50507.htmlhttp://www.shnenglu.com/ACM-Boy/services/trackbacks/50507.html闃呰鍏ㄦ枃

ACM-Boy 2008-05-20 12:45 鍙戣〃璇勮
]]>
PKU 2201 Cartesian Treehttp://www.shnenglu.com/ACM-Boy/archive/2008/04/25/48158.htmlACM-BoyACM-BoyFri, 25 Apr 2008 13:27:00 GMThttp://www.shnenglu.com/ACM-Boy/archive/2008/04/25/48158.htmlhttp://www.shnenglu.com/ACM-Boy/comments/48158.htmlhttp://www.shnenglu.com/ACM-Boy/archive/2008/04/25/48158.html#Feedback0http://www.shnenglu.com/ACM-Boy/comments/commentRss/48158.htmlhttp://www.shnenglu.com/ACM-Boy/services/trackbacks/48158.html闃呰鍏ㄦ枃

ACM-Boy 2008-04-25 21:27 鍙戣〃璇勮
]]>
PKU 1018 Communication Systemhttp://www.shnenglu.com/ACM-Boy/archive/2008/04/25/48157.htmlACM-BoyACM-BoyFri, 25 Apr 2008 13:25:00 GMThttp://www.shnenglu.com/ACM-Boy/archive/2008/04/25/48157.htmlhttp://www.shnenglu.com/ACM-Boy/comments/48157.htmlhttp://www.shnenglu.com/ACM-Boy/archive/2008/04/25/48157.html#Feedback0http://www.shnenglu.com/ACM-Boy/comments/commentRss/48157.htmlhttp://www.shnenglu.com/ACM-Boy/services/trackbacks/48157.html 棰樼洰鏉ユ簮錛?/span>

PKU 1018 Communication System

 

綆楁硶鍒嗙被錛?/span>

鏋氫婦+璐績(jī)

 

鍘熸枃錛?/span>

Communication System

Time Limit:1000MS  Memory Limit:10000K

Description

We have received an order from Pizoor Communications Inc. for a special communication system. The system consists of several devices. For each device, we are free to choose from several manufacturers. Same devices from two manufacturers differ in their maximum bandwidths and prices.
By overall bandwidth (B) we mean the minimum of the bandwidths of the chosen devices in the communication system and the total price (P) is the sum of the prices of all chosen devices. Our goal is to choose a manufacturer for each device to maximize B/P.

Input

The first line of the input file contains a single integer t (1 ≤ t ≤ 10), the number of test cases, followed by the input data for each test case. Each test case starts with a line containing a single integer n (1 ≤ n ≤ 100), the number of devices in the communication system, followed by n lines in the following format: the i-th line (1 ≤ i ≤ n) starts with mi (1 ≤ mi ≤ 100), the number of manufacturers for the i-th device, followed by mi pairs of positive integers in the same line, each indicating the bandwidth and the price of the device respectively, corresponding to a manufacturer.

Output

Your program should produce a single line for each test case containing a single number which is the maximum possible B/P for the test case. Round the numbers in the output to 3 digits after decimal point.

Sample Input

1 3

3 100 25 150 35 80 25

2 120 80 155 40

2 100 100 120 110

 

Sample Output

0.649

 

Source

Tehran 2002, First Iran Nationwide Internet Programming Contest

 

 

涓枃鎻忚堪錛?/span>

浣犻渶瑕佽喘涔?/span>n縐嶈澶囨潵緇勪竴涓氫俊緋葷粺錛屾瘡涓縐嶈澶囷紝鍙堟槸鐢變竴浜涗笉鍚岀殑鍒墮犲晢鐢熶駭鐨勶紝涓嶅悓鍒墮犲晢鐢熶駭鐨勫悓縐嶈澶囦細(xì)鏈変笉鍚岀殑甯﹀鍜屼環(huán)鏍箋傜幇鍦ㄤ綘瑕佸湪姣忎竴涓澶囩殑鍒墮犲晢涓変竴涓紝浣垮緱璐拱鐨?/span>n縐嶈澶囷紝瀹冧滑甯﹀鐨勬渶灝忓間笌浠鋒牸涔嬪拰鐨勬瘮鏈澶с?/span>

 

棰樼洰鍒嗘瀽錛?/span>

涓寮濮嬫兂鍒扮殑灝辨槸鏆存悳錛屼絾鏄悳绱㈢殑娣卞害杈懼埌100錛屾椂闂磋偗瀹氭槸涓嶅厑璁哥殑銆傛兂瑕佽В鍐寵繖棰橈紝蹇呴』鎵懼埌涓涓ソ鐨勬煡鎵劇瓥鐣ャ傚啀鎯蟲(chóng)兂鐪嬭繖棰樼殑鐗圭偣錛屾渶鍚庣殑絳旀錛屽甫瀹芥槸閫夊彇鎵鏈夎澶囦腑鐨勬渶灝忓鹼紝鑰屼環(huán)鏍兼槸閫夊彇鎵鏈夎澶囩殑浠鋒牸鎬誨拰銆傚鏋滄煇涓埗閫犲晢鐢熶駭鐨勬煇縐嶈澶囷紝瀹冪殑甯﹀杈冮珮鑰屼環(huán)鏍艱緝浣庯紝閭d箞閫夊彇瀹冪殑鍙兘鎬у氨姣旇緝澶с傚啀榪涗竴姝ヨ錛屽鏋滄墍閫夊彇鐨?/span>n縐嶈澶囩殑甯﹀鐨勬渶灝忓?/span>b宸茬粡紜畾錛岄偅涔堝浜庢煇縐嶈澶囷紝鎴戜滑灝卞彲浠ュ湪閭d簺鐢熶駭榪欑璁懼鐨勶紝甯﹀澶т簬絳変簬b鐨勫埗閫犲晢涓繘琛岄夋嫨銆傚綋鐒舵槸閫夐偅涓環(huán)鏍兼渶浣庣殑璁懼錛屽洜涓虹瓟妗堢殑鍒嗗瓙宸茬粡紜畾涓?/span>b錛屾墍浠ュ垎姣嶈秺灝忚秺濂姐傜湅鏉ュ彧瑕佹灇涓?/span>b錛屽啀瀵逛簬姣忎釜璁懼璐績(jī)鐨勯夋嫨鏈灝忎環(huán)鏍煎氨鍙互浜?jiǎn)锛屾棄櫁村鏉傚害湄?fù)O錛?/span>mnB錛夛紝B涓哄甫瀹芥灇涓劇殑鏁伴噺銆備絾闂鍙堟潵浜?jiǎn)锛屽簲璇ユ庝箞鏋氫婦甯﹀錛岄鐩腑騫舵湭緇欏嚭甯﹀鐨勫彇鍊艱寖鍥達(dá)紝濡傛灉浠?/span>0..maxB涓涓竴涓灇涓劇殑璇濓紝鏃㈣垂鏃跺張浼?xì)閫犳垚榪囧閲嶅鎯呭喌錛堝鏋滄灇涓鵑偅浜涘湪杈撳叆涓嚭鐜扮殑涓や釜榪炵畫(huà)甯﹀涔嬮棿鐨勫鹼紝鏈鍚庣殑絳旀鏄竴鏍風(fēng)殑錛夈傛墍浠ユ垜浠簲璇ラ噰鍙栨煇涓柟娉曡褰曡緭鍏ヤ腑鍑虹幇榪囩殑甯﹀錛?/span>STL涓殑set鏄釜涓嶉敊鐨勯夋嫨錛夛紝鍐嶆灇涓捐繖浜涘甫瀹姐傚湪鏋氫婦涓紝鍙兘鍑虹幇榪欑鎯呭喌錛氭灇涓?/span>b錛岄夋嫨浜?/span>n縐嶈澶囷紝浣嗛夋嫨鐨勬墍鏈夎澶囩殑甯﹀閮藉ぇ浜?/span>b錛岄偅涔堟渶緇堢敤b/price灝變笉鏄繖縐嶆儏鍐電殑姝g‘絳旀銆傚叾瀹炰笉鐢ㄦ媴蹇?jī)锛屽洜湄?fù)姝g‘絳旀涓瀹氬ぇ浜?/span>b/price銆傚亣璁句笂闈㈣繖縐嶆儏鍐電殑瀹為檯甯﹀鏈灝忓兼槸b’錛岄偅涓綋鎴戜滑鍐嶅幓鏋氫婦b’鏃訛紝鑷沖皯鏈変竴涓澶囩殑甯﹀絳変簬b’錛岃繖嬈″緱鍒扮殑絳旀涔熷氨鏄笂闈㈤偅縐嶆儏鍐電殑絳旀錛屾墍浠ユ渶緇堣繕鏄兘寰楀埌姝g‘瑙c?/span>

 

浠g爜錛?/span>

#include <iostream>

#include <map>

#include <set>

#include <climits>

using namespace std;

 

const int MAX = 105;

 

struct Info

{

                int band, price;

};

 

struct Device

{

                int manuNum;

                Info info[MAX];

                map<int, int> minPrice;                 //map[i] = j 琛ㄧず甯﹀>=i鐨勬渶灝忎環(huán)鏍兼槸j

                int minBand, maxBand;

};

 

Device device[MAX];

int deviceNum;

set<int> band;                                                                  //杈撳叆涓嚭鐜拌繃鐨?/span>band

set<int>::iterator start, end;

int maxBand, minBand;                                 //闇瑕佹灇涓劇殑band鐨勬渶鍊?/span>

 

int cmp( const void *a , const void *b )

{

                Info *c = (Info *)a;

                Info *d = (Info *)b;

                if(c->band != d->band)

                                return d->band - c->band;

                else

                                return c->price - d->price;

}

 

void Input ()

{

                int i, j, max, min;

                band.clear();

                cin>>deviceNum;

                for (i=0; i<deviceNum; i++)

                {

                                device[i].minBand = INT_MAX;

                                device[i].maxBand = -1;

                                cin>>device[i].manuNum;

                                for (j=0; j<device[i].manuNum; j++)

                                {

                                                cin>>device[i].info[j].band>>device[i].info[j].price;

                                                band.insert(device[i].info[j].band);

                                                if ( device[i].info[j].band > device[i].maxBand )

                                                                device[i].maxBand = device[i].info[j].band;

                                                if ( device[i].info[j].band < device[i].minBand )

                                                                device[i].minBand = device[i].info[j].band;

                                }

                                                               

                }

}

 

void Pre ()                                           //棰勫鐞?/span>

{

                int i, j, min, b;

                //璁$畻鎵闇鏋氫婦鐨勫甫瀹界殑鏈鍊?/span>

                maxBand = INT_MAX;                   //maxBand涓烘墍鏈夎澶囧甫瀹芥渶澶у肩殑鏈灝忓?/span>

                minBand = INT_MAX;                    //minBand涓烘墍鏈夎澶囧甫瀹芥渶灝忓肩殑鏈灝忓?/span>

                for (i=0; i<deviceNum; i++)

                {

                                if ( device[i].maxBand < maxBand )

                                                maxBand = device[i].maxBand;

                                if ( device[i].minBand < minBand )

                                                minBand = device[i].minBand;

                }

 

                //瀵逛簬姣忎釜璁懼錛屾壘鍒板甫瀹藉ぇ浜庣瓑浜庢煇涓鍊肩殑鏈灝忎環(huán)鏍?/span>

                for (i=0; i<deviceNum; i++)

                {

                                //band浠庡ぇ鍒板皬錛?/span>band鐩哥瓑鏃?/span>price浠庡皬鍒板ぇ

                                qsort(device[i].info, device[i].manuNum, sizeof(Info), cmp);

                                device[i].minPrice.clear();

                                min = device[i].info[0].price;

                                b = device[i].info[0].band;

                                device[i].minPrice[b] = min;

                                for (j=1; j<device[i].manuNum; j++)

                                {

                                                if ( device[i].info[j].band == b )

                                                                continue;

                                                if ( device[i].info[j].price < min )

                                                {

                                                                min = device[i].info[j].price;

                                                }

                                                b = device[i].info[j].band;

                                                device[i].minPrice[b] = min;

                                }

                }             

}

 

void Solve ()

{

                Pre();

 

                int b, i, totalPrice;

                double rate, ans;

                map<int, int>::iterator it;

                ans = 0;

                start = band.find(minBand);

                end = band.find(maxBand);

                end ++;

                while ( start != end )

                {

                                b = *start;

                                start ++;

                                totalPrice = 0;

                                for (i=0; i<deviceNum; i++)

                                {

                                                //鎵懼埌甯﹀澶т簬絳変簬b鐨勬渶灝忎環(huán)鏍?/span>

                                                for (it=device[i].minPrice.begin(); it!=device[i].minPrice.end(); it++)

                                                {

                                                                if ( it->first >= b )

                                                                {

                                                                                totalPrice += it->second;

                                                                                break;

                                                                }

                                                }

 

                                }

                                rate = double(b) / totalPrice;

                                if ( rate > ans )

                                                ans = rate;

                }

 

                printf("%.3f\n", ans);

}

 

int main ()

{

                int test;

                cin>>test;

                while ( test -- )

                {

                                Input ();

                                Solve ();

                }

 

                return 0;

}



ACM-Boy 2008-04-25 21:25 鍙戣〃璇勮
]]>
PKU 3513 Let's Go to the Movieshttp://www.shnenglu.com/ACM-Boy/archive/2008/03/25/45395.htmlACM-BoyACM-BoyTue, 25 Mar 2008 15:16:00 GMThttp://www.shnenglu.com/ACM-Boy/archive/2008/03/25/45395.htmlhttp://www.shnenglu.com/ACM-Boy/comments/45395.htmlhttp://www.shnenglu.com/ACM-Boy/archive/2008/03/25/45395.html#Feedback0http://www.shnenglu.com/ACM-Boy/comments/commentRss/45395.htmlhttp://www.shnenglu.com/ACM-Boy/services/trackbacks/45395.html闃呰鍏ㄦ枃

ACM-Boy 2008-03-25 23:16 鍙戣〃璇勮
]]>
pku 1505 Copying Bookshttp://www.shnenglu.com/ACM-Boy/archive/2008/03/10/44085.htmlACM-BoyACM-BoyMon, 10 Mar 2008 07:11:00 GMThttp://www.shnenglu.com/ACM-Boy/archive/2008/03/10/44085.htmlhttp://www.shnenglu.com/ACM-Boy/comments/44085.htmlhttp://www.shnenglu.com/ACM-Boy/archive/2008/03/10/44085.html#Feedback0http://www.shnenglu.com/ACM-Boy/comments/commentRss/44085.htmlhttp://www.shnenglu.com/ACM-Boy/services/trackbacks/44085.html瑙i鎶ュ憡

 

棰樼洰鏉ユ簮錛?/span>

PKU 1505 Copying Books

 

綆楁硶鍒嗙被錛?/span>

DP

 

鍘熸枃錛?/span>

Copying Books

Time Limit: 3000MS


Memory Limit: 10000K

Total Submissions: 1806


Accepted: 404

Description

Before the invention of book-printing, it was very hard to make a copy of a book. All the contents had to be re-written by hand by so called scribers. The scriber had been given a book and after several months he finished its copy. One of the most famous scribers lived in the 15th century and his name was Xaverius Endricus Remius Ontius Xendrianus (Xerox). Anyway, the work was very annoying and boring. And the only way to speed it up was to hire more scribers.

Once upon a time, there was a theater ensemble that wanted to play famous Antique Tragedies. The scripts of these plays were divided into many books and actors needed more copies of them, of course. So they hired many scribers to make copies of these books. Imagine you have m books (numbered 1, 2 ... m) that may have different number of pages (p1, p2 ... pm) and you want to make one copy of each of them. Your task is to divide these books among k scribes, k <= m. Each book can be assigned to a single scriber only, and every scriber must get a continuous sequence of books. That means, there exists an increasing succession of numbers 0 = b0 < b1 < b2, ... < bk-1 <= bk = m such that i-th scriber gets a sequence of books with numbers between bi-1+1 and bi. The time needed to make a copy of all the books is determined by the scriber who was assigned the most work. Therefore, our goal is to minimize the maximum number of pages assigned to a single scriber. Your task is to find the optimal assignment.

Input

The input consists of N cases. The first line of the input contains only positive integer N. Then follow the cases. Each case consists of exactly two lines. At the first line, there are two integers m and k, 1 <= k <= m <= 500. At the second line, there are integers p1, p2, ... pm separated by spaces. All these values are positive and less than 10000000.

Output

For each case, print exactly one line. The line must contain the input succession p1, p2, ... pm divided into exactly k parts such that the maximum sum of a single part should be as small as possible. Use the slash character ('/') to separate the parts. There must be exactly one space character between any two successive numbers and between the number and the slash.

If there is more than one solution, print the one that minimizes the work assigned to the first scriber, then to the second scriber etc. But each scriber must be assigned at least one book.

Sample Input

2

9 3

100 200 300 400 500 600 700 800 900

5 4

100 100 100 100 100

Sample Output

100 200 300 400 500 / 600 700 / 800 900

100 / 100 / 100 / 100 100

Source

Central Europe 1998

 

 

涓枃鎻忚堪錛?/span>

棰樼洰澶ф剰鏄粰浣?/span>m錛?/span>1…m錛夋湰涔︼紝姣忔湰涔︽湁Pm欏碉紝鐢?/span>k錛?/span>k<=m錛変釜鍛樺伐鏉ュ鍗拌繖浜涗功銆傛瘡鏈功鍙兘鍒嗛厤緇欎竴涓憳宸ユ潵澶嶅嵃錛屽茍涓旀瘡涓憳宸ュ繀欏誨鍗頒竴孌佃繛緇殑涔︾睄錛屾瘡涓憳宸ュ鍗扮殑鏃墮棿鍙栧喅浜庢墍澶嶅嵃涔︾睄鐨勬婚〉鏁般傝浣犵粰鍑虹浉搴旂殑鍒嗛厤錛屼嬌寰楀垎閰嶇粰鍛樺伐鐨勪功綾嶉〉鏁扮殑鏈澶у煎敖閲忓皬銆傛敞鎰忥紝濡傛灉鏈夊縐嶅垎閰嶇殑鏂規(guī)錛屼嬌寰楃涓涓憳宸ョ殑涔︾睄欏墊暟灝介噺灝戯紝鍏舵鏄浜屼釜銆佺涓変釜……浠ユ綾繪帹銆?/span>

 

棰樼洰鍒嗘瀽錛?/span>

鎴戜滑鍙互浠庡悗寰鍓嶆帹錛屾渶鍚庝竴涓憳宸ワ紝涔熷氨鏄k涓憳宸ワ紝浠栬嚦灝戣澶嶅嵃絎?/span>m鏈功錛岃嚦澶氬彲浠ュ鍗扮k鏈埌絎?/span>m鏈紙鍥犱負(fù)鑷沖皯瑕佸垎閰嶇粰鍓?/span>k-1涓憳宸ユ瘡浜轟竴鏈功錛夈傚亣璁撅紝絎?/span>k鍚嶅憳宸ュ鍒剁i錛?/span>k<=i<=m錛夋湰涔﹀埌絎?/span>m鏈功錛岄偅涔堬紝鎵鏈夊憳宸ュ鍗頒功綾嶇殑鏈灝忔椂闂村氨涓虹k鍚嶅憳宸ユ墍闇鐨勬椂闂翠互鍙?qiáng)鍓?/span>k-1鍚嶅憳宸ュ鍒跺墠i-1鏈功鎵闇鏈灝忔椂闂寸殑杈冨ぇ鐨勯偅涓椂闂淬傝繖鏍鳳紝闂鐨勮妯″氨浠?/span>k涓憳宸ュ鍗?/span>m鏈功鍑忓皬鍒頒簡(jiǎn)k-1涓憳宸ュ鍗?/span>i-1鏈功錛岃屼笖姹傝В榪囩▼涓細(xì)涓嶆柇閬囧埌鍓?/span>a涓憳宸ュ鍗板墠b鏈功鐨勬渶灝忔椂闂淬備負(fù)浜?jiǎn)鍑彏畯闂鐨勮妯′互鍙?qiáng)璁板綍閲嶅瀛愰棶棰樼殑瑙o紝灝卞彲浠ョ敤DP銆?/span>

浣嗕粎浠呯畻鍑烘渶灝忔椂闂寸殑涓嶅鐨勶紝榪樿緇欏嚭鍒嗛厤鐨勬柟妗堬紝榪欎釜紼嶅井鏈夌偣綣佺悙銆傚洜涓洪鐩腑璇達(dá)紝濡傛灉鏈夊縐嶆渶浼樼殑鍒嗛厤鏂規(guī)錛屽簲璇ヨ鍓嶉潰鐨勫憳宸ュ垎閰嶇殑欏墊暟灝介噺灝戙傞偅涔堬紝鍙互浠庡悗鎺紝鍦ㄥ綋鍓嶇殑鍛樺伐鎵澶嶅嵃鐨勪功綾嶉〉鏁版病鏈夎秴榪囨渶澶ч〉鏁扮殑鎯呭喌涓嬶紝璁╁叾澶嶅嵃鐨勯〉鏁版渶澶у寲銆傚鏋滆秴榪囦簡(jiǎn)鏈澶ч〉鏁幫紝灝辨妸榪欐湰涔﹀垎閰嶇粰鍓嶄竴鍚嶅憳宸ャ傛渶鍚庡啀鎸夐『搴忓皢鍒嗛厤緇撴灉杈撳嚭鍑烘潵銆?/span>

 

浠g爜錛?/span>

#include <cstdio>

#include <climits>

#include <cstring>

 

const int MAX = 505;

int book[MAX];

__int64 total[MAX];                        //1~n鏈功鐨勯〉鏁?/span>

int k, m;

__int64 f[MAX][MAX];                  //f[i][j] = k 琛ㄧず鍓?/span>i涓漢澶嶅埗鍓?/span>j鏈功鎵闇鏈灝戞椂闂存槸k

__int64 max;

void Input ()

{

                scanf("%d%d", &m, &k);

                int i;

                for (i=1; i<=m; i++)

                                scanf("%d", &book[i]);

}

 

__int64 Sum (int s, int e)                                               //絎?/span>s鏈功鍒扮e鏈功鐨勬婚〉鏁?/span>

{

                return (total[e] - total[s-1]);

}

 

__int64 Max (__int64 a, __int64 b)

{

                return ( a>b?a:b );

}

 

__int64 Min (int x, int y)                                //鍓?/span>x涓漢澶嶅埗鍓?/span>y鏈功鎵闇鐨勬渶灝戞椂闂?/span>        x<=y

{

//鑰冭檻鐗規(guī)畩鎯呭喌

                if ( f[x][y] != -1 )

                                return f[x][y];

                if ( y == 0 )

                                return ( f[x][y] = 0 );

                if ( x == 0 )

                                return ( f[x][y] = INT_MAX );

 

                int i;

                __int64 temp;

                f[x][y] = INT_MAX;

                for (i=x-1; i<y; i++)

                {

//絎?/span>x涓漢澶嶅埗絎?/span>i+1鍒扮y鏈功涓庡墠x-1涓漢澶嶅埗鍓?/span>i鏈功鐨勬椂闂磋緝澶х殑鏃墮棿

                                temp = Max( Min(x-1, i), Sum(i+1, y) );                 

                                if ( temp < f[x][y] )

                                {

                                                f[x][y] = temp;

                                }

                }

                return f[x][y];

}

 

void Output ()

{

                int i, p;

                __int64 temp;

                int slash[MAX];

                max = f[k][m];

                memset(slash, 0, sizeof(slash));

                temp = 0;

                p = k;

                for (i=m; i>0; i--)

                {

                                //璁╁悗闈㈢殑鍛樺伐灝介噺澶嶅嵃鏈澶氱殑涔︾睄

                                if ( temp + book[i] > max || i < p )

                                {

                                                slash[i] = 1;

                                                temp = book[i];

                                                p --;

                                }

                                else

                                {

                                                temp += book[i];

                                }

                }

 

                for (i=1; i<=m; i++)

                {

                                printf("%d", book[i]);

                                if ( slash[i] == 1 )

                                                printf(" / ");

                                else if ( i != m )

                                                printf(" ");

                }

                printf("\n");

}

 

void Solve ()

{

                int i, j;

                //棰勫鐞嗕功綾嶉〉鏁扮殑鍜?/span>

                total[0] = 0;

                for (i=1; i<=m; i++)

                                total[i] = total[i-1] + book[i];

 

                memset(f, -1, sizeof(f));

               

                Min(k, m);

               

                Output();

}

 

int main ()

{

                int test;

                scanf("%d", &test);

                while ( test-- )

                {

                                Input ();

                                Solve ();

                }

 

                return 0;

}

 

 

紼嬪簭鍒嗘瀽涓庡績(jī)寰楋細(xì)

鏃墮棿澶嶆潅搴?/span>O(n2)錛岀┖闂村鏉傚害O(n2)銆?/span>

鍦ㄧ敤璁板繂鍖栨悳绱㈣В鍐?/span>DP闂鏃訛紝寰寰姣旇緝絎﹀悎浜虹殑鎬濈淮錛屽鏄撴兂鍒版ā鍨嬶紝緙栫▼姣旇緝綆鍗曘傚湪瑙i榪囩▼涓紝闄や簡(jiǎn)鍙互鎸夌収甯哥悊欏虹潃鎺紝涔熷彲浠ュ皾璇曢嗗悜鎬濈淮錛屼粠鏈鍚庣殑鐘舵佸掔潃鎺紝榪欐牱鍙互浣塊棶棰樻兂寰楁洿鍔犻忓交錛屾湁姣旇緝濂界殑鏁堟灉銆?/span>



ACM-Boy 2008-03-10 15:11 鍙戣〃璇勮
]]>
PKU 2181 Jumping Cowshttp://www.shnenglu.com/ACM-Boy/archive/2008/02/02/42409.htmlACM-BoyACM-BoySat, 02 Feb 2008 13:41:00 GMThttp://www.shnenglu.com/ACM-Boy/archive/2008/02/02/42409.htmlhttp://www.shnenglu.com/ACM-Boy/comments/42409.htmlhttp://www.shnenglu.com/ACM-Boy/archive/2008/02/02/42409.html#Feedback0http://www.shnenglu.com/ACM-Boy/comments/commentRss/42409.htmlhttp://www.shnenglu.com/ACM-Boy/services/trackbacks/42409.html    緇欎綘n涓嵂鐨勫簭鍒楋紝鐗涗粠鏃墮棿1寮濮嬪悆鑽紝鍦ㄥ鏁版椂闂村悆鑽彲浠ュ鍔犲脊璺沖姏錛屽湪鍋舵暟鏃墮棿鍚冭嵂鍒欎細(xì)鍑忓皯寮硅煩鍔涖傚湪鏌愪竴鏃墮棿錛屼綘鍙互璺寵繃涓浜涜嵂錛屼絾涓鏃﹀悆榪囨煇縐嶈嵂錛屼綘灝變笉鑳藉湪閫夊墠闈㈢殑鑽簡(jiǎn)銆傞棶浣犳煇涓涓悆鑽殑搴忓垪錛屼嬌鐗涙渶緇堢殑寮硅煩鍔涙渶澶с?br>
鎬濊礬錛?br>    铏界劧棰樼洰涓嶉毦錛屼絾鎬濊冮鐩殑榪囩▼鍗佸垎鏈夋剰鎬濄傚浜庢煇縐嶈嵂錛屽叡鏈?涓姸鎬侊細(xì)鍦ㄥ鏁版椂闂村悆銆佸湪濂囨暟鏃墮棿涓嶅悆銆佸湪鍋舵暟鏃墮棿鍚冧互鍙?qiáng)鍦ㄥ伓鏁版棄櫁翠笉鍚冦傚叧閿湪浜庤繖4縐嶇姸鎬佷箣闂寸殑杞Щ銆傚洜涓哄鏋滆煩榪囨煇縐嶈嵂鏄笉闇瑕佽姳璐規(guī)椂闂寸殑錛屾墍浠ュ湪鏌?嬈$殑鍚冭嵂鏃墮棿鍐咃紝鏃墮棿鐩稿綋浜庢槸闈?rùn)姝㈢殑锛屼竴鐩寸淮鎸佸湪絎?嬈″悆鑽殑鏃墮棿孌靛唴銆?br>    鎵浠ュ彲鐢ㄤ竴鏁扮粍max[i][2][2]琛ㄧず鐘舵侊紝絎琲縐嶈嵂鍦ㄥ/鍋舵椂闂存鍐呭悆/涓嶅悆銆傚彲寰楃姸鎬佽漿縐誨彲琛ㄧず涓猴細(xì)
    max[i][0][0] = Max (max[i-1][0][0], max[i-1][0][1]);
    max[i][0][1] = Max (max[i-1][1][0], max[i-1][1][1]) - high[i];
    max[i][1][0] = Max (max[i-1][1][0], max[i-1][1][1]);
    max[i][1][1] = Max (max[i-1][0][0], max[i-1][0][1]) + high[i];

浠g爜錛?br>
#include <iostream>
using namespace std;

const int MAX = 150005;
int high[MAX];
int max[MAX][2][2];
int n;

void Input ()
{
    scanf("%d", &n);
    int i;
    for (i=1; i<=n; i++)
        scanf("%d", &high[i]);

}

int Max (int a, int b)
{
    return ( a>b?a:b );
}

void Solve ()
{
    int i;
    for (i=1; i<=n; i++)
    {
        max[i][0][0] = Max (max[i-1][0][0], max[i-1][0][1]);
        max[i][0][1] = Max (max[i-1][1][0], max[i-1][1][1]) - high[i];
        max[i][1][0] = Max (max[i-1][1][0], max[i-1][1][1]);
        max[i][1][1] = Max (max[i-1][0][0], max[i-1][0][1]) + high[i];
    }
    printf("%d\n", Max ( Max(max[n][0][0], max[n][0][1]), Max(max[n][1][0], max[n][1][1])) );
}

int main ()
{
    Input ();
    Solve ();

    return 0;
}


ACM-Boy 2008-02-02 21:41 鍙戣〃璇勮
]]>
PKU 2559 Largest Rectangle in a Histogramhttp://www.shnenglu.com/ACM-Boy/archive/2008/02/01/42366.htmlACM-BoyACM-BoyFri, 01 Feb 2008 11:34:00 GMThttp://www.shnenglu.com/ACM-Boy/archive/2008/02/01/42366.htmlhttp://www.shnenglu.com/ACM-Boy/comments/42366.htmlhttp://www.shnenglu.com/ACM-Boy/archive/2008/02/01/42366.html#Feedback0http://www.shnenglu.com/ACM-Boy/comments/commentRss/42366.htmlhttp://www.shnenglu.com/ACM-Boy/services/trackbacks/42366.html棰樼洰澶ф剰錛?/span>
    緇欏畾n涓繛緇殑闀垮害涓?鐨勭煩褰㈢殑楂樺害h錛?<=n<=100000錛?<=hi<=1000000000錛夛紝闂綘鍏朵腑鑳芥瀯鎴愮殑鏈澶х煩褰㈢殑闈㈢Н鏄灝戙?/span>

鎬濊礬錛?/span>
    寰堟樉鐒?dòng)灱岀敤DP銆備絾鍏抽敭鏄庢牱琛ㄧず鐘舵侊紝涓寮濮嬫兂鐢ㄤ竴涓簩緇存暟緇刴in[][]琛ㄧず浠巌锝瀓鐨勬渶灝忛珮搴︼紝闈㈢Н灝辯瓑浜巑in[i][j]*(j-i+1)銆備絾寰堜笉騫革紝鏍規(guī)嵁棰樼洰緇欏畾鐨刵鐨勮寖鍥達(dá)紝榪欎釜浜岀淮鏁扮粍鏍規(guī)湰鏃犳硶鍒涘緩銆?(
    鍚庢潵浠庤鍧涗笂寰楀埌鎻愮ず錛屽洜涓哄浜庡浘涓殑鏌愪釜闈㈢Н鏈澶х殑鐭╁艦錛屽繀鐒舵湁涓涓渶浣庣殑楂樺害h[k]錛屽嵆鐭╁艦鐨勯珮絳変簬h[k]錛屼互絎琸鍧楃煩褰㈢殑楂樺害錛屾渶宸﹁竟鍙互鍒拌揪榪欎釜鐭╁艦鐨勫乏杈癸紝鏈鍙寵竟鍙互鍒拌揪榪欎釜鐭╁艦鐨勫彸杈廣傛墍浠ワ紝鍙互浠ユ瘡鍧楃煩褰㈣繘琛屾墿灞曪紝姹傚嚭鏈宸﹁竟鍜屾渶鍙寵竟錛堝嵆涓よ竟鐨勯珮搴﹂兘澶т簬絳変簬榪欏潡鐨勯珮搴︼級(jí)錛屽緱鍑洪潰縐痵[i]錛岃繖鏍峰氨鍙眰鍑烘渶澶х殑s[i]浜?jiǎn)銆?/span>

浠g爜錛?/span>

#include <cstdio>

const int MAX = 100005;
__int64 h[MAX];
__int64 left[MAX], right[MAX];        //left[i] = j琛ㄧず絎琲涓煩褰互瀹冪殑楂樺害鍒拌揪鏈宸﹁竟鐨勪笅鏍?/span>
int n;

bool Input ()
{
    scanf("%d", &n);
    if ( n == 0 )
        return false;
    int i;
    for (i=1; i<=n; i++)
        scanf("%I64d", &h[i]);
    h[0] = h[n+1] = -1;
    return true;
}

void Solve ()
{
    int i;
    __int64 temp, max;
    for (i=1; i<=n; i++)
    {
        left[i] = right[i] = i;
    }

    for (i=1; i<=n; i++)
    {
        while ( h[left[i]-1] >= h[i] )
            left[i] = left[left[i]-1];
    }
    for (i=n; i>0; i--)
    {
        while ( h[right[i]+1] >= h[i] )
            right[i] = right[right[i]+1];
    }

    max = 0;
    for (i=1; i<=n; i++)
    {
        temp = h[i] * (right[i] - left[i] + 1);
        if ( temp > max )
            max = temp;
    }

    printf("%I64d\n", max);
}

int main ()
{
    while ( Input() )
    {
        Solve();
    }

    return 0;
}




ACM-Boy 2008-02-01 19:34 鍙戣〃璇勮
]]>
pku 3486 Computershttp://www.shnenglu.com/ACM-Boy/archive/2008/01/28/42029.htmlACM-BoyACM-BoyMon, 28 Jan 2008 06:45:00 GMThttp://www.shnenglu.com/ACM-Boy/archive/2008/01/28/42029.htmlhttp://www.shnenglu.com/ACM-Boy/comments/42029.htmlhttp://www.shnenglu.com/ACM-Boy/archive/2008/01/28/42029.html#Feedback0http://www.shnenglu.com/ACM-Boy/comments/commentRss/42029.htmlhttp://www.shnenglu.com/ACM-Boy/services/trackbacks/42029.html棰樼洰澶ф剰錛?/p>     緇欏畾涓涓椂闂存湡闂磏錛岀數(shù)鑴戠殑浠鋒牸c錛屼互鍙?qiáng)鐢?shù)鑴戠殑緇翠慨璐圭敤m(y,z)錛堢y鍙扮數(shù)鑴戜粠y騫寸敤鍒扮z騫存葷殑緇翠慨璐圭敤錛夈傝浣犳眰鍑哄湪鏈熼檺n涓嬌鐢ㄧ數(shù)鑴戠殑鏈浣庤垂鐢ㄣ?br>
鎬濊礬錛?br>    涓轟簡(jiǎn)璁╂昏垂鐢ㄦ渶浣庯紝浣犲繀欏諱綔鍑?guó)櫩欐狅L(fēng)殑鍐崇瓥錛氬亣璁句綘姝e湪浣跨敤鏌愪竴鍙扮數(shù)鑴戝凡鐢ㄥ埌y騫達(dá)紝浣爕+1騫存槸緇х畫(huà)鐢ㄨ繖鍙扮數(shù)鑴戯紝榪樻槸閲嶆柊涔扮y+1鍙扮數(shù)鑴戯紙娉ㄦ剰錛岃繖閲岀殑y+1鏄寚杈撳叆涓殑絎瑈+1琛岀數(shù)鑴戯紝鑰屼笉鏄寚浣犲凡璐拱浜?jiǎn)y+1鍙扮數(shù)鑴戯紝鍥犱負(fù)y騫村彧鑳戒拱杈撳叆涓殑絎瑈琛岀數(shù)鑴戯紝涓轟簡(jiǎn)涓嶄駭鐢熸販娣嗭紝灝嗙數(shù)鑴戠敤緙栧彿琛ㄧず錛夈傛樉鐒?dòng)灱屾煇涓闃舵鐨勬渶浼樿В騫朵笉鑳戒竴瀹氬鑷村叏灞鐨勬渶浼樿В錛屾墍浠ヨ偗瀹氫笉鑳界敤璐績(jī)銆?br>    鎴戜滑浠庢渶鍚庣殑鎯呭喌鏉ヨ冭檻錛屾渶鍚庡繀鐒舵槸鏌愪竴涓紪鍙蜂負(fù)y鐨勭數(shù)鑴戯紝浠庣y騫翠嬌鐢ㄥ埌絎琻騫達(dá)紝鑰屽墠闈㈢殑1锝瀥-1騫達(dá)紝鑷繁鍙彲鑳借喘涔扮紪鍙蜂負(fù)1~y-1鐨勭數(shù)鑴戜嬌鐢ㄥ埌y-1騫淬傝繖鏍鳳紝闂鐨勮寖鍥村氨鍑忓皬浜?jiǎn)锛屼粠缂栧彿湄?fù)1锝瀗鐨勭數(shù)鑴戜嬌鐢╪騫達(dá)紝闄嶄綆鍒頒簡(jiǎn)緙栧彿涓?锝瀥-1鐨勭數(shù)鑴戜嬌鐢▂-1騫淬傜粡鍒嗘瀽錛屽彲鎺ㄥ嚭閫掓帹寮忥細(xì)
    F[n] = min { F[i] + c + m[i+1][n] | 0<=i<=n-1 }
F[n]琛ㄧずn鍙扮數(shù)鑴戜嬌鐢╪騫寸殑鏈浣庤垂鐢?br>
浠g爜錛?br>
#include <cstdio>
#include <climits>
#include <cstring>

const int MAX = 1005;
int n, c;
int mend[MAX][MAX];
int f[MAX];
int cost;

bool Input ()
{
    if ( scanf("%d", &c) == EOF )
        return false;
    scanf("%d", &n);
    int i, j;
    for (i=1; i<=n; i++)
    {
        for (j=i; j<=n; j++)
            scanf("%d", &mend[i][j]);
    }
    return true;
}


void Solve ()
{
    int i, j;
    memset(f, 0, sizeof(f));
    for (i=1; i<=n; i++)
    {
        f[i] = INT_MAX;
        for (j=0; j<i; j++)
        {
            if ( f[j] + mend[j+1][i] + c < f[i] )
                f[i] = f[j] + mend[j+1][i] + c;
        }
    }
    printf("%d\n", f[n]);
}

int main ()
{
    while ( Input() )
    {
        Solve ();
    }

    return 0;
}


ACM-Boy 2008-01-28 14:45 鍙戣〃璇勮
]]>
PKU 1019 Number Sequencehttp://www.shnenglu.com/ACM-Boy/archive/2008/01/19/41474.htmlACM-BoyACM-BoySat, 19 Jan 2008 08:46:00 GMThttp://www.shnenglu.com/ACM-Boy/archive/2008/01/19/41474.htmlhttp://www.shnenglu.com/ACM-Boy/comments/41474.htmlhttp://www.shnenglu.com/ACM-Boy/archive/2008/01/19/41474.html#Feedback0http://www.shnenglu.com/ACM-Boy/comments/commentRss/41474.htmlhttp://www.shnenglu.com/ACM-Boy/services/trackbacks/41474.html棰樻剰錛?br>     灝辨槸鏈夎繖鏍蜂竴涓簭鍒楋細(xì)1 12 123 1234 12345 .....錛岃緭鍏ュ簭鍒楃殑涓嬫爣錛岃浣犵畻鍑?guó)櫙ュ簭鍒楁墍鍦ㄤ笅鏍囩殑瀛楃

鎬濊礬錛?br>     涓寮濮嬫兂鐢ㄥ瓧絎︿覆妯℃嫙鏉ュ仛錛岀粨鏋淭LE銆傚悗鏉ョ湅浜?jiǎn)discuss錛屽張鎯充簡(jiǎn)涓涓嬶紝鍙戠幇鍙互鎸夎寰嬪皢搴忓垪鍒嗘垚鍑犳錛岀劧鍚庡啀鍦ㄦ瘡孌典腑鏌ユ壘銆傚叿浣撳仛娉曟槸錛氬厛鎸夊簭鍒? 涓暟瀛楃殑浣嶆暟鏉ュ垎錛?12123...123456789鏄竴孌碉紝1..10 1..11 1..12 ... 1..99鏄竴孌碉紝1..100 ... 1..999鏄竴孌碉紝浠ユ綾繪帹銆傜‘瀹氫簡(jiǎn)鏄湪涓婇潰鐨勫摢涓孌典互鍚庯紝鍐嶆寜綾諱技鐨勬濇兂紜畾榪欎釜涓嬫爣鏄湪鍝釜12345...n鐨勫簭鍒楋紝鏈鍚庡垽鏂槸鍦ㄥ叾涓摢涓暟瀛楃殑 鍝竴浣嶃?br>
浠g爜錛?br> #include <iostream>
#include <cmath>
using namespace std;

const long long a[] = {0, 45, 9045, 1395495, 189414495, 2147483648};            //112123...9, 11231234...99, ... 鐨勪綅鏁?br> const long long b[] = {1, 11, 192, 2893, 38894, 488895, 5888896};                //1, 1234...10, 1234...100, ...鐨勪綅鏁?br>
int digit (int n)
{
    int ans = 1;
    while ( n / 10 != 0 )
    {
          n /= 10;
          ans ++;
    }
    return ans;
}

char Pos (int n, long long index)      //鍦?234...n涓壘鍒頒笅鏍囦負(fù)index鐨勫瓧絎?br> {
     long long i, j;
     long long pos = 0;
     for (i=1; i<=n; i++)
     {
         pos += digit(i);
         if ( pos >= index )
            break;
     }
    
     pos -= digit(i);               //瀹氫綅鍦╥涓?br>      j = digit(i) - (index - pos);
     //if ( j == digit(i) - 1 )
     //   cout<<endl;
     while ( j > 0 )
     {
           i /= 10;
           j --;
     }

     return (i % 10) + '0';
}


char Find (long long pos)
{
     long long p, t;
     int index = 0;
     int temp;
     while ( a[index] < pos )
     {
           index ++;
     }
     p = a[index - 1];
    
     p += b[index - 1];
     temp = int(pow(10.0, index-1));
     t = b[index - 1] + index;
     while ( p < pos )
     {
           p += t;
           t += index;
           temp ++;
     }
    
     p -= t - index;
    
     return Pos(temp, pos-p);
}

int main ()
{
    int test;
    long long i;
    cin>>test
    while ( test-- )
    {
          cin>>i;
          cout<<Find(i)<<endl;
    }

    return 0;


ACM-Boy 2008-01-19 16:46 鍙戣〃璇勮
]]>
PKU2975 Nimhttp://www.shnenglu.com/ACM-Boy/archive/2007/12/07/38025.htmlACM-BoyACM-BoyFri, 07 Dec 2007 13:41:00 GMThttp://www.shnenglu.com/ACM-Boy/archive/2007/12/07/38025.htmlhttp://www.shnenglu.com/ACM-Boy/comments/38025.htmlhttp://www.shnenglu.com/ACM-Boy/archive/2007/12/07/38025.html#Feedback3http://www.shnenglu.com/ACM-Boy/comments/commentRss/38025.htmlhttp://www.shnenglu.com/ACM-Boy/services/trackbacks/38025.html    鍥犱負(fù)姣忔鍙兘浠庝竴涓爢涓彇鐭沖瓙錛屾墍浠ュ彧瑕佸浜庢瘡涓爢i錛屽厛姹傚嚭鍏朵粬鎵鏈夊爢鐨勫紓鎴栧拰temp錛屽啀鐪?锝濳i-1涓庤繖涓紓鎴栧拰鍐嶈繘琛屽紓鎴栨槸鍚︿負(fù)0錛屽彧瑕佷負(fù)0灝卞緱鍒頒竴縐嶈儨鍒╃殑鏂規(guī)硶銆傝嚜宸卞厛鏄兂鏋氫婦0锝濳i-1錛屼笌temp榪涜寮傛垨銆傚悗鏉ユ劅瑙夋病鏈夊繀瑕侊紝鍙Ki>temp灝卞彲浠ヤ簡(jiǎn)錛屽洜涓鴻嫢浠庡爢i涓彇鍑簒涓煶瀛愶紝Ki-x寮傛垨temp==0 <==> Ki-x==temp錛屽彧瑕並i>temp錛屽氨瀛樺湪Ki-x==temp銆?br>
#include <cstdio>

#define PILE 1001

__int64 stone[PILE], test;       //test涓烘墍鏈夌煶瀛愭暟鐨勫紓鎴栧拰
int piles;

bool Input ()
{
    scanf("%d", &piles);
    if ( piles == 0 )
        return false;
   
    int i;
    for (i=0; i<piles; i++)
        scanf("%I64d", &stone[i]);
    return true;
}

void Solve ()
{
    int i, ans;
    __int64 temp;
    test = 0;
    ans = 0;
    for (i=0; i<piles; i++)
        test ^= stone[i];
   
    if ( test != 0 )
    {
        for (i=0; i<piles; i++)
        {
            temp = test ^ stone[i];      //鍐嶄笌stone[i]鍋氫竴嬈″紓鎴栵紝鐩稿綋浜庨櫎stone[i]瀵瑰叾浠栨墍鏈夊爢鐨勭煶瀛愯繘琛屽紓鎴?br>
            if ( stone[i] > temp )
                ans++;
        }
    }
    printf("%d\n", ans);
}

int main ()
{
    while ( Input() )
    {
        Solve();
    }
   
    return 0;
}




ACM-Boy 2007-12-07 21:41 鍙戣〃璇勮
]]>
PKU2907 Collecting Beepershttp://www.shnenglu.com/ACM-Boy/archive/2007/12/07/38019.htmlACM-BoyACM-BoyFri, 07 Dec 2007 11:31:00 GMThttp://www.shnenglu.com/ACM-Boy/archive/2007/12/07/38019.htmlhttp://www.shnenglu.com/ACM-Boy/comments/38019.htmlhttp://www.shnenglu.com/ACM-Boy/archive/2007/12/07/38019.html#Feedback1http://www.shnenglu.com/ACM-Boy/comments/commentRss/38019.htmlhttp://www.shnenglu.com/ACM-Boy/services/trackbacks/38019.html    鍥犱負(fù)鍦板浘鏈澶у彧鏈?0×20錛岃宐eeper鏈澶氫篃鍙湁10涓紝鎵浠ュ彲浠ヨ冭檻鐢ㄦ繁鎼滐紝鎵懼埌鎵鏈夊彲鑳借礬寰勶紝鍦ㄥ叾涓姞涓浜涚畝鍗曠殑鍑忔灊灝卞彲浠ヤ簡(jiǎn)銆傝搗鍒濅互涓轟細(xì)瓚呮椂錛屽彲鏈鍚庤繕鏄?ms銆傦細(xì)錛?br>

Source Code

Problem: 2907
User: QuXiao
Memory: 176K
Time: 0MS
Language: C++
Result: Accepted
  • Source Code
  • #include <iostream>
    #include <climits>
    using namespace std;

    struct Point
    {
    int x, y;
    };

    int num, X, Y;
    Point start, beeper[15];
    int shortest;
    int visited[15];


    int Length (Point p1, Point p2)
    {
    return abs(p1.x - p2.x) + abs(p1.y - p2.y);
    }

    void Input ()
    {
    int i;
    cin>>X>>Y;
    cin>>start.x>>start.y;
    cin>>num;
    for (i=0; i<num; i++)
    cin>>beeper[i].x>>beeper[i].y;
    }

    void DFS (int cur, int len, int n)
    {
    if ( n == num )
    {
    int t = Length(beeper[cur], start);
    if ( len + t < shortest )
    shortest = len + t;
    }
    else if ( len < shortest )
    {
    int i;
    for (i=0; i<num; i++)
    {
    if ( visited[i] == 0 )
    {
    visited[i] = 1;
    DFS (i, len+Length(beeper[cur], beeper[i]), n+1);
    visited[i] = 0;
    }
    }
    }
    }


    void Solve ()
    {
    int i, t;
    shortest = INT_MAX;
    memset(visited, 0, sizeof(visited));
    for (i=0; i<num; i++)
    {
    t = Length(beeper[i], start);
    visited[i] = 1;
    DFS (i, t, 1);
    visited[i] = 0;
    }
    cout<<"The shortest path has length "<<shortest<<endl;
    }

    int main ()
    {
    int test;
    cin>>test;
    while ( test-- )
    {
    Input ();
    Solve ();
    }

    return 0;
    }





ACM-Boy 2007-12-07 19:31 鍙戣〃璇勮
]]>
久久伊人五月丁香狠狠色| 久久久久久精品无码人妻| 亚洲中文精品久久久久久不卡| 国产精品激情综合久久| 国产精品久久毛片完整版| 国内精品久久人妻互换| 久久电影网2021| 东京热TOKYO综合久久精品 | 久久国产影院| 99久久亚洲综合精品网站| 久久午夜电影网| 韩国三级大全久久网站| 国产精品久久免费| a级毛片无码兔费真人久久| 99久久精品这里只有精品| 国内精品久久久久久久影视麻豆 | 99久久综合国产精品免费| 一级女性全黄久久生活片免费| 久久久久久久综合狠狠综合| 国内精品伊人久久久久777| 无码人妻精品一区二区三区久久| 精品久久久久久中文字幕人妻最新 | 久久久久久久久无码精品亚洲日韩 | 精品久久一区二区三区| 欧美久久综合性欧美| 久久久久亚洲av成人无码电影 | 国产精品gz久久久| 午夜精品久久久内射近拍高清| 亚洲欧美另类日本久久国产真实乱对白| 一本久久综合亚洲鲁鲁五月天亚洲欧美一区二区| 午夜视频久久久久一区| 久久久久人妻一区二区三区vr| 国产精品美女久久久| 久久青青草原亚洲av无码| 99精品久久精品一区二区| 精品久久久久国产免费| 久久久久亚洲AV成人网人人网站| 国产精品无码久久久久久| 亚州日韩精品专区久久久| 粉嫩小泬无遮挡久久久久久| 四虎影视久久久免费|